объяснение 2 трека

This commit is contained in:
2026-10-25 23:04:14 +03:00
parent d49914a62f
commit 19452af70e
4 changed files with 39 additions and 32 deletions
Binary file not shown.
+6 -6
View File
@@ -1,28 +1,28 @@
{ {
"hypothesis": "Keyset pagination on (chat_id, created_at, id) avoids large offsets; redundant (chat_id)-only index does not improve reads but slows writes.", "hypothesis": "Keyset pagination on (chat_id, created_at, id) avoids large offsets; redundant (chat_id)-only index does not improve reads but slows writes.",
"hot_chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "hot_chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"read_plans": { "read_plans": {
"keyset_limit_50": { "keyset_limit_50": {
"node_type": "Index Only Scan", "node_type": "Index Only Scan",
"index_name": "messages_chat_history_idx", "index_name": "messages_chat_history_idx",
"execution_ms": 0.061, "execution_ms": 0.323,
"plan_rows": 50 "plan_rows": 50
}, },
"offset_50000_limit_50": { "offset_50000_limit_50": {
"node_type": "Index Only Scan", "node_type": "Index Only Scan",
"index_name": "messages_chat_history_idx", "index_name": "messages_chat_history_idx",
"execution_ms": 6.117, "execution_ms": 5.577,
"plan_rows": 50 "plan_rows": 50
}, },
"keyset_with_extra_chat_id_index": { "keyset_with_extra_chat_id_index": {
"node_type": "Index Only Scan", "node_type": "Index Only Scan",
"index_name": "messages_chat_history_idx", "index_name": "messages_chat_history_idx",
"execution_ms": 0.052, "execution_ms": 0.055,
"plan_rows": 50 "plan_rows": 50
} }
}, },
"write_messages_per_second": { "write_messages_per_second": {
"with_extra_chat_id_index": 23192.1, "with_extra_chat_id_index": 17808.1,
"production_indexes_only": 38756.3 "production_indexes_only": 22943.3
} }
} }
+26 -26
View File
@@ -1,69 +1,69 @@
{ {
"source": { "source": {
"messages": 116022, "messages": 113003,
"users": 88, "users": 8,
"sample": [ "sample": [
{ {
"id": "ffb54a59-afe2-41b7-9d55-e53a68117a84", "id": "ffdc1b38-be68-4b22-b3ac-9cfa0a8b95e7",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff90fc55-75ed-4633-85da-219d49656ebe", "id": "ff7ceafd-9fd1-4880-8a05-607961c68543",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff77cfb7-e1a3-45e3-ad54-c9b88a79cc1b", "id": "fef0853c-9b43-4f1d-bd5f-2941a08eeac1",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff102c2f-a3f2-4e39-a9c5-9a997a49f157", "id": "fee4413a-af81-4a84-8f4a-0c6704462f02",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "fe8a483b-94c8-40fc-a5d4-b0e2fd2602fc", "id": "febc6e0a-110e-4cda-8320-7fc88e5faf52",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
} }
] ]
}, },
"restored": { "restored": {
"messages": 116022, "messages": 113003,
"users": 88, "users": 8,
"sample": [ "sample": [
{ {
"id": "ffb54a59-afe2-41b7-9d55-e53a68117a84", "id": "ffdc1b38-be68-4b22-b3ac-9cfa0a8b95e7",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff90fc55-75ed-4633-85da-219d49656ebe", "id": "ff7ceafd-9fd1-4880-8a05-607961c68543",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff77cfb7-e1a3-45e3-ad54-c9b88a79cc1b", "id": "fef0853c-9b43-4f1d-bd5f-2941a08eeac1",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "ff102c2f-a3f2-4e39-a9c5-9a997a49f157", "id": "fee4413a-af81-4a84-8f4a-0c6704462f02",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
}, },
{ {
"id": "fe8a483b-94c8-40fc-a5d4-b0e2fd2602fc", "id": "febc6e0a-110e-4cda-8320-7fc88e5faf52",
"chat_id": "01aeb3d4-8235-4964-8981-ace0cec560df", "chat_id": "9d97f9d9-1ad0-4ab6-b95a-f35411c401b6",
"text": "w" "text": "w"
} }
] ]
}, },
"counts_match": true, "counts_match": true,
"sample_match": true, "sample_match": true,
"restore_seconds": 3.75, "restore_seconds": 3.6,
"dump_bytes": 3024158, "dump_bytes": 2945586,
"data_loss_boundary": "Logical pg_dump is consistent at dump start; concurrent writes during dump are not included. WAL/PITR not used — RPO equals changes after dump began." "data_loss_boundary": "Logical pg_dump is consistent at dump start; concurrent writes during dump are not included. WAL/PITR not used — RPO equals changes after dump began."
} }
+7
View File
@@ -86,6 +86,13 @@ def main():
conn.execute('DROP INDEX IF EXISTS messages_chat_id_only_idx') conn.execute('DROP INDEX IF EXISTS messages_chat_id_only_idx')
conn.execute('CREATE INDEX messages_chat_id_only_idx ON messages (chat_id)') conn.execute('CREATE INDEX messages_chat_id_only_idx ON messages (chat_id)')
conn.commit() conn.commit()
indexes = conn.execute(
"SELECT indexname, indexdef FROM pg_indexes "
"WHERE tablename = 'messages' ORDER BY indexname"
).fetchall()
print(indexes)
plan_keyset_with_extra = explain(conn, keyset_sql, (hot_id,)) plan_keyset_with_extra = explain(conn, keyset_sql, (hot_id,))
write_before = insert_batch(conn, hot_id, user_id, 500) write_before = insert_batch(conn, hot_id, user_id, 500)
conn.execute('DROP INDEX IF EXISTS messages_chat_id_only_idx') conn.execute('DROP INDEX IF EXISTS messages_chat_id_only_idx')