postgresql - What's wrong with GIN index, can't avoid SEQ scan? -
i've created table this,
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);
when query title,
test=# explain analyze select * mytable 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 filter: 10221 planning time: 0.176 ms execution time: 75.564 ms (6 rows)
the index not used. ideas? have 10m rows.
there typo in index definition, should be
on mytable using gin (to_tsvector('english', title))
instead of
on mytable using gin (to_tsvector('english', 'title'))
the way wrote it, constant , not field indexed, , such index indeed useless search 1 perform.
to see if index can used, can execute
set enable_seqscan=off;
and run query again.
if index still not used, index cannot used.
in addition above, there strikes me strange execution plan. postgresql estimates sequential scan of mytable
return 13744 rows , not 10 million there are. did disable autovacuum or there else cause table statistics inaccurate?
Comments
Post a Comment