Debian Codegraph @

contrib/amcheck/expected/check_btree.out

raw
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 -- Stabilize 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) WITH (deduplicate_items = ON);
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 regress_bttest_role;
18 -- verify permissions are checked (error due to function not callable)
19 SET ROLE regress_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 regress_bttest_role;
29 GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass) TO regress_bttest_role;
30 GRANT EXECUTE ON FUNCTION bt_index_check(regclass, boolean) TO regress_bttest_role;
31 GRANT EXECUTE ON FUNCTION bt_index_parent_check(regclass, boolean) TO regress_bttest_role;
32 SET ROLE regress_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: expected "btree" index as targets for verification
61 DETAIL: Relation "bttest_a_brin_idx" is a brin 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 | waitstart
101 ----------+----------+----------+------+-------+------------+---------------+---------+-------+----------+--------------------+-----+------+---------+----------+-----------
102 (0 rows)
103
104 COMMIT;
105 -- Deduplication
106 TRUNCATE bttest_a;
107 INSERT INTO bttest_a SELECT 42 FROM generate_series(1, 2000);
108 SELECT bt_index_check('bttest_a_idx', true);
109 bt_index_check
110 ----------------
111
112 (1 row)
113
114 -- normal check outside of xact for index with included columns
115 SELECT bt_index_check('bttest_multi_idx');
116 bt_index_check
117 ----------------
118
119 (1 row)
120
121 -- more expansive tests for index with included columns
122 SELECT bt_index_parent_check('bttest_multi_idx', true, true);
123 bt_index_parent_check
124 -----------------------
125
126 (1 row)
127
128 -- repeat expansive tests for index built using insertions
129 TRUNCATE bttest_multi;
130 INSERT INTO bttest_multi SELECT i, i%2 FROM generate_series(1, 100000) as i;
131 SELECT bt_index_parent_check('bttest_multi_idx', true, true);
132 bt_index_parent_check
133 -----------------------
134
135 (1 row)
136
137 --
138 -- Test for multilevel page deletion/downlink present checks, and rootdescend
139 -- checks
140 --
141 INSERT INTO delete_test_table SELECT i, 1, 2, 3 FROM generate_series(1,80000) i;
142 ALTER TABLE delete_test_table ADD PRIMARY KEY (a,b,c,d);
143 -- Delete most entries, and vacuum, deleting internal pages and creating "fast
144 -- root"
145 DELETE FROM delete_test_table WHERE a < 79990;
146 VACUUM delete_test_table;
147 SELECT bt_index_parent_check('delete_test_table_pkey', true);
148 bt_index_parent_check
149 -----------------------
150
151 (1 row)
152
153 --
154 -- BUG #15597: must not assume consistent input toasting state when forming
155 -- tuple. Bloom filter must fingerprint normalized index tuple representation.
156 --
157 CREATE TABLE toast_bug(buggy text);
158 ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE extended;
159 CREATE INDEX toasty ON toast_bug(buggy);
160 -- pg_attribute entry for toasty.buggy (the index) will have plain storage:
161 UPDATE pg_attribute SET attstorage = 'p'
162 WHERE attrelid = 'toasty'::regclass AND attname = 'buggy';
163 -- Whereas pg_attribute entry for toast_bug.buggy (the table) still has extended storage:
164 SELECT attstorage FROM pg_attribute
165 WHERE attrelid = 'toast_bug'::regclass AND attname = 'buggy';
166 attstorage
167 ------------
168 x
169 (1 row)
170
171 -- Insert compressible heap tuple (comfortably exceeds TOAST_TUPLE_THRESHOLD):
172 INSERT INTO toast_bug SELECT repeat('a', 2200);
173 -- Should not get false positive report of corruption:
174 SELECT bt_index_check('toasty', true);
175 bt_index_check
176 ----------------
177
178 (1 row)
179
180 --
181 -- Check that index expressions and predicates are run as the table's owner,
182 -- with empty search_path
183 --
184 TRUNCATE bttest_a;
185 INSERT INTO bttest_a SELECT * FROM generate_series(1, 1000);
186 ALTER TABLE bttest_a OWNER TO regress_bttest_role;
187 -- A dummy index function checking current_user
188 CREATE FUNCTION ifun(int8) RETURNS int8 AS $$
189 BEGIN
190 ASSERT current_setting('search_path') = 'pg_catalog, pg_temp',
191 format('ifun(%s) called with current_schemas %s, search_path %s',
192 $1, current_schemas(true), current_setting('search_path'));
193 ASSERT "current_user"() = 'regress_bttest_role',
194 format('ifun(%s) called by %s', $1, current_user);
195 RETURN $1;
196 END;
197 $$ LANGUAGE plpgsql IMMUTABLE;
198 CREATE INDEX bttest_a_expr_idx ON bttest_a ((ifun(id) + ifun(0)))
199 WHERE ifun(id + 10) > ifun(10);
200 BEGIN;
201 SET LOCAL check_function_bodies = off;
202 CREATE SCHEMA preempt;
203 GRANT USAGE ON SCHEMA preempt TO regress_bttest_role;
204 SET LOCAL search_path = preempt, pg_catalog, public;
205 CREATE FUNCTION "current_user"() RETURNS name AS $$
206 broken
207 $$ LANGUAGE sql STABLE PARALLEL SAFE STRICT;
208 SELECT bt_index_check('bttest_a_expr_idx', true);
209 bt_index_check
210 ----------------
211
212 (1 row)
213
214 ROLLBACK;
215 -- UNIQUE constraint check
216 SELECT bt_index_check('bttest_a_idx', heapallindexed => true, checkunique => true);
217 bt_index_check
218 ----------------
219
220 (1 row)
221
222 SELECT bt_index_check('bttest_b_idx', heapallindexed => false, checkunique => true);
223 bt_index_check
224 ----------------
225
226 (1 row)
227
228 SELECT bt_index_parent_check('bttest_a_idx', heapallindexed => true, rootdescend => true, checkunique => true);
229 bt_index_parent_check
230 -----------------------
231
232 (1 row)
233
234 SELECT bt_index_parent_check('bttest_b_idx', heapallindexed => true, rootdescend => false, checkunique => true);
235 bt_index_parent_check
236 -----------------------
237
238 (1 row)
239
240 -- Check that null values in an unique index are not treated as equal
241 CREATE TABLE bttest_unique_nulls (a serial, b int, c int UNIQUE);
242 INSERT INTO bttest_unique_nulls VALUES (generate_series(1, 10000), 2, default);
243 SELECT bt_index_check('bttest_unique_nulls_c_key', heapallindexed => true, checkunique => true);
244 bt_index_check
245 ----------------
246
247 (1 row)
248
249 CREATE INDEX on bttest_unique_nulls (b,c);
250 SELECT bt_index_check('bttest_unique_nulls_b_c_idx', heapallindexed => true, checkunique => true);
251 bt_index_check
252 ----------------
253
254 (1 row)
255
256 -- Check support of both 1B and 4B header sizes of short varlena datum
257 CREATE TABLE varlena_bug (v text);
258 ALTER TABLE varlena_bug ALTER column v SET storage plain;
259 INSERT INTO varlena_bug VALUES ('x');
260 COPY varlena_bug from stdin;
261 CREATE INDEX varlena_bug_idx on varlena_bug(v);
262 SELECT bt_index_check('varlena_bug_idx', true);
263 bt_index_check
264 ----------------
265
266 (1 row)
267
268 -- Also check that we compress varlena values, which were previously stored
269 -- uncompressed in index.
270 INSERT INTO varlena_bug VALUES (repeat('Test', 250));
271 ALTER TABLE varlena_bug ALTER COLUMN v SET STORAGE extended;
272 SELECT bt_index_check('varlena_bug_idx', true);
273 bt_index_check
274 ----------------
275
276 (1 row)
277
278 -- cleanup
279 DROP TABLE bttest_a;
280 DROP TABLE bttest_b;
281 DROP TABLE bttest_multi;
282 DROP TABLE delete_test_table;
283 DROP TABLE toast_bug;
284 DROP FUNCTION ifun(int8);
285 DROP TABLE bttest_unique_nulls;
286 DROP OWNED BY regress_bttest_role; -- permissions
287 DROP ROLE regress_bttest_role;
288 DROP TABLE varlena_bug;