Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f35f30f

Browse files
committed
Add amcheck missing downlink tests.
Also use palloc0() for main amcheck state, and adjust a few comments. Somehow I pushed old version of patch in commit 4eaf7ea, so commit the difference. Peter Geoghegan
1 parent f04d4ac commit f35f30f

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

contrib/amcheck/expected/check_btree.out

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
-- minimal test, basically just verifying that amcheck
21
CREATE TABLE bttest_a(id int8);
32
CREATE TABLE bttest_b(id int8);
43
CREATE TABLE bttest_multi(id int8, data int8);
4+
CREATE TABLE delete_test_table (a bigint, b bigint, c bigint, d bigint);
5+
-- Stabalize tests
6+
ALTER TABLE bttest_a SET (autovacuum_enabled = false);
7+
ALTER TABLE bttest_b SET (autovacuum_enabled = false);
8+
ALTER TABLE bttest_multi SET (autovacuum_enabled = false);
9+
ALTER TABLE delete_test_table SET (autovacuum_enabled = false);
510
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
611
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
712
INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
@@ -120,9 +125,25 @@ SELECT bt_index_parent_check('bttest_multi_idx', true);
120125

121126
(1 row)
122127

128+
--
129+
-- Test for multilevel page deletion/downlink present checks
130+
--
131+
INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
132+
ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
133+
DELETE FROM delete_test_table WHERE a > 40000;
134+
VACUUM delete_test_table;
135+
DELETE FROM delete_test_table WHERE a > 10;
136+
VACUUM delete_test_table;
137+
SELECT bt_index_parent_check('delete_test_table_pkey', true);
138+
bt_index_parent_check
139+
-----------------------
140+
141+
(1 row)
142+
123143
-- cleanup
124144
DROP TABLE bttest_a;
125145
DROP TABLE bttest_b;
126146
DROP TABLE bttest_multi;
147+
DROP TABLE delete_test_table;
127148
DROP OWNED BY bttest_role; -- permissions
128149
DROP ROLE bttest_role;

contrib/amcheck/sql/check_btree.sql

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
-- minimal test, basically just verifying that amcheck
21
CREATE TABLE bttest_a(id int8);
32
CREATE TABLE bttest_b(id int8);
43
CREATE TABLE bttest_multi(id int8, data int8);
4+
CREATE TABLE delete_test_table (a bigint, b bigint, c bigint, d bigint);
5+
6+
-- Stabalize tests
7+
ALTER TABLE bttest_a SET (autovacuum_enabled = false);
8+
ALTER TABLE bttest_b SET (autovacuum_enabled = false);
9+
ALTER TABLE bttest_multi SET (autovacuum_enabled = false);
10+
ALTER TABLE delete_test_table SET (autovacuum_enabled = false);
511

612
INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
713
INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
@@ -71,9 +77,21 @@ TRUNCATE bttest_multi;
7177
INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
7278
SELECT bt_index_parent_check('bttest_multi_idx', true);
7379

80+
--
81+
-- Test for multilevel page deletion/downlink present checks
82+
--
83+
INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
84+
ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
85+
DELETE FROM delete_test_table WHERE a > 40000;
86+
VACUUM delete_test_table;
87+
DELETE FROM delete_test_table WHERE a > 10;
88+
VACUUM delete_test_table;
89+
SELECT bt_index_parent_check('delete_test_table_pkey', true);
90+
7491
-- cleanup
7592
DROP TABLE bttest_a;
7693
DROP TABLE bttest_b;
7794
DROP TABLE bttest_multi;
95+
DROP TABLE delete_test_table;
7896
DROP OWNED BY bttest_role; -- permissions
7997
DROP ROLE bttest_role;

contrib/amcheck/verify_nbtree.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ bt_check_every_level(Relation rel, Relation heaprel, bool readonly,
340340
/*
341341
* Initialize state for entire verification operation
342342
*/
343-
state = palloc(sizeof(BtreeCheckState));
343+
state = palloc0(sizeof(BtreeCheckState));
344344
state->rel = rel;
345345
state->heaprel = heaprel;
346346
state->readonly = readonly;
@@ -772,13 +772,15 @@ bt_check_level_from_leftmost(BtreeCheckState *state, BtreeLevel level)
772772
* - That tuples report that they have the expected number of attributes.
773773
* INCLUDE index pivot tuples should not contain non-key attributes.
774774
*
775-
* Furthermore, when state passed shows ShareLock held, and target page is
776-
* internal page, function also checks:
775+
* Furthermore, when state passed shows ShareLock held, function also checks:
777776
*
778777
* - That all child pages respect downlinks lower bound.
779778
*
779+
* - That downlink to block was encountered in parent where that's expected.
780+
* (Limited to heapallindexed readonly callers.)
781+
*
780782
* This is also where heapallindexed callers use their Bloom filter to
781-
* fingerprint IndexTuples.
783+
* fingerprint IndexTuples for later IndexBuildHeapScan() verification.
782784
*
783785
* Note: Memory allocated in this routine is expected to be released by caller
784786
* resetting state->targetcontext.
@@ -1074,7 +1076,7 @@ bt_target_page_check(BtreeCheckState *state)
10741076
/*
10751077
* * Check if page has a downlink in parent *
10761078
*
1077-
* This can only be checked in readonly + heapallindexed case.
1079+
* This can only be checked in heapallindexed + readonly case.
10781080
*/
10791081
if (state->heapallindexed && state->readonly)
10801082
bt_downlink_missing_check(state);
@@ -1561,7 +1563,7 @@ bt_downlink_missing_check(BtreeCheckState *state)
15611563
* infinity items. Besides, bt_downlink_check() is unwilling to descend
15621564
* multiple levels. (The similar bt_downlink_check() P_ISDELETED() check
15631565
* within bt_check_level_from_leftmost() won't reach the page either, since
1564-
* the leaf's live siblings should have their sibling links updating to
1566+
* the leaf's live siblings should have their sibling links updated to
15651567
* bypass the deletion target page when it is marked fully dead.)
15661568
*
15671569
* If this error is raised, it might be due to a previous multi-level page

0 commit comments

Comments
 (0)