Хранить отзывы сессий в PostgreSQL, сохранять U+0000, ограничить ожидание БД
Application / stack (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Pavel Grigorev
2026-11-06 17:11:03 +03:00
parent 0c6b95cc53
commit f69ad8c27c
31 changed files with 974 additions and 725 deletions
+41 -41
View File
@@ -1,65 +1,65 @@
# EXPLAIN (ANALYZE, BUFFERS): история сообщений, рабочий индекс messages_chat_history_idx
# {"date": "2026-10-29T09:19:19Z", "docker_cpus": 12, "docker_memory_gib": 1.9, "docker_server": "27.2.0", "postgres": "17.11", "shared_buffers": "128MB"}
# {"date": "2026-11-06T09:31:42Z", "docker_cpus": 12, "docker_memory_gib": 1.9, "docker_server": "27.2.0", "postgres": "17.11", "shared_buffers": "128MB"}
# messages: 200000; big chat: 100000, medium: 3000, small: 10
## big_first
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b' ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..27.46 rows=51 width=464) (actual time=0.034..0.056 rows=51 loops=1)
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2' ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..27.64 rows=51 width=462) (actual time=0.023..0.043 rows=51 loops=1)
Buffers: shared hit=9
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..53460.07 rows=100847 width=464) (actual time=0.034..0.052 rows=51 loops=1)
Index Cond: (chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b'::uuid)
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..53519.06 rows=100267 width=462) (actual time=0.022..0.038 rows=51 loops=1)
Index Cond: (chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2'::uuid)
Buffers: shared hit=9
Planning:
Buffers: shared hit=140
Planning Time: 1.713 ms
Execution Time: 0.106 ms
Buffers: shared hit=139
Planning Time: 1.200 ms
Execution Time: 0.107 ms
## big_d90_keyset
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b' AND (created_at, id) > ('2026-09-28 00:28:21.157057+00', 'c0c9ed9c-be61-4384-8a45-bae9a536e6bf') ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..143.81 rows=51 width=464) (actual time=0.036..0.061 rows=51 loops=1)
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2' AND (created_at, id) > ('2026-09-28 00:28:21.157057+00', '68768260-63ef-498c-a995-6183f15116f1') ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..143.21 rows=51 width=462) (actual time=0.031..0.056 rows=51 loops=1)
Buffers: shared hit=11
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..27913.79 rows=9928 width=464) (actual time=0.035..0.056 rows=51 loops=1)
Index Cond: ((chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b'::uuid) AND (ROW(created_at, id) > ROW('2026-09-28 00:28:21.157057+00'::timestamp with time zone, 'c0c9ed9c-be61-4384-8a45-bae9a536e6bf'::uuid)))
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..28399.10 rows=10143 width=462) (actual time=0.030..0.052 rows=51 loops=1)
Index Cond: ((chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2'::uuid) AND (ROW(created_at, id) > ROW('2026-09-28 00:28:21.157057+00'::timestamp with time zone, '68768260-63ef-498c-a995-6183f15116f1'::uuid)))
Buffers: shared hit=11
Planning:
Buffers: shared hit=139
Planning Time: 1.479 ms
Execution Time: 0.144 ms
Buffers: shared hit=138
Planning Time: 0.939 ms
Execution Time: 0.128 ms
## big_d90_offset
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b' ORDER BY created_at, id OFFSET 90000 LIMIT 51
Limit (cost=36460.92..36461.04 rows=1 width=464) (actual time=112.111..123.230 rows=51 loops=1)
Buffers: shared hit=12711, temp read=5508 written=5850
I/O Timings: temp read=7.753 write=67.976
-> Gather Merge (cost=26655.57..36460.92 rows=84040 width=464) (actual time=83.327..120.582 rows=90051 loops=1)
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2' ORDER BY created_at, id OFFSET 90000 LIMIT 51
Limit (cost=36336.63..36336.74 rows=1 width=462) (actual time=86.122..93.620 rows=51 loops=1)
Buffers: shared hit=12716, temp read=5489 written=5853
I/O Timings: temp read=6.704 write=28.200
-> Gather Merge (cost=26587.75..36336.63 rows=83556 width=462) (actual time=57.285..91.018 rows=90051 loops=1)
Workers Planned: 2
Workers Launched: 2
Buffers: shared hit=12711, temp read=5508 written=5850
I/O Timings: temp read=7.753 write=67.976
-> Sort (cost=25655.55..25760.60 rows=42020 width=464) (actual time=77.801..83.567 rows=30068 loops=3)
Buffers: shared hit=12716, temp read=5489 written=5853
I/O Timings: temp read=6.704 write=28.200
-> Sort (cost=25587.72..25692.17 rows=41778 width=462) (actual time=52.688..58.040 rows=30085 loops=3)
Sort Key: created_at, id
Sort Method: external merge Disk: 15832kB
Buffers: shared hit=12711, temp read=5508 written=5850
I/O Timings: temp read=7.753 write=67.976
Worker 0: Sort Method: external merge Disk: 16424kB
Worker 1: Sort Method: external merge Disk: 14416kB
-> Parallel Seq Scan on messages (cost=0.00..13664.67 rows=42020 width=464) (actual time=0.012..17.673 rows=33333 loops=3)
Filter: (chat_id = '60993bbf-7c34-4ffe-9cd5-da5471b4387b'::uuid)
Sort Method: external merge Disk: 15856kB
Buffers: shared hit=12716, temp read=5489 written=5853
I/O Timings: temp read=6.704 write=28.200
Worker 0: Sort Method: external merge Disk: 15016kB
Worker 1: Sort Method: external merge Disk: 15816kB
-> Parallel Seq Scan on messages (cost=0.00..13669.67 rows=41778 width=462) (actual time=0.009..16.948 rows=33333 loops=3)
Filter: (chat_id = 'bab8f878-617d-4988-a42a-c28b81490ed2'::uuid)
Rows Removed by Filter: 33333
Buffers: shared hit=12623
Buffers: shared hit=12628
Planning:
Buffers: shared hit=140
Planning Time: 1.732 ms
Execution Time: 129.398 ms
Buffers: shared hit=139
Planning Time: 1.009 ms
Execution Time: 95.985 ms
## small_first
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = '60557307-b3a2-4910-b148-88898ec43ea1' ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..50.93 rows=12 width=464) (actual time=0.038..0.104 rows=10 loops=1)
SELECT id, chat_id, sender_id, text, created_at FROM messages WHERE chat_id = 'fb9c80b1-749e-4946-aec5-cd8b3ab4eab1' ORDER BY created_at, id LIMIT 51
Limit (cost=0.42..51.00 rows=12 width=462) (actual time=0.034..0.078 rows=10 loops=1)
Buffers: shared hit=13
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..50.93 rows=12 width=464) (actual time=0.037..0.103 rows=10 loops=1)
Index Cond: (chat_id = '60557307-b3a2-4910-b148-88898ec43ea1'::uuid)
-> Index Scan using messages_chat_history_idx on messages (cost=0.42..51.00 rows=12 width=462) (actual time=0.033..0.075 rows=10 loops=1)
Index Cond: (chat_id = 'fb9c80b1-749e-4946-aec5-cd8b3ab4eab1'::uuid)
Buffers: shared hit=13
Planning:
Buffers: shared hit=140
Planning Time: 1.721 ms
Execution Time: 0.149 ms
Buffers: shared hit=139
Planning Time: 0.955 ms
Execution Time: 0.145 ms