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