]> granicus.if.org Git - postgresql/blob - contrib/amcheck/expected/check_btree.out
Add test coverage for rootdescend verification.
[postgresql] / contrib / amcheck / expected / check_btree.out
1 CREATE TABLE bttest_a(id int8);
2 CREATE TABLE bttest_b(id int8);
3 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);
10 INSERT INTO bttest_a SELECT * FROM generate_series(1, 100000);
11 INSERT INTO bttest_b SELECT * FROM generate_series(100000, 1, -1);
12 INSERT INTO bttest_multi SELECT i, i%2  FROM generate_series(1, 100000) as i;
13 CREATE INDEX bttest_a_idx ON bttest_a USING btree (id);
14 CREATE INDEX bttest_b_idx ON bttest_b USING btree (id);
15 CREATE UNIQUE INDEX bttest_multi_idx ON bttest_multi
16 USING btree (id) INCLUDE (data);
17 CREATE ROLE bttest_role;
18 -- verify permissions are checked (error due to function not callable)
19 SET ROLE bttest_role;
20 SELECT bt_index_check('bttest_a_idx'::regclass);
21 ERROR:  permission denied for function bt_index_check
22 SELECT bt_index_parent_check('bttest_a_idx'::regclass);
23 ERROR:  permission denied for function bt_index_parent_check
24 RESET ROLE;
25 -- we, intentionally, don't check relation permissions - it's useful
26 -- to run this cluster-wide with a restricted account, and as tested
27 -- above explicit permission has to be granted for that.
28 GRANT EXECUTE ON FUNCTION bt_index_check(regclass) TO bttest_role;
29 GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO bttest_role;
30 GRANT EXECUTE ON FUNCTION bt_index_check(regclass, boolean) TO bttest_role;
31 GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass, boolean) TO bttest_role;
32 SET ROLE bttest_role;
33 SELECT bt_index_check('bttest_a_idx');
34  bt_index_check 
35 ----------------
36  
37 (1 row)
38
39 SELECT bt_index_parent_check('bttest_a_idx');
40  bt_index_parent_check 
41 -----------------------
42  
43 (1 row)
44
45 RESET ROLE;
46 -- verify plain tables are rejected (error)
47 SELECT bt_index_check('bttest_a');
48 ERROR:  "bttest_a" is not an index
49 SELECT bt_index_parent_check('bttest_a');
50 ERROR:  "bttest_a" is not an index
51 -- verify non-existing indexes are rejected (error)
52 SELECT bt_index_check(17);
53 ERROR:  could not open relation with OID 17
54 SELECT bt_index_parent_check(17);
55 ERROR:  could not open relation with OID 17
56 -- verify wrong index types are rejected (error)
57 BEGIN;
58 CREATE INDEX bttest_a_brin_idx ON bttest_a USING brin(id);
59 SELECT bt_index_parent_check('bttest_a_brin_idx');
60 ERROR:  only B-Tree indexes are supported as targets for verification
61 DETAIL:  Relation "bttest_a_brin_idx" is not a B-Tree index.
62 ROLLBACK;
63 -- normal check outside of xact
64 SELECT bt_index_check('bttest_a_idx');
65  bt_index_check 
66 ----------------
67  
68 (1 row)
69
70 -- more expansive tests
71 SELECT bt_index_check('bttest_a_idx', true);
72  bt_index_check 
73 ----------------
74  
75 (1 row)
76
77 SELECT bt_index_parent_check('bttest_b_idx', true);
78  bt_index_parent_check 
79 -----------------------
80  
81 (1 row)
82
83 BEGIN;
84 SELECT bt_index_check('bttest_a_idx');
85  bt_index_check 
86 ----------------
87  
88 (1 row)
89
90 SELECT bt_index_parent_check('bttest_b_idx');
91  bt_index_parent_check 
92 -----------------------
93  
94 (1 row)
95
96 -- make sure we don't have any leftover locks
97 SELECT * FROM pg_locks
98 WHERE relation = ANY(ARRAY['bttest_a', 'bttest_a_idx', 'bttest_b', 'bttest_b_idx']::regclass[])
99     AND pid = pg_backend_pid();
100  locktype | database | relation | page | tuple | virtualxid | transactionid | classid | objid | objsubid | virtualtransaction | pid | mode | granted | fastpath 
101 ----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------
102 (0 rows)
103
104 COMMIT;
105 -- normal check outside of xact for index with included columns
106 SELECT bt_index_check('bttest_multi_idx');
107  bt_index_check 
108 ----------------
109  
110 (1 row)
111
112 -- more expansive tests for index with included columns
113 SELECT bt_index_parent_check('bttest_multi_idx', true, true);
114  bt_index_parent_check 
115 -----------------------
116  
117 (1 row)
118
119 -- repeat expansive tests for index built using insertions
120 TRUNCATE bttest_multi;
121 INSERT INTO bttest_multi SELECT i, i%2  FROM generate_series(1, 100000) as i;
122 SELECT bt_index_parent_check('bttest_multi_idx', true, true);
123  bt_index_parent_check 
124 -----------------------
125  
126 (1 row)
127
128 --
129 -- Test for multilevel page deletion/downlink present checks, and rootdescend
130 -- checks
131 --
132 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
133 ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
134 -- Delete most entries, and vacuum, deleting internal pages and creating "fast
135 -- root"
136 DELETE FROM delete_test_table WHERE a < 79990;
137 VACUUM delete_test_table;
138 SELECT bt_index_parent_check('delete_test_table_pkey', true);
139  bt_index_parent_check 
140 -----------------------
141  
142 (1 row)
143
144 --
145 -- BUG #15597: must not assume consistent input toasting state when forming
146 -- tuple.  Bloom filter must fingerprint normalized index tuple representation.
147 --
148 CREATE TABLE toast_bug(buggy text);
149 ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE plain;
150 -- pg_attribute entry for toasty.buggy will have plain storage:
151 CREATE INDEX toasty ON toast_bug(buggy);
152 -- Whereas pg_attribute entry for toast_bug.buggy now has extended storage:
153 ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE extended;
154 -- Insert compressible heap tuple (comfortably exceeds TOAST_TUPLE_THRESHOLD):
155 INSERT INTO toast_bug SELECT repeat('a', 2200);
156 -- Should not get false positive report of corruption:
157 SELECT bt_index_check('toasty', true);
158  bt_index_check 
159 ----------------
160  
161 (1 row)
162
163 -- cleanup
164 DROP TABLE bttest_a;
165 DROP TABLE bttest_b;
166 DROP TABLE bttest_multi;
167 DROP TABLE delete_test_table;
168 DROP TABLE toast_bug;
169 DROP OWNED BY bttest_role; -- permissions
170 DROP ROLE bttest_role;