Here's a slow query in Postgres 9.1.6, although the maximum count is 2, with both rows already identified by their primary keys: (4.5 seconds)
EXPLAIN ANALYZE SELECT COUNT(*) FROM tbl WHERE id IN ('6d48fc431d21', 'd9e659e756ad') AND data ? 'building_floorspace' AND data ?| ARRAY['elec_mean_monthly_use', 'gas_mean_monthly_use']; QUERY PLAN
Hmm, maybe if I first make a subquery with the first part of the primary key ...: (no, another 4.5 seconds)
EXPLAIN ANALYZE SELECT COUNT(*) FROM ( SELECT * FROM tbl WHERE id IN ('6d48fc431d21', 'd9e659e756ad') ) AS t WHERE data ? 'building_floorspace' AND data ?| ARRAY['elec_mean_monthly_use', 'gas_mean_monthly_use']; QUERY PLAN
How can I prevent Postgres from embedding a subquery?
Reference Information. I have a Postgres 9.1 table using hstore and a GiST index ..
indexing postgresql subquery inlining
Seamus Abshere Feb 15 '13 at 15:22 2013-02-15 15:22
source share