forked from mtusi2026/mtusi2026lab2
81 lines
9.1 KiB
Plaintext
81 lines
9.1 KiB
Plaintext
Timing is off.
|
|
SET
|
|
VACUUM
|
|
BEGIN
|
|
INSERT 0 2
|
|
INSERT 0 41
|
|
INSERT 0 82
|
|
INSERT 0 52000
|
|
ANALYZE
|
|
=== dataset
|
|
total_messages | big_chat_messages
|
|
----------------+-------------------
|
|
52236 | 12000
|
|
(1 row)
|
|
|
|
=== 1. first page (no cursor), LIMIT 51 = limit+1
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=0.41..14.37 rows=51 width=78) (actual time=0.013..0.019 rows=51 loops=1)
|
|
Buffers: shared hit=4
|
|
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.41..3251.66 rows=11885 width=78) (actual time=0.013..0.016 rows=51 loops=1)
|
|
Index Cond: (chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid)
|
|
Buffers: shared hit=4
|
|
Planning:
|
|
Buffers: shared hit=7
|
|
Planning Time: 0.079 ms
|
|
Execution Time: 0.034 ms
|
|
(9 rows)
|
|
|
|
=== 2. deep page: keyset cursor after message #10000 (query used by API)
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=0.41..20.41 rows=51 width=78) (actual time=0.014..0.021 rows=51 loops=1)
|
|
Buffers: shared hit=4
|
|
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.41..2971.84 rows=7578 width=78) (actual time=0.014..0.017 rows=51 loops=1)
|
|
Index Cond: ((chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-02 00:00:10+00'::timestamp with time zone, '28dffdc4-76f2-4542-b18f-b3a28402e2dc'::uuid)))
|
|
Buffers: shared hit=4
|
|
Planning Time: 0.044 ms
|
|
Execution Time: 0.097 ms
|
|
(7 rows)
|
|
|
|
=== 3. for comparison: OFFSET pagination to the same page (NOT used by API)
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=2179.38..2179.51 rows=51 width=78) (actual time=3.948..3.952 rows=51 loops=1)
|
|
Buffers: shared hit=697
|
|
-> Sort (cost=2154.38..2184.09 rows=11885 width=78) (actual time=3.459..3.729 rows=10051 loops=1)
|
|
Sort Key: created_at, id
|
|
Sort Method: quicksort Memory: 1978kB
|
|
Buffers: shared hit=697
|
|
-> Seq Scan on messages (cost=0.00..1349.95 rows=11885 width=78) (actual time=0.007..1.906 rows=12000 loops=1)
|
|
Filter: (chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid)
|
|
Rows Removed by Filter: 40236
|
|
Buffers: shared hit=697
|
|
Planning Time: 0.057 ms
|
|
Execution Time: 4.068 ms
|
|
(12 rows)
|
|
|
|
=== 4. same keyset query WITHOUT messages_chat_created_id_idx (index dropped inside the transaction)
|
|
DROP INDEX
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=1863.95..1864.08 rows=51 width=78) (actual time=2.214..2.218 rows=51 loops=1)
|
|
Buffers: shared hit=697
|
|
-> Sort (cost=1863.95..1882.89 rows=7578 width=78) (actual time=2.213..2.215 rows=51 loops=1)
|
|
Sort Key: created_at, id
|
|
Sort Method: top-N heapsort Memory: 31kB
|
|
Buffers: shared hit=697
|
|
-> Seq Scan on messages (cost=0.00..1611.13 rows=7578 width=78) (actual time=0.437..2.084 rows=2000 loops=1)
|
|
Filter: ((chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid) AND (ROW(created_at, id) > ROW('2026-01-02 00:00:10+00'::timestamp with time zone, '28dffdc4-76f2-4542-b18f-b3a28402e2dc'::uuid)))
|
|
Rows Removed by Filter: 50236
|
|
Buffers: shared hit=697
|
|
Planning:
|
|
Buffers: shared hit=4
|
|
Planning Time: 0.065 ms
|
|
Execution Time: 2.235 ms
|
|
(14 rows)
|
|
|
|
ROLLBACK
|
|
=== rolled back: synthetic data removed, index restored
|