Timing is on. INSERT 0 1 Time: 3.601 ms INSERT 0 10 Time: 2.276 ms SELECT 100000 Time: 463.510 ms DROP INDEX Time: 3.420 ms CREATE TABLE Time: 5.623 ms ALTER TABLE Time: 4.390 ms CREATE INDEX Time: 2.480 ms INSERT 0 100000 Time: 4284.598 ms (00:04.285) CREATE INDEX Time: 4.338 ms INSERT 0 100000 Time: 4752.484 ms (00:04.752) ANALYZE Time: 67.604 ms ANALYZE Time: 66.671 ms Time: 0.725 ms QUERY PLAN -------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=4738.03..4743.89 rows=51 width=68) (actual time=23.277..31.083 rows=51 loops=1) Buffers: shared hit=1280 -> Gather Merge (cost=4738.03..10831.42 rows=52986 width=68) (actual time=23.275..31.076 rows=51 loops=1) Workers Planned: 1 Workers Launched: 1 Buffers: shared hit=1280 -> Sort (cost=3738.02..3870.48 rows=52986 width=68) (actual time=13.960..13.973 rows=40 loops=2) Sort Key: created_at DESC, id DESC Sort Method: top-N heapsort Memory: 36kB Buffers: shared hit=1280 Worker 0: Sort Method: top-N heapsort Memory: 37kB -> Parallel Seq Scan on alternative (cost=0.00..1970.29 rows=52986 width=68) (actual time=0.008..6.159 rows=45000 loops=2) Filter: (chat_id = '10253fd7-f49d-4add-97e2-130e62ab0306'::uuid) Rows Removed by Filter: 5000 Buffers: shared hit=1235 Planning: Buffers: shared hit=49 Planning Time: 0.391 ms Execution Time: 31.121 ms (19 rows) Time: 32.904 ms QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.42..4.81 rows=51 width=68) (actual time=0.022..0.037 rows=51 loops=1) Buffers: shared hit=24 -> Index Scan Backward using history_key on messages (cost=0.42..7736.02 rows=89770 width=68) (actual time=0.021..0.033 rows=51 loops=1) Index Cond: (chat_id = '10253fd7-f49d-4add-97e2-130e62ab0306'::uuid) Buffers: shared hit=24 Planning: Buffers: shared hit=33 Planning Time: 0.550 ms Execution Time: 0.058 ms (9 rows) Time: 1.354 ms DROP TABLE Time: 8.325 ms