QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Limit (cost=5.42..12.15 rows=51 width=178) (actual time=0.258..0.290 rows=51 loops=1) Buffers: shared hit=6 read=5 InitPlan 1 (returns $0) -> Limit (cost=5.00..5.00 rows=1 width=24) (actual time=0.128..0.129 rows=1 loops=1) Buffers: shared hit=5 -> Sort (cost=5.00..5.50 rows=200 width=24) (actual time=0.128..0.129 rows=1 loops=1) Sort Key: chats.created_at Sort Method: top-N heapsort Memory: 25kB Buffers: shared hit=5 -> Seq Scan on chats (cost=0.00..4.00 rows=200 width=24) (actual time=0.019..0.044 rows=200 loops=1) Buffers: shared hit=2 -> Index Only Scan using idx_messages_chat_covering on messages (cost=0.42..99.42 rows=750 width=178) (actual time=0.256..0.284 rows=51 loops=1) Index Cond: ((chat_id = $0) AND (ROW(created_at, id) > ROW('2000-01-01 00:00:00+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))) Heap Fetches: 0 Buffers: shared hit=6 read=5 Planning: Buffers: shared hit=152 Planning Time: 2.105 ms Execution Time: 0.494 ms (19 rows)