portal=# create table bulk_data (a integer, b integer, primary key (a, b)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "bulk_data_pkey" for table "bulk_data" CREATE TABLE portal=# insert into bulk_data select 1,generate_series(1,1000000); INSERT 0 1000000 portal=# insert into bulk_data select 2,generate_series(1,1000000); INSERT 0 1000000 portal=# explain analyze select * from bulk_data where a = 1 limit 100; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..272.33 rows=100 width=8) (actual time=0.461..0.875 rows=100 loops=1) -> Index Scan using bulk_data_pkey on bulk_data (cost=0.00..25898.89 rows=9510 width=8) (actual time=0.454..0.630 rows=100 loops=1) Index Cond: (a = 1) Total runtime: 1.094 ms (4 rows) portal=# explain analyze select * from bulk_data where a = 1 and (b % 1000) = 0 limit 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=183.81..10439.27 rows=48 width=8) (actual time=409.110..494.701 rows=100 loops=1) -> Bitmap Heap Scan on bulk_data (cost=183.81..10439.27 rows=48 width=8) (actual time=409.103..494.228 rows=100 loops=1) Recheck Cond: (a = 1) Filter: ((b % 1000) = 0) -> Bitmap Index Scan on bulk_data_pkey (cost=0.00..183.79 rows=9510 width=0) (actual time=404.616..404.616 rows=1000000 loops=1) Index Cond: (a = 1) Total runtime: 495.186 ms (7 rows) portal=# analyze bulk_data; ANALYZE portal=# explain analyze select * from bulk_data where a = 1 limit 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..3.50 rows=100 width=8) (actual time=0.037..0.435 rows=100 loops=1) -> Seq Scan on bulk_data (cost=0.00..34804.20 rows=995341 width=8) (actual time=0.031..0.184 rows=100 loops=1) Filter: (a = 1) Total runtime: 0.676 ms (4 rows) portal=# explain analyze select * from bulk_data where a = 1 and (b % 1000) = 0 limit 100; QUERY PLAN ------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..900.23 rows=100 width=8) (actual time=1.261..76.754 rows=100 loops=1) -> Seq Scan on bulk_data (cost=0.00..44804.28 rows=4977 width=8) (actual time=1.255..76.381 rows=100 loops=1) Filter: ((a = 1) AND ((b % 1000) = 0)) Total runtime: 77.084 ms (4 rows) portal=#