BEGIN INSERT 0 1 INSERT 0 1 INSERT 0 1 INSERT 0 10000 ANALYZE messages_in_test_chat ----------------------- 10000 (1 row) First page (50 items plus one lookahead) QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.29..4.28 rows=51 width=78) (actual time=0.024..0.044 rows=51 loops=1) Buffers: shared hit=3 -> Index Scan using messages_history on messages (cost=0.29..782.85 rows=10000 width=78) (actual time=0.022..0.035 rows=51 loops=1) Index Cond: (chat_id = ''::uuid) Buffers: shared hit=3 Planning: Buffers: shared hit=18 Planning Time: 0.268 ms Execution Time: 0.073 ms (9 rows) Deep page (after message 9000) QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=0.29..15.36 rows=51 width=78) (actual time=0.081..0.103 rows=51 loops=1) Buffers: shared hit=3 -> Index Scan using messages_history on messages (cost=0.29..296.39 rows=1002 width=78) (actual time=0.079..0.094 rows=51 loops=1) Index Cond: ((chat_id = ''::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 02:30:00+00'::timestamp with time zone, ''::uuid))) Buffers: shared hit=3 Planning Time: 0.178 ms Execution Time: 0.185 ms (7 rows) ROLLBACK