I have a query involving a JSONB column in PostgreSQL, structured as follows:
select ((option ->> 'fruit_id'))
from table1 t1
where ((option ->> 'fruit_id')) = '1'
limit 10
This query is designed to fetch data from a JSONB column named option, extracting the value associated with the key 'fruit_id'.
I have created a B-tree index on the expression (option ->> 'fruit_id') to optimize this query. According to the PostgreSQL documentation, this setup seems to be a suitable candidate for an index-only scan.
However, the query appears to be using the index(index scan) but not performing an index-only scan. What could be the reason for this behavior? Is there something specific about JSONB indexing in PostgreSQL that prevents an index-only scan in this scenario?
I applied the vacuum command to the table, but even after that, index-only-scan was not performed.
Referenced document content
The index type must support index-only scans. B-tree indexes always do