title: Stream records one by one against matching query in PostgreSQL
body: <p>Hello everyone I hope all of u are doing well, I working on a time critical search engine and I want to know is there a way to get fetching records stream one by one against a marching query.<br>
  Like in my case I have a table of 40 million records and I want to search according to Search String  but if the search string is unique (contain rare records) or lengthy it took time to see through all the records and then return result which is time costly.<br>
  I already use indexing (ts_vector, GIN) but no help.</p>
  
  <p><strong>Search Query:</strong></p>
  
  <pre><code>explain analyze 
  Select  "SNR_SKU",
          "SNR_Title",
          "SNR_ModelNo",
          "SNR_Brand",
          "SNR_UPC",
          "SNR_Available",
          "SNR_ProductURL",
          "SNR_ImageURL",
          "SNR_Description",
          "SNR_isShow",
          "SNR_Date",
          "SNR_Category",
          "SNR_Condition",
          "SNR_SubCategory",
          "SNR_PriceBefore",
          "SNR_CustomerReviews",
          "SNR_Price"
  from (
    Select *,
           similarity('apple iphone 5s 16gb',"SNR_Title") as rank
    from products_allproducts 
    Where "SNR_Title" ~ 'apple' 
      AND "SNR_Title" ~ 'iphone' 
      AND "SNR_Title" ~ '5s' 
      AND "SNR_Title" ~ '16gb' 
    ORDER BY rank DESC LIMIT 36 OFFSET 0
  ) AS rankTable;
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code> QUERY PLAN                                                                                             
  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Subquery Scan on ranktable  (cost=1974848.30..1974848.32 rows=1 width=450) (actual time=16316.394..16316.395 rows=1 loops=1)
     -&gt;  Limit  (cost=1974848.30..1974848.31 rows=1 width=490) (actual time=16316.392..16316.393 rows=1 loops=1)
           -&gt;  Sort  (cost=1974848.30..1974848.31 rows=1 width=490) (actual time=16316.391..16316.391 rows=1 loops=1)
                 Sort Key: (similarity('apple iphone 5s 16gb'::text, (products_allproducts."SNR_Title")::text)) DESC
                 Sort Method: quicksort  Memory: 25kB
                 -&gt;  Gather  (cost=1000.00..1974848.29 rows=1 width=490) (actual time=16302.006..16316.383 rows=1 loops=1)
                       Workers Planned: 2
                       Workers Launched: 2
                       -&gt;  Parallel Seq Scan on products_allproducts  (cost=0.00..1973848.19 rows=1 width=490) (actual time=11275.609..16294.657 rows=0 loops=3)
                             Filter: ((("SNR_Title")::text ~ 'apple'::text) AND (("SNR_Title")::text ~ 'iphone'::text) AND (("SNR_Title")::text ~ '5s'::text) AND (("SNR_Title")::text ~ '16gb'::text))
                             Rows Removed by Filter: 6722677
  Planning time: 0.902 ms
  Execution time: 16462.318 ms
  (13 rows)
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>Here is my query plan:
  <a href="https://i.stack.imgur.com/WNrSu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WNrSu.png" alt="enter image description here"></a></p>