I have a 25mln rows "Zemla" table with index
CREATE INDEX zemla_level
ON public."Zemla"
USING btree
(level);
Now I do simple query
select * from "Zemla" where level = 7
and get very hard query plan
Bitmap Heap Scan on "Zemla" (cost=18316.26..636704.15 rows=978041 width=181) (actual time=216.681..758.663 rows=975247 loops=1)
Recheck Cond: (level = 7)
Heap Blocks: exact=54465
-> Bitmap Index Scan on zemla_level (cost=0.00..18071.74 rows=978041 width=0) (actual time=198.041..198.041 rows=1949202 loops=1)
Index Cond: (level = 7)
and another simple query which should be executed immediately when index present i think
select count(*) from "Zemla" where level = 7
Aggregate (cost=639149.25..639149.26 rows=1 width=0) (actual time=1188.366..1188.366 rows=1 loops=1)
-> Bitmap Heap Scan on "Zemla" (cost=18316.26..636704.15 rows=978041 width=0) (actual time=213.918..763.833 rows=975247 loops=1)
Recheck Cond: (level = 7)
Heap Blocks: exact=54465
-> Bitmap Index Scan on zemla_level (cost=0.00..18071.74 rows=978041 width=0) (actual time=195.409..195.409 rows=1949202 loops=1)
Index Cond: (level = 7)
My question is why PostgreSQL after first Index Scan does another Bitmap Heap Scan with so much overhead ?
Edit: What is a "Bitmap heap scan" in a query plan? is another question because it answers why some queries with OR operator has bitmap heap scan. My queries haven't neither OR nor AND operator