forked from mtusi2026/mtusi2026lab2
исправление - символ не дает 500
This commit is contained in:
@@ -2,7 +2,7 @@ docker compose exec -T postgres psql -X -q -U messenger -d messenger -v ON_ERROR
|
||||
=== Объём данных
|
||||
messages_total | messages_in_big_chat
|
||||
----------------+----------------------
|
||||
21618 | 12000
|
||||
21650 | 12000
|
||||
|
||||
|
||||
=== Индекс истории (migrations/001_core.sql)
|
||||
@@ -14,58 +14,58 @@ docker compose exec -T postgres psql -X -q -U messenger -d messenger -v ON_ERROR
|
||||
=== 1. Первая страница (limit=50, приложение просит 51 строку, чтобы понять, есть ли следующая)
|
||||
QUERY PLAN
|
||||
---------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.018..0.041 rows=51 loops=1)
|
||||
Buffers: shared hit=5
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.017..0.033 rows=51 loops=1)
|
||||
Index Cond: (chat_id = '4981747a-a263-417e-80a3-fb7063eb8be5'::uuid)
|
||||
Buffers: shared hit=5
|
||||
Limit (actual time=0.023..0.043 rows=51 loops=1)
|
||||
Buffers: shared hit=6
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.022..0.036 rows=51 loops=1)
|
||||
Index Cond: (chat_id = 'b0b6cd43-57d9-4deb-99f3-e04443a88e4c'::uuid)
|
||||
Buffers: shared hit=6
|
||||
Planning:
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.139 ms
|
||||
Execution Time: 0.066 ms
|
||||
Planning Time: 0.160 ms
|
||||
Execution Time: 0.077 ms
|
||||
|
||||
|
||||
=== 2. Страница из середины истории по keyset-курсору (после 6000-го сообщения)
|
||||
QUERY PLAN
|
||||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=0.009..0.020 rows=51 loops=1)
|
||||
Buffers: shared hit=4
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.009..0.016 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = '4981747a-a263-417e-80a3-fb7063eb8be5'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 01:40:00+00'::timestamp with time zone, '41b24ea4-c9d1-467e-a5cc-6b4a5413a8be'::uuid)))
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.068 ms
|
||||
Execution Time: 0.076 ms
|
||||
Limit (actual time=0.019..0.055 rows=51 loops=1)
|
||||
Buffers: shared hit=6
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.018..0.044 rows=51 loops=1)
|
||||
Index Cond: ((chat_id = 'b0b6cd43-57d9-4deb-99f3-e04443a88e4c'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 01:40:00+00'::timestamp with time zone, 'bc979085-5d84-44a6-9df2-3b1fff1bdaf1'::uuid)))
|
||||
Buffers: shared hit=6
|
||||
Planning Time: 0.157 ms
|
||||
Execution Time: 0.122 ms
|
||||
|
||||
|
||||
=== 3. Для сравнения: та же страница через OFFSET (так приложение НЕ делает)
|
||||
QUERY PLAN
|
||||
-----------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=1.377..1.386 rows=51 loops=1)
|
||||
Buffers: shared hit=161
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.023..1.131 rows=6051 loops=1)
|
||||
Index Cond: (chat_id = '4981747a-a263-417e-80a3-fb7063eb8be5'::uuid)
|
||||
Buffers: shared hit=161
|
||||
Planning Time: 0.099 ms
|
||||
Execution Time: 1.406 ms
|
||||
Limit (actual time=1.586..1.603 rows=51 loops=1)
|
||||
Buffers: shared hit=163
|
||||
-> Index Scan using messages_chat_history_idx on messages (actual time=0.020..1.305 rows=6051 loops=1)
|
||||
Index Cond: (chat_id = 'b0b6cd43-57d9-4deb-99f3-e04443a88e4c'::uuid)
|
||||
Buffers: shared hit=163
|
||||
Planning Time: 0.095 ms
|
||||
Execution Time: 1.625 ms
|
||||
|
||||
|
||||
=== 4. Для сравнения: запрос 2 без индекса (индекс удалён только внутри этой транзакции)
|
||||
QUERY PLAN
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
Limit (actual time=2.522..2.528 rows=51 loops=1)
|
||||
Buffers: shared hit=296
|
||||
-> Sort (actual time=2.522..2.524 rows=51 loops=1)
|
||||
Limit (actual time=4.238..4.247 rows=51 loops=1)
|
||||
Buffers: shared hit=289
|
||||
-> Sort (actual time=4.237..4.241 rows=51 loops=1)
|
||||
Sort Key: created_at, id
|
||||
Sort Method: top-N heapsort Memory: 31kB
|
||||
Buffers: shared hit=296
|
||||
-> Seq Scan on messages (actual time=0.631..2.057 rows=6000 loops=1)
|
||||
Filter: ((chat_id = '4981747a-a263-417e-80a3-fb7063eb8be5'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 01:40:00+00'::timestamp with time zone, '41b24ea4-c9d1-467e-a5cc-6b4a5413a8be'::uuid)))
|
||||
Rows Removed by Filter: 15618
|
||||
Buffers: shared hit=296
|
||||
Buffers: shared hit=289
|
||||
-> Seq Scan on messages (actual time=0.967..3.376 rows=6000 loops=1)
|
||||
Filter: ((chat_id = 'b0b6cd43-57d9-4deb-99f3-e04443a88e4c'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 01:40:00+00'::timestamp with time zone, 'bc979085-5d84-44a6-9df2-3b1fff1bdaf1'::uuid)))
|
||||
Rows Removed by Filter: 15650
|
||||
Buffers: shared hit=289
|
||||
Planning:
|
||||
Buffers: shared hit=4
|
||||
Planning Time: 0.128 ms
|
||||
Execution Time: 2.554 ms
|
||||
Planning Time: 0.119 ms
|
||||
Execution Time: 4.268 ms
|
||||
|
||||
|
||||
=== ROLLBACK: синтетические данные удалены, индекс на месте
|
||||
|
||||
Reference in New Issue
Block a user