research: measure track2 A/A noise with unchanged application
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
# План запроса истории: класс small, чат 200
|
||||
|
||||
Код: src_sha256 8a7e256c540af433, commit 8e7d4183e32c; вариант индекса: keyset
|
||||
Страница истории читаемого чата (limit 50); позиция — сколько
|
||||
сообщений истории до страницы:
|
||||
- first: после 0
|
||||
- middle: после 100
|
||||
- last: после 150
|
||||
|
||||
## Планы приложения
|
||||
|
||||
auto_explain (ANALYZE, BUFFERS, TIMING): запрос, параметры и план,
|
||||
с которыми его выполнило приложение (prepared statement asyncpg).
|
||||
|
||||
### first
|
||||
|
||||
duration: 0.131 ms plan:
|
||||
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
|
||||
FROM messages
|
||||
WHERE messages.chat_id = $1::UUID ORDER BY messages.created_at, messages.id
|
||||
LIMIT $2::INTEGER
|
||||
Query Parameters: $1 = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e', $2 = '51'
|
||||
Limit (cost=0.42..197.70 rows=51 width=204) (actual time=0.013..0.056 rows=51.00 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.42..731.51 rows=189 width=204) (actual time=0.012..0.053 rows=51.00 loops=1)
|
||||
Index Cond: (chat_id = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e'::uuid)
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=54
|
||||
|
||||
### middle
|
||||
|
||||
duration: 0.067 ms plan:
|
||||
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
|
||||
FROM messages
|
||||
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
|
||||
LIMIT $4::INTEGER
|
||||
Query Parameters: $1 = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e', $2 = '2026-10-02 01:27:36.624396+00', $3 = '90118262-ca69-4669-ab86-35c58766c377', $4 = '51'
|
||||
Limit (cost=0.42..24.15 rows=6 width=204) (actual time=0.009..0.047 rows=51.00 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.42..241.72 rows=61 width=204) (actual time=0.008..0.044 rows=51.00 loops=1)
|
||||
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=53
|
||||
|
||||
### last
|
||||
|
||||
duration: 0.063 ms plan:
|
||||
Query Text: SELECT messages.id, messages.chat_id, messages.sender_id, messages.text, messages.created_at
|
||||
FROM messages
|
||||
WHERE messages.chat_id = $1::UUID AND (messages.created_at, messages.id) > ($2::TIMESTAMP WITH TIME ZONE, $3::UUID) ORDER BY messages.created_at, messages.id
|
||||
LIMIT $4::INTEGER
|
||||
Query Parameters: $1 = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e', $2 = '2026-10-02 01:28:04.858109+00', $3 = 'c3668122-9cd2-478d-a1c4-b769d73d6a94', $4 = '51'
|
||||
Limit (cost=0.42..24.15 rows=6 width=204) (actual time=0.006..0.045 rows=50.00 loops=1)
|
||||
Buffers: shared hit=54
|
||||
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.42..241.72 rows=61 width=204) (actual time=0.005..0.043 rows=50.00 loops=1)
|
||||
Index Cond: ((chat_id = $1) AND (ROW(created_at, id) > ROW($2, $3)))
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=54
|
||||
|
||||
## Страница middle в psql: с индексом и без
|
||||
|
||||
Тот же текст запроса и те же параметры, что у плана middle.
|
||||
psql планирует их заново (custom plan). DROP INDEX — внутри
|
||||
транзакции, затем ROLLBACK: индекс остаётся в базе.
|
||||
|
||||
### С индексом ix_messages_chat_id_created_at_id
|
||||
|
||||
Limit (cost=0.42..201.43 rows=51 width=204) (actual time=0.041..0.273 rows=51.00 loops=1)
|
||||
Buffers: shared hit=53
|
||||
-> Index Scan using ix_messages_chat_id_created_at_id on messages (cost=0.42..307.84 rows=78 width=204) (actual time=0.040..0.268 rows=51.00 loops=1)
|
||||
Index Cond: ((chat_id = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 01:27:36.624396+00'::timestamp with time zone, '90118262-ca69-4669-ab86-35c58766c377'::uuid)))
|
||||
Index Searches: 1
|
||||
Buffers: shared hit=53
|
||||
Planning:
|
||||
Buffers: shared hit=141
|
||||
Planning Time: 0.396 ms
|
||||
Execution Time: 0.308 ms
|
||||
|
||||
### Без индекса ix_messages_chat_id_created_at_id
|
||||
|
||||
Limit (cost=5678.57..5684.51 rows=51 width=204) (actual time=5.735..6.866 rows=51.00 loops=1)
|
||||
Buffers: shared hit=3789
|
||||
-> Gather Merge (cost=5678.57..5687.54 rows=77 width=204) (actual time=5.735..6.860 rows=51.00 loops=1)
|
||||
Workers Planned: 2
|
||||
Workers Launched: 2
|
||||
Buffers: shared hit=3789
|
||||
-> Sort (cost=4678.55..4678.63 rows=32 width=204) (actual time=4.405..4.409 rows=28.33 loops=3)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: quicksort Memory: 34kB
|
||||
Buffers: shared hit=3789
|
||||
Worker 0: Sort Method: quicksort Memory: 32kB
|
||||
Worker 1: Sort Method: quicksort Memory: 34kB
|
||||
-> Parallel Seq Scan on messages (cost=0.00..4677.75 rows=32 width=204) (actual time=2.434..4.383 rows=33.33 loops=3)
|
||||
Filter: ((chat_id = 'd83c4273-021f-4c3b-9fa7-4ab244b7e31e'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 01:27:36.624396+00'::timestamp with time zone, '90118262-ca69-4669-ab86-35c58766c377'::uuid)))
|
||||
Rows Removed by Filter: 41967
|
||||
Buffers: shared hit=3759
|
||||
Planning:
|
||||
Buffers: shared hit=17
|
||||
Planning Time: 0.089 ms
|
||||
Execution Time: 6.889 ms
|
||||
Reference in New Issue
Block a user