Skip to content

Instantly share code, notes, and snippets.

@bkempner
Created January 21, 2012 00:20
Show Gist options
  • Save bkempner/1650406 to your computer and use it in GitHub Desktop.
Save bkempner/1650406 to your computer and use it in GitHub Desktop.
de2nq092qkqfxll=> create index ben_test_partial on units (city_name) where is_deleted = true;
CREATE INDEX
de2nq092qkqfxll=> explain select count(*) from units where city_name = 'San Francisco' and is_deleted = true;
QUERY PLAN
----------------------------------------------------------------------------------------
Aggregate (cost=1276.17..1276.17 rows=1 width=0)
-> Bitmap Heap Scan on units (cost=35.38..1276.00 rows=331 width=0)
Recheck Cond: (((city_name)::text = 'San Francisco'::text) AND is_deleted)
-> Bitmap Index Scan on ben_test_partial (cost=0.00..35.37 rows=331 width=0)
Index Cond: ((city_name)::text = 'San Francisco'::text)
(5 rows)
de2nq092qkqfxll=> drop index ben_test_partial;
DROP INDEX
de2nq092qkqfxll=> create index ben_test_partial_2 on units (city_name, is_deleted);
CREATE INDEX
de2nq092qkqfxll=> explain select count(*) from units where city_name = 'San Francisco' and is_deleted = true;
QUERY PLAN
-------------------------------------------------------------------------------------------------
Aggregate (cost=1249.61..1249.61 rows=1 width=0)
-> Bitmap Heap Scan on units (cost=8.82..1249.44 rows=331 width=0)
Recheck Cond: ((city_name)::text = 'San Francisco'::text)
Filter: is_deleted
-> Bitmap Index Scan on ben_test_partial_2 (cost=0.00..8.80 rows=331 width=0)
Index Cond: (((city_name)::text = 'San Francisco'::text) AND (is_deleted = true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment