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
|
|
----------------+-------------------
|
|
52472 | 12000
|
|
(1 row)
|
|
|
|
=== 1. first page (no cursor), LIMIT 51 = limit+1
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=0.41..14.59 rows=51 width=78) (actual time=0.031..0.039 rows=51 loops=1)
|
|
Buffers: shared hit=5
|
|
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.41..3343.23 rows=12025 width=78) (actual time=0.031..0.036 rows=51 loops=1)
|
|
Index Cond: (chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid)
|
|
Buffers: shared hit=5
|
|
Planning:
|
|
Buffers: shared hit=7
|
|
Planning Time: 0.091 ms
|
|
Execution Time: 0.063 ms
|
|
(9 rows)
|
|
|
|
=== 2. deep page: keyset cursor after message #10000 (query used by API)
|
|
QUERY PLAN
|
|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=0.41..20.81 rows=51 width=78) (actual time=0.010..0.015 rows=51 loops=1)
|
|
Buffers: shared hit=4
|
|
-> Index Scan using messages_chat_created_id_idx on messages (cost=0.41..3064.10 rows=7660 width=78) (actual time=0.010..0.012 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, 'bfe688ce-a094-4f72-a345-2e7a6e39c30b'::uuid)))
|
|
Buffers: shared hit=4
|
|
Planning Time: 0.041 ms
|
|
Execution Time: 0.068 ms
|
|
(7 rows)
|
|
|
|
=== 3. for comparison: OFFSET pagination to the same page (NOT used by API)
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=2195.82..2195.95 rows=51 width=78) (actual time=4.329..4.333 rows=51 loops=1)
|
|
Buffers: shared hit=700
|
|
-> Sort (cost=2170.82..2200.88 rows=12025 width=78) (actual time=3.850..4.096 rows=10051 loops=1)
|
|
Sort Key: created_at, id
|
|
Sort Method: quicksort Memory: 1978kB
|
|
Buffers: shared hit=700
|
|
-> Seq Scan on messages (cost=0.00..1355.90 rows=12025 width=78) (actual time=0.008..2.033 rows=12000 loops=1)
|
|
Filter: (chat_id = '00000000-0000-4000-8000-0000000c0000'::uuid)
|
|
Rows Removed by Filter: 40472
|
|
Buffers: shared hit=700
|
|
Planning Time: 0.044 ms
|
|
Execution Time: 4.450 ms
|
|
(12 rows)
|
|
|
|
=== 4. same keyset query WITHOUT messages_chat_created_id_idx (index dropped inside the transaction)
|
|
DROP INDEX
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
Limit (cost=1873.81..1873.94 rows=51 width=78) (actual time=1.999..2.003 rows=51 loops=1)
|
|
Buffers: shared hit=700
|
|
-> Sort (cost=1873.81..1892.96 rows=7660 width=78) (actual time=1.998..2.000 rows=51 loops=1)
|
|
Sort Key: created_at, id
|
|
Sort Method: top-N heapsort Memory: 31kB
|
|
Buffers: shared hit=700
|
|
-> Seq Scan on messages (cost=0.00..1618.26 rows=7660 width=78) (actual time=0.424..1.874 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, 'bfe688ce-a094-4f72-a345-2e7a6e39c30b'::uuid)))
|
|
Rows Removed by Filter: 50472
|
|
Buffers: shared hit=700
|
|
Planning:
|
|
Buffers: shared hit=4
|
|
Planning Time: 0.074 ms
|
|
Execution Time: 2.019 ms
|
|
(14 rows)
|
|
|
|
ROLLBACK
|
|
=== rolled back: synthetic data removed, index restored
|