I have a table named snapshots with a column named data in jsonb format An Index is created on snapshots table
create index on snapshots using(( data->>'creator' ));
The following query was using index initially but not after couple of days
SELECT id, data - 'sections' - 'sharing' AS data FROM snapshots WHERE data->>'creator' = '[email protected]' ORDER BY xmin::text::bigint DESC
below is the output by running explain analyze
Sort (cost=19.10..19.19 rows=35 width=77) (actual time=292.159..292.163 rows=35 loops=1)
Sort Key: (((xmin)::text)::bigint) DESC
Sort Method: quicksort Memory: 30kB
-> Seq Scan on snapshots (cost=0.00..18.20 rows=35 width=77) (actual time=3.500..292.104 rows=35 loops=1)
Filter: ((data ->> 'creator'::text) = '[email protected]'::text)
Rows Removed by Filter: 152
Planning Time: 0.151 ms
Execution Time: 292.198 ms
explain(analyze, BUFFERS, TIMING)would interesting to see (especially if you can do `set track_io_timing=on;' before that). 200ms to scan such a tiny table seems quite slow - but if the values are large, that might be an explanation.set enable_seqscan=off;this will force Postgres to use the index if it can. If it the does use the index, that means the statistics suggest to the optimizer that a seqscan may be faster. tryvacuum analyseto regenerate the statistics.