Pager usage is off. version ----------------------------------------------------------------------------------------- PostgreSQL 18.6 on x86_64-pc-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit (1 row) DROP SCHEMA CREATE SCHEMA SET setseed --------- (1 row) CREATE TABLE INSERT 0 1000000 CREATE INDEX VACUUM BASELINE: WARMUP QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=9193.98..9194.00 rows=10 width=35) (actual time=9.855..9.858 rows=10.00 loops=1) Buffers: shared hit=8333 read=11 -> Sort (cost=9193.98..9218.31 rows=9733 width=35) (actual time=9.853..9.855 rows=10.00 loops=1) Sort Key: created_at DESC Sort Method: top-N heapsort Memory: 25kB Buffers: shared hit=8333 read=11 -> Bitmap Heap Scan on comments (cost=111.86..8983.65 rows=9733 width=35) (actual time=2.353..9.133 rows=10000.00 loops=1) Recheck Cond: (user_id = 42) Heap Blocks: exact=8333 Buffers: shared hit=8333 read=11 -> Bitmap Index Scan on ix_comments_user_id (cost=0.00..109.42 rows=9733 width=0) (actual time=1.395..1.396 rows=10000.00 loops=1) Index Cond: (user_id = 42) Index Searches: 1 Buffers: shared read=11 Planning: Buffers: shared hit=40 read=3 Planning Time: 0.519 ms Execution Time: 10.084 ms (18 rows) BASELINE: MEASURED QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=9193.98..9194.00 rows=10 width=35) (actual time=16.326..16.329 rows=10.00 loops=1) Buffers: shared hit=8344 -> Sort (cost=9193.98..9218.31 rows=9733 width=35) (actual time=16.324..16.325 rows=10.00 loops=1) Sort Key: created_at DESC Sort Method: top-N heapsort Memory: 25kB Buffers: shared hit=8344 -> Bitmap Heap Scan on comments (cost=111.86..8983.65 rows=9733 width=35) (actual time=2.206..13.236 rows=10000.00 loops=1) Recheck Cond: (user_id = 42) Heap Blocks: exact=8333 Buffers: shared hit=8344 -> Bitmap Index Scan on ix_comments_user_id (cost=0.00..109.42 rows=9733 width=0) (actual time=1.376..1.376 rows=10000.00 loops=1) Index Cond: (user_id = 42) Index Searches: 1 Buffers: shared hit=11 Planning Time: 0.118 ms Execution Time: 16.537 ms (16 rows) CREATE INDEX DATE INDEX: WARMUP QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.42..63.93 rows=10 width=35) (actual time=240.240..240.278 rows=10.00 loops=1) Buffers: shared hit=495902 read=1358 -> Index Scan using ix_comments_created_at on comments (cost=0.42..61814.32 rows=9733 width=35) (actual time=240.238..240.274 rows=10.00 loops=1) Filter: (user_id = 42) Rows Removed by Filter: 495944 Index Searches: 1 Buffers: shared hit=495902 read=1358 Planning: Buffers: shared hit=17 read=1 Planning Time: 0.279 ms Execution Time: 240.306 ms (11 rows) DATE INDEX: MEASURED QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.42..63.93 rows=10 width=35) (actual time=241.245..241.279 rows=10.00 loops=1) Buffers: shared hit=497260 -> Index Scan using ix_comments_created_at on comments (cost=0.42..61814.32 rows=9733 width=35) (actual time=241.243..241.276 rows=10.00 loops=1) Filter: (user_id = 42) Rows Removed by Filter: 495944 Index Searches: 1 Buffers: shared hit=497260 Planning Time: 0.082 ms Execution Time: 241.354 ms (9 rows) CREATE INDEX COMPOSITE INDEX: WARMUP QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.42..26.01 rows=10 width=35) (actual time=0.031..0.043 rows=10.00 loops=1) Buffers: shared hit=10 read=3 -> Index Scan using ix_comments_user_date on comments (cost=0.42..24902.26 rows=9733 width=35) (actual time=0.030..0.041 rows=10.00 loops=1) Index Cond: (user_id = 42) Index Searches: 1 Buffers: shared hit=10 read=3 Planning: Buffers: shared hit=20 read=1 Planning Time: 0.267 ms Execution Time: 0.058 ms (10 rows) COMPOSITE INDEX: MEASURED QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.42..26.01 rows=10 width=35) (actual time=0.032..0.043 rows=10.00 loops=1) Buffers: shared hit=13 -> Index Scan using ix_comments_user_date on comments (cost=0.42..24902.26 rows=9733 width=35) (actual time=0.031..0.042 rows=10.00 loops=1) Index Cond: (user_id = 42) Index Searches: 1 Buffers: shared hit=13 Planning Time: 0.084 ms Execution Time: 0.067 ms (8 rows)