Switching from indexed to sequential scans

Previously, it was pointed out that when the query planner knows much of the table is going to be returned, it will just execute a sequential scan. This still isn't the case even in the very poor plan that is given, if we want all the values from 0 to 3 here:

EXPLAIN ANALYZE SELECT COUNT(*) FROM t WHERE v<4;
QUERY PLAN
----------
Aggregate  (cost=1706.53..1706.54 rows=1 width=0) (actual time=112.030..112.031 rows=1 loops=1)
       ->  Bitmap Heap Scan on t  (cost=665.33..1606.83 rows=39880 width=0) (actual time=5.712..59.564 rows=40144 loops=1)
             Recheck Cond: (v < 4)
             ->  Bitmap Index Scan on i  (cost=0.00..655.36 rows=39880 width=0) (actual time=5.609..5.609 rows=40144 loops=1)
                   Index Cond: (v < 4)
  

But, even ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.