1
我創建了這樣一個表格,GIN索引有什麼問題,無法避免SEQ掃描?
create table mytable(hash char(40), title varchar(500));
create index name_fts on mytable using gin(to_tsvector('english', 'title'));
CREATE UNIQUE INDEX md5_uniq_idx ON mytable(hash);
當我查詢的名稱,
test=# explain analyze select * from mytable where to_tsvector('english', title) @@ 'abc | def'::tsquery limit 10;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Limit (cost=0.00..277.35 rows=10 width=83) (actual time=0.111..75.549 rows=10 loops=1)
-> Seq Scan on mytable (cost=0.00..381187.45 rows=13744 width=83) (actual time=0.110..75.546 rows=10 loops=1)
Filter: (to_tsvector('english'::regconfig, (title)::text) @@ '''abc'' | ''def'''::tsquery)
Rows Removed by Filter: 10221
Planning time: 0.176 ms
Execution time: 75.564 ms
(6 rows)
將不使用索引。有任何想法嗎?我有10米行。
這不是全文搜索的工作原理。 – Phill
@Phill你能詳細說明嗎? – daisy
您的查詢在執行時轉換該值,這會很慢,它永遠不會使用索引。您應該將tsvector存儲在表格的單獨列中。 – Phill