лаба на 5
Skeleton contracts / contracts (pull_request) Failing after 34s

This commit is contained in:
2026-10-08 02:29:37 +03:00
parent a2e8ca2817
commit 173455c94e
13 changed files with 752 additions and 79 deletions
+23
View File
@@ -0,0 +1,23 @@
=== Grade 5: preparing skewed dataset ===
BEGIN
INSERT 0 1
INSERT 0 4
INSERT 0 4
INSERT 0 120000
COMMIT
ANALYZE
=== Dataset distribution ===
title | message_count
-----------------------+---------------
Benchmark large chat | 90000
Benchmark medium chat | 20000
Benchmark small chat | 8000
Benchmark tiny chat | 2000
(4 rows)
=== Total messages ===
total_messages
----------------
120000
(1 row)
+86
View File
@@ -0,0 +1,86 @@
Timing is on.
=== Grade 5: index comparison ===
NOTICE: table "bench_index_a" does not exist, skipping
DROP TABLE
Time: 1.402 ms
DROP TABLE
Time: 0.122 ms
NOTICE: table "bench_index_b" does not exist, skipping
SELECT 120000
Time: 100.016 ms
SELECT 120000
Time: 146.729 ms
CREATE INDEX
Time: 44.119 ms
CREATE INDEX
Time: 86.764 ms
VACUUM
Time: 139.424 ms
VACUUM
Time: 140.120 ms
=== Table and index sizes ===
variant | index_size
-------------------+------------
A: regular index | 6928 kB
B: covering index | 13 MB
(2 rows)
Time: 0.846 ms
=== Index A: large chat, deep page ===
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..19.65 rows=100 width=87) (actual time=0.030..0.046 rows=100 loops=1)
Buffers: shared hit=2 read=4
-> Index Scan using bench_a_history_idx on bench_index_a (cost=0.42..4303.33 rows=22377 width=87) (actual time=0.030..0.041 rows=100 loops=1)
Index Cond: ((chat_id = '66666666-6666-4666-8666-666666666661'::uuid) AND (created_at > '2026-01-01 00:01:00+00'::timestamp with time zone))
Buffers: shared hit=2 read=4
Planning:
Buffers: shared hit=32
Planning Time: 0.091 ms
Execution Time: 0.059 ms
(9 rows)
Time: 1.254 ms
=== Index B: large chat, deep page ===
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..8.07 rows=100 width=87) (actual time=0.038..0.064 rows=100 loops=1)
Buffers: shared hit=1 read=5
-> Index Only Scan using bench_b_history_idx on bench_index_b (cost=0.42..1730.46 rows=22596 width=87) (actual time=0.037..0.058 rows=100 loops=1)
Index Cond: ((chat_id = '66666666-6666-4666-8666-666666666661'::uuid) AND (created_at > '2026-01-01 00:01:00+00'::timestamp with time zone))
Heap Fetches: 0
Buffers: shared hit=1 read=5
Planning:
Buffers: shared hit=18
Planning Time: 0.079 ms
Execution Time: 0.074 ms
(10 rows)
Time: 0.315 ms
=== Index A: small chat ===
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..44.76 rows=100 width=87) (actual time=0.037..0.059 rows=100 loops=1)
Buffers: shared hit=3 read=3
-> Index Scan using bench_a_history_idx on bench_index_a (cost=0.42..3453.96 rows=7788 width=87) (actual time=0.037..0.052 rows=100 loops=1)
Index Cond: (chat_id = '66666666-6666-4666-8666-666666666663'::uuid)
Buffers: shared hit=3 read=3
Planning Time: 0.043 ms
Execution Time: 0.068 ms
(7 rows)
Time: 0.263 ms
=== Index B: small chat ===
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..8.02 rows=100 width=87) (actual time=0.023..0.074 rows=100 loops=1)
Buffers: shared hit=2 read=4
-> Index Only Scan using bench_b_history_idx on bench_index_b (cost=0.42..614.82 rows=8080 width=87) (actual time=0.022..0.067 rows=100 loops=1)
Index Cond: (chat_id = '66666666-6666-4666-8666-666666666663'::uuid)
Heap Fetches: 0
Buffers: shared hit=2 read=4
Planning Time: 0.042 ms
Execution Time: 0.085 ms
(8 rows)
Time: 0.308 ms
+1
View File
@@ -0,0 +1 @@
RESTORE_ELAPSED_SECONDS=1.03
+38
View File
@@ -0,0 +1,38 @@
=== Row counts by table ===
table_name | rows_count
---------------+------------
bench_index_a | 120000
bench_index_b | 120000
messages | 120000
(3 rows)
=== Message distribution by chat ===
chat_id | message_count
--------------------------------------+---------------
66666666-6666-4666-8666-666666666661 | 90000
66666666-6666-4666-8666-666666666662 | 20000
66666666-6666-4666-8666-666666666663 | 8000
66666666-6666-4666-8666-666666666664 | 2000
(4 rows)
=== Deterministic sample of messages ===
id | chat_id | sender_id | text | created_at
--------------------------------------+--------------------------------------+--------------------------------------+------------------------------+----------------------------
00000001-0000-4000-8000-000000000001 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 1 | 2026-01-01 00:00:00.001+00
00000002-0000-4000-8000-000000000002 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 2 | 2026-01-01 00:00:00.002+00
00000003-0000-4000-8000-000000000003 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 3 | 2026-01-01 00:00:00.003+00
00000004-0000-4000-8000-000000000004 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 4 | 2026-01-01 00:00:00.004+00
00000005-0000-4000-8000-000000000005 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 5 | 2026-01-01 00:00:00.005+00
00000006-0000-4000-8000-000000000006 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 6 | 2026-01-01 00:00:00.006+00
00000007-0000-4000-8000-000000000007 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 7 | 2026-01-01 00:00:00.007+00
00000008-0000-4000-8000-000000000008 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 8 | 2026-01-01 00:00:00.008+00
00000009-0000-4000-8000-000000000009 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 9 | 2026-01-01 00:00:00.009+00
0000000a-0000-4000-8000-00000000000a | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 10 | 2026-01-01 00:00:00.01+00
(10 rows)
=== Message content checksum ===
message_count | content_checksum
---------------+----------------------------------
120000 | 16c1cb06c01f4ec4f161e45b59a5dce7
(1 row)
+38
View File
@@ -0,0 +1,38 @@
=== Row counts by table ===
table_name | rows_count
---------------+------------
bench_index_a | 120000
bench_index_b | 120000
messages | 120000
(3 rows)
=== Message distribution by chat ===
chat_id | message_count
--------------------------------------+---------------
66666666-6666-4666-8666-666666666661 | 90000
66666666-6666-4666-8666-666666666662 | 20000
66666666-6666-4666-8666-666666666663 | 8000
66666666-6666-4666-8666-666666666664 | 2000
(4 rows)
=== Deterministic sample of messages ===
id | chat_id | sender_id | text | created_at
--------------------------------------+--------------------------------------+--------------------------------------+------------------------------+----------------------------
00000001-0000-4000-8000-000000000001 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 1 | 2026-01-01 00:00:00.001+00
00000002-0000-4000-8000-000000000002 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 2 | 2026-01-01 00:00:00.002+00
00000003-0000-4000-8000-000000000003 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 3 | 2026-01-01 00:00:00.003+00
00000004-0000-4000-8000-000000000004 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 4 | 2026-01-01 00:00:00.004+00
00000005-0000-4000-8000-000000000005 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 5 | 2026-01-01 00:00:00.005+00
00000006-0000-4000-8000-000000000006 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 6 | 2026-01-01 00:00:00.006+00
00000007-0000-4000-8000-000000000007 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 7 | 2026-01-01 00:00:00.007+00
00000008-0000-4000-8000-000000000008 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 8 | 2026-01-01 00:00:00.008+00
00000009-0000-4000-8000-000000000009 | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 9 | 2026-01-01 00:00:00.009+00
0000000a-0000-4000-8000-00000000000a | 66666666-6666-4666-8666-666666666661 | 55555555-5555-4555-8555-555555555555 | Grade 5 synthetic message 10 | 2026-01-01 00:00:00.01+00
(10 rows)
=== Message content checksum ===
message_count | content_checksum
---------------+----------------------------------
120000 | 16c1cb06c01f4ec4f161e45b59a5dce7
(1 row)
+97
View File
@@ -0,0 +1,97 @@
Timing is on.
=== Grade 5: repeated write benchmark ===
=== PostgreSQL 17.6; 10000 inserted rows per run ===
CREATE PROCEDURE
Time: 5.749 ms
NOTICE: === RUN 1, VARIANT A ===
NOTICE: Insert on "grade5_write_A_1" (cost=0.00..525.00 rows=0 width=0) (actual time=22.080..22.081 rows=0 loops=1)
NOTICE: Buffers: shared hit=40536 read=6 dirtied=278 written=274
NOTICE: WAL: records=20129 bytes=2895528
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.484..5.930 rows=10000 loops=1)
NOTICE: Planning:
NOTICE: Buffers: shared hit=12
NOTICE: Planning Time: 0.153 ms
NOTICE: Execution Time: 22.278 ms
CALL
Time: 301.986 ms
NOTICE: === RUN 1, VARIANT B ===
NOTICE: Insert on "grade5_write_B_1" (cost=0.00..525.00 rows=0 width=0) (actual time=22.852..22.852 rows=0 loops=1)
NOTICE: Buffers: shared hit=40770 read=6 dirtied=395 written=391
NOTICE: WAL: records=20246 bytes=3857376
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.351..5.782 rows=10000 loops=1)
NOTICE: Planning Time: 0.054 ms
NOTICE: Execution Time: 22.963 ms
CALL
Time: 324.262 ms
NOTICE: === RUN 2, VARIANT B ===
NOTICE: Insert on "grade5_write_B_2" (cost=0.00..525.00 rows=0 width=0) (actual time=21.701..21.701 rows=0 loops=1)
NOTICE: Buffers: shared hit=40770 read=6 dirtied=395 written=391
NOTICE: WAL: records=20246 bytes=3857376
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.425..5.720 rows=10000 loops=1)
NOTICE: Planning Time: 0.069 ms
NOTICE: Execution Time: 21.789 ms
CALL
Time: 422.448 ms
NOTICE: === RUN 2, VARIANT A ===
NOTICE: Insert on "grade5_write_A_2" (cost=0.00..525.00 rows=0 width=0) (actual time=22.510..22.510 rows=0 loops=1)
NOTICE: Buffers: shared hit=40536 read=6 dirtied=278 written=274
NOTICE: WAL: records=20129 bytes=2895528
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.424..6.208 rows=10000 loops=1)
NOTICE: Planning Time: 0.057 ms
NOTICE: Execution Time: 22.596 ms
CALL
Time: 294.527 ms
NOTICE: === RUN 3, VARIANT A ===
NOTICE: Insert on "grade5_write_A_3" (cost=0.00..525.00 rows=0 width=0) (actual time=24.216..24.217 rows=0 loops=1)
NOTICE: Buffers: shared hit=40536 read=6 dirtied=278 written=274
NOTICE: WAL: records=20129 bytes=2895528
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.752..6.839 rows=10000 loops=1)
NOTICE: Planning Time: 0.064 ms
NOTICE: Execution Time: 24.310 ms
CALL
Time: 279.345 ms
NOTICE: === RUN 3, VARIANT B ===
NOTICE: Insert on "grade5_write_B_3" (cost=0.00..525.00 rows=0 width=0) (actual time=24.158..24.159 rows=0 loops=1)
NOTICE: Buffers: shared hit=40770 read=6 dirtied=395 written=391
NOTICE: WAL: records=20246 bytes=3857376
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.425..6.257 rows=10000 loops=1)
NOTICE: Planning Time: 0.057 ms
NOTICE: Execution Time: 24.248 ms
CALL
Time: 393.958 ms
NOTICE: === RUN 4, VARIANT B ===
NOTICE: Insert on "grade5_write_B_4" (cost=0.00..525.00 rows=0 width=0) (actual time=23.306..23.307 rows=0 loops=1)
NOTICE: Buffers: shared hit=40770 read=6 dirtied=395 written=391
NOTICE: WAL: records=20246 bytes=3857376
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.440..6.001 rows=10000 loops=1)
NOTICE: Planning Time: 0.060 ms
NOTICE: Execution Time: 23.397 ms
CALL
Time: 351.346 ms
NOTICE: === RUN 4, VARIANT A ===
NOTICE: Insert on "grade5_write_A_4" (cost=0.00..525.00 rows=0 width=0) (actual time=92.972..92.973 rows=0 loops=1)
NOTICE: Buffers: shared hit=40536 read=6 dirtied=278 written=274
NOTICE: WAL: records=20129 bytes=2895528
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.489..5.808 rows=10000 loops=1)
NOTICE: Planning Time: 0.071 ms
NOTICE: Execution Time: 93.088 ms
CALL
Time: 354.370 ms
NOTICE: === RUN 5, VARIANT A ===
NOTICE: Insert on "grade5_write_A_5" (cost=0.00..525.00 rows=0 width=0) (actual time=24.264..24.264 rows=0 loops=1)
NOTICE: Buffers: shared hit=40536 read=6 dirtied=278 written=274
NOTICE: WAL: records=20129 bytes=2895528
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.634..6.771 rows=10000 loops=1)
NOTICE: Planning Time: 0.052 ms
NOTICE: Execution Time: 24.388 ms
CALL
Time: 328.367 ms
NOTICE: === RUN 5, VARIANT B ===
NOTICE: Insert on "grade5_write_B_5" (cost=0.00..525.00 rows=0 width=0) (actual time=26.081..26.082 rows=0 loops=1)
NOTICE: Buffers: shared hit=40770 read=6 dirtied=395 written=391
NOTICE: WAL: records=20246 bytes=3857376
NOTICE: -> Function Scan on generate_series g (cost=0.00..525.00 rows=10000 width=572) (actual time=0.408..6.748 rows=10000 loops=1)
NOTICE: Planning Time: 0.071 ms
NOTICE: Execution Time: 26.206 ms
CALL
Time: 383.466 ms
+24
View File
@@ -0,0 +1,24 @@
Timing is on.
=== Grade 5: write overhead comparison ===
=== Index A: insert 10000 messages ===
BEGIN
Time: 0.099 ms
INSERT 0 10000
Time: 27.003 ms
ROLLBACK
Time: 0.142 ms
=== Index B: insert 10000 messages ===
BEGIN
Time: 0.357 ms
INSERT 0 10000
Time: 25.934 ms
ROLLBACK
Time: 0.179 ms
=== Verify unchanged row counts ===
variant | count
---------+--------
A | 120000
B | 120000
(2 rows)
Time: 11.135 ms