This commit is contained in:
@@ -2,65 +2,65 @@
|
||||
== Data volume
|
||||
total_messages | target_chat_messages
|
||||
----------------+----------------------
|
||||
70006 | 20000
|
||||
70003 | 20000
|
||||
(1 row)
|
||||
|
||||
|
||||
== 1. First page: WHERE chat_id = ? ORDER BY created_at, id LIMIT 51
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.005..0.022 rows=51 loops=1)
|
||||
Limit (actual time=0.007..0.012 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.005..0.020 rows=51 loops=1)
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.006..0.009 rows=51 loops=1)
|
||||
Index Cond: (chat_id = '00000000-0000-0000-0001-000000000000'::uuid)
|
||||
Buffers: shared hit=4
|
||||
Planning:
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.045 ms
|
||||
Execution Time: 0.029 ms
|
||||
Planning Time: 0.036 ms
|
||||
Execution Time: 0.022 ms
|
||||
(9 rows)
|
||||
|
||||
|
||||
== 2. Deep page after the 15 000th message: (created_at, id) > (?, ?)
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.005..0.010 rows=51 loops=1)
|
||||
Limit (actual time=0.006..0.010 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.005..0.007 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '00000000-0000-0000-0001-000000000000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, '5ec4eb0a-04cf-487e-9ec0-16b7367e29df'::uuid)))
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.005..0.008 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '00000000-0000-0000-0001-000000000000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, 'd5bb7c5e-b8e9-43e6-864a-c12a22b3e27d'::uuid)))
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.027 ms
|
||||
Execution Time: 0.025 ms
|
||||
Planning Time: 0.023 ms
|
||||
Execution Time: 0.029 ms
|
||||
(7 rows)
|
||||
|
||||
|
||||
== 3. Same deep page with OFFSET instead of a cursor (for comparison, not used by the API)
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=1.076..1.080 rows=51 loops=1)
|
||||
Limit (actual time=1.024..1.028 rows=51 loops=1)
|
||||
Buffers: shared hit=296
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.007..0.800 rows=15051 loops=1)
|
||||
-> Index Scan using messages_chat_id_created_at_id_idx on messages (actual time=0.007..0.768 rows=15051 loops=1)
|
||||
Index Cond: (chat_id = '00000000-0000-0000-0001-000000000000'::uuid)
|
||||
Buffers: shared hit=296
|
||||
Planning Time: 0.025 ms
|
||||
Execution Time: 1.093 ms
|
||||
Planning Time: 0.021 ms
|
||||
Execution Time: 1.036 ms
|
||||
(7 rows)
|
||||
|
||||
|
||||
== 4. Deep page without messages_chat_id_created_at_id_idx (index scans disabled for this query only)
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=2.151..2.154 rows=51 loops=1)
|
||||
Limit (actual time=2.097..2.101 rows=51 loops=1)
|
||||
Buffers: shared hit=914
|
||||
-> Sort (actual time=2.151..2.152 rows=51 loops=1)
|
||||
-> Sort (actual time=2.096..2.098 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=914
|
||||
-> Seq Scan on messages (actual time=0.420..1.969 rows=5000 loops=1)
|
||||
Filter: ((chat_id = '00000000-0000-0000-0001-000000000000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, '5ec4eb0a-04cf-487e-9ec0-16b7367e29df'::uuid)))
|
||||
Rows Removed by Filter: 65006
|
||||
-> Seq Scan on messages (actual time=0.423..1.891 rows=5000 loops=1)
|
||||
Filter: ((chat_id = '00000000-0000-0000-0001-000000000000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 04:10:00+00'::timestamp with time zone, 'd5bb7c5e-b8e9-43e6-864a-c12a22b3e27d'::uuid)))
|
||||
Rows Removed by Filter: 65003
|
||||
Buffers: shared hit=914
|
||||
Planning Time: 0.021 ms
|
||||
Execution Time: 2.162 ms
|
||||
Planning Time: 0.020 ms
|
||||
Execution Time: 2.108 ms
|
||||
(12 rows)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user