feat: prove query tradeoffs and fresh-volume restore

This commit is contained in:
Самохвалов Андрей Ремович
2026-10-02 12:58:21 +03:00
parent e50ba0f8d2
commit b3dae2855f
9 changed files with 436 additions and 4 deletions
+31
View File
@@ -0,0 +1,31 @@
variant,index,operation,trial,dataset_rows,execution_ms,shared_hit,shared_read,shared_dirtied,plan,rows_inserted
A,messages_history_idx,first,1,100000,0.008,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,first,2,100000,0.015,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,first,3,100000,0.011,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,first,4,100000,0.009,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,first,5,100000,0.009,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,deep,1,100000,0.009,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,deep,2,100000,0.017,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,deep,3,100000,0.011,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,deep,4,100000,0.022,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,deep,5,100000,0.009,6,0,0,Limit > messages_history_idx,0
A,messages_history_idx,write500,1,100000,3.997,,,,INSERT 500 + COMMIT,500
A,messages_history_idx,write500,2,100000,3.276,,,,INSERT 500 + COMMIT,500
A,messages_history_idx,write500,3,100000,2.616,,,,INSERT 500 + COMMIT,500
A,messages_history_idx,write500,4,100000,2.632,,,,INSERT 500 + COMMIT,500
A,messages_history_idx,write500,5,100000,2.467,,,,INSERT 500 + COMMIT,500
B,messages_history_covering_idx,first,1,100000,0.009,5,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,first,2,100000,0.011,5,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,first,3,100000,0.013,5,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,first,4,100000,0.01,5,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,first,5,100000,0.016,5,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,deep,1,100000,0.009,4,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,deep,2,100000,0.009,4,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,deep,3,100000,0.011,4,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,deep,4,100000,0.012,4,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,deep,5,100000,0.01,4,0,0,Limit > messages_history_covering_idx,0
B,messages_history_covering_idx,write500,1,100000,2.638,,,,INSERT 500 + COMMIT,500
B,messages_history_covering_idx,write500,2,100000,12.557,,,,INSERT 500 + COMMIT,500
B,messages_history_covering_idx,write500,3,100000,2.7,,,,INSERT 500 + COMMIT,500
B,messages_history_covering_idx,write500,4,100000,2.382,,,,INSERT 500 + COMMIT,500
B,messages_history_covering_idx,write500,5,100000,2.439,,,,INSERT 500 + COMMIT,500
1 variant index operation trial dataset_rows execution_ms shared_hit shared_read shared_dirtied plan rows_inserted
2 A messages_history_idx first 1 100000 0.008 6 0 0 Limit > messages_history_idx 0
3 A messages_history_idx first 2 100000 0.015 6 0 0 Limit > messages_history_idx 0
4 A messages_history_idx first 3 100000 0.011 6 0 0 Limit > messages_history_idx 0
5 A messages_history_idx first 4 100000 0.009 6 0 0 Limit > messages_history_idx 0
6 A messages_history_idx first 5 100000 0.009 6 0 0 Limit > messages_history_idx 0
7 A messages_history_idx deep 1 100000 0.009 6 0 0 Limit > messages_history_idx 0
8 A messages_history_idx deep 2 100000 0.017 6 0 0 Limit > messages_history_idx 0
9 A messages_history_idx deep 3 100000 0.011 6 0 0 Limit > messages_history_idx 0
10 A messages_history_idx deep 4 100000 0.022 6 0 0 Limit > messages_history_idx 0
11 A messages_history_idx deep 5 100000 0.009 6 0 0 Limit > messages_history_idx 0
12 A messages_history_idx write500 1 100000 3.997 INSERT 500 + COMMIT 500
13 A messages_history_idx write500 2 100000 3.276 INSERT 500 + COMMIT 500
14 A messages_history_idx write500 3 100000 2.616 INSERT 500 + COMMIT 500
15 A messages_history_idx write500 4 100000 2.632 INSERT 500 + COMMIT 500
16 A messages_history_idx write500 5 100000 2.467 INSERT 500 + COMMIT 500
17 B messages_history_covering_idx first 1 100000 0.009 5 0 0 Limit > messages_history_covering_idx 0
18 B messages_history_covering_idx first 2 100000 0.011 5 0 0 Limit > messages_history_covering_idx 0
19 B messages_history_covering_idx first 3 100000 0.013 5 0 0 Limit > messages_history_covering_idx 0
20 B messages_history_covering_idx first 4 100000 0.01 5 0 0 Limit > messages_history_covering_idx 0
21 B messages_history_covering_idx first 5 100000 0.016 5 0 0 Limit > messages_history_covering_idx 0
22 B messages_history_covering_idx deep 1 100000 0.009 4 0 0 Limit > messages_history_covering_idx 0
23 B messages_history_covering_idx deep 2 100000 0.009 4 0 0 Limit > messages_history_covering_idx 0
24 B messages_history_covering_idx deep 3 100000 0.011 4 0 0 Limit > messages_history_covering_idx 0
25 B messages_history_covering_idx deep 4 100000 0.012 4 0 0 Limit > messages_history_covering_idx 0
26 B messages_history_covering_idx deep 5 100000 0.01 4 0 0 Limit > messages_history_covering_idx 0
27 B messages_history_covering_idx write500 1 100000 2.638 INSERT 500 + COMMIT 500
28 B messages_history_covering_idx write500 2 100000 12.557 INSERT 500 + COMMIT 500
29 B messages_history_covering_idx write500 3 100000 2.7 INSERT 500 + COMMIT 500
30 B messages_history_covering_idx write500 4 100000 2.382 INSERT 500 + COMMIT 500
31 B messages_history_covering_idx write500 5 100000 2.439 INSERT 500 + COMMIT 500
+11
View File
@@ -0,0 +1,11 @@
UTC: 2026-10-02T09:42:09.839961+00:00
PostgreSQL: 17.6 (Debian 17.6-2.pgdg12+1)
Synthetic chat sizes: hot=80000, medium=15000, cold=5000; fixed 51-row pages; deep cursor=72000
Variant A: messages_history_idx
{"variant": "A", "operation": "first", "plan": {"Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, "Total Cost": 7.65, "Plan Rows": 51, "Plan Width": 75, "Actual Startup Time": 0.001, "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0, "Plans": [{"Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, "Scan Direction": "Forward", "Index Name": "messages_history_idx", "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, "Total Cost": 11340.4, "Plan Rows": 80004, "Plan Width": 75, "Actual Startup Time": 0.001, "Actual Total Time": 0.004, "Actual Rows": 51, "Actual Loops": 1, "Index Cond": "(chat_id = 'a9024646-24db-4984-b912-1030eea3ed60'::uuid)", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0}]}}
{"variant": "A", "operation": "deep", "plan": {"Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, "Total Cost": 53.72, "Plan Rows": 51, "Plan Width": 75, "Actual Startup Time": 0.002, "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0, "Plans": [{"Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, "Scan Direction": "Forward", "Index Name": "messages_history_idx", "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, "Total Cost": 6225.66, "Plan Rows": 5956, "Plan Width": 75, "Actual Startup Time": 0.001, "Actual Total Time": 0.004, "Actual Rows": 51, "Actual Loops": 1, "Index Cond": "((chat_id = 'a9024646-24db-4984-b912-1030eea3ed60'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 09:42:09.355081+00'::timestamp with time zone, '3101b2d4-b2be-4696-9cf8-ea625d0e9d29'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0}]}}
Variant B: messages_history_covering_idx
{"variant": "B", "operation": "first", "plan": {"Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, "Total Cost": 3.89, "Plan Rows": 51, "Plan Width": 75, "Actual Startup Time": 0.002, "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0, "Plans": [{"Node Type": "Index Only Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, "Scan Direction": "Forward", "Index Name": "messages_history_covering_idx", "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, "Total Cost": 5458.29, "Plan Rows": 80107, "Plan Width": 75, "Actual Startup Time": 0.002, "Actual Total Time": 0.005, "Actual Rows": 51, "Actual Loops": 1, "Index Cond": "(chat_id = 'a9024646-24db-4984-b912-1030eea3ed60'::uuid)", "Rows Removed by Index Recheck": 0, "Heap Fetches": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0}]}}
{"variant": "B", "operation": "deep", "plan": {"Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, "Total Cost": 4.04, "Plan Rows": 51, "Plan Width": 75, "Actual Startup Time": 0.002, "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 4, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0, "Plans": [{"Node Type": "Index Only Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, "Scan Direction": "Forward", "Index Name": "messages_history_covering_idx", "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, "Total Cost": 523.64, "Plan Rows": 7361, "Plan Width": 75, "Actual Startup Time": 0.002, "Actual Total Time": 0.004, "Actual Rows": 51, "Actual Loops": 1, "Index Cond": "((chat_id = 'a9024646-24db-4984-b912-1030eea3ed60'::uuid) AND (ROW(created_at, id) > ROW('2026-10-02 09:42:09.355081+00'::timestamp with time zone, '3101b2d4-b2be-4696-9cf8-ea625d0e9d29'::uuid)))", "Rows Removed by Index Recheck": 0, "Heap Fetches": 0, "Shared Hit Blocks": 4, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, "Local Hit Blocks": 0, "Local Read Blocks": 0, "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, "Temp Written Blocks": 0}]}}
Original history index restored; committed write rows=5000
Index size after benchmark, original A=6799360 bytes, covering B=11935744 bytes; B dropped after measurement
+19
View File
@@ -0,0 +1,19 @@
UTC start: 2026-10-02T09:51:09Z
Source: mtusi2026lab2_postgres_data; new volume: mtusi2026lab2_restore_20261002125101_21469
pg_dump custom-format backup: 3441039 bytes, 0 seconds
pg_restore into fresh volume: 0 seconds
New PostgreSQL + pg_restore + restored API ready: 10 seconds
Source PostgreSQL stopped; verification uses only postgres_restore and api_restore
Restore fingerprint PASS (all rows, ordered by primary key):
users: count=110 sha256=84e13a36176df82d787eeb17cf160e722adb27b354efc63cb0b071b60cb3d0dc
chats: count=26 sha256=53597c37349eeb1dd2dcc4b844ebd0daf609ec94b0f0b761c49f2494d8d5f283
memberships: count=41 sha256=04f4aa2eda1dac52d50043574125826e294c572f9e1ca38e9ae871ad12ac3897
messages: count=115026 sha256=f59985688652b2c9a4217847a4c4967ab7763714913fc59980e6e905bb43aa9d
sessions: count=49 sha256=81c9bd6d920343331e8855ffccf7122f21f02778decedd3f4cc3bb76c8f62147
Selected synthetic messages PASS (id, text SHA-256):
c00beec9-c124-44c5-8a91-0629359b0fbc 535c5b38862ae8ece532e63f3f4003ed180a8d072364909e203a07c0e586f564
ebe3793f-8a8e-4ea7-b440-b4d6b98758cb 0bef8c417a079915200fb7168a9ccd09a91f72761098499885c55c762c98e125
7d0b0c48-437f-45d0-98ab-05d80ee615a6 160bf34ba510916e90b48de2484fd9e055fdff06a103da43c94488ca43736fd0
Restored API PASS: readiness 200, active token reads first message 200, expired token 401
UTC verified: 2026-10-02T09:51:20Z
Recovery point: pg_dump snapshot; writes committed afterward are outside this backup