大家好,我希望你们所有人都做得很好,我在一个时间紧迫的搜索引擎上工作,我想知道是否有一种方法可以针对进行中的查询逐个获取记录流。
就像我的情况一样,我有一个4000万条记录的表,我想根据搜索字符串进行搜索,但是如果搜索字符串是唯一的(包含稀有记录)或时间很长,则需要花一些时间才能浏览所有记录,然后返回结果时间很长。
我已经使用索引(ts_vector,GIN),但没有帮助。
搜索查询:
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;
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)
-> Limit (cost=1974848.30..1974848.31 rows=1 width=490) (actual time=16316.392..16316.393 rows=1 loops=1)
-> 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
-> 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
-> 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)
谢谢。