]> granicus.if.org Git - postgresql/blob - contrib/amcheck/expected/check_btree.out
Make heap TID a tiebreaker nbtree index column.
[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 test for index with included columns
113 SELECT bt_index_parent_check('bttest_multi_idx', true);
114  bt_index_parent_check 
115 -----------------------
116  
117 (1 row)
118
119 -- repeat expansive test 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);
123  bt_index_parent_check 
124 -----------------------
125  
126 (1 row)
127
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 many entries, and vacuum. This causes page deletions.
134 DELETE FROM delete_test_table WHERE a > 40000;
135 VACUUM delete_test_table;
136 -- Delete most entries, and vacuum, deleting internal pages and creating "fast
137 -- root"
138 DELETE FROM delete_test_table WHERE a < 79990;
139 VACUUM delete_test_table;
140 SELECT bt_index_parent_check('delete_test_table_pkey', true);
141  bt_index_parent_check 
142 -----------------------
143  
144 (1 row)
145
146 --
147 -- BUG #15597: must not assume consistent input toasting state when forming
148 -- tuple.  Bloom filter must fingerprint normalized index tuple representation.
149 --
150 CREATE TABLE toast_bug(buggy text);
151 ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE plain;
152 -- pg_attribute entry for toasty.buggy will have plain storage:
153 CREATE INDEX toasty ON toast_bug(buggy);
154 -- Whereas pg_attribute entry for toast_bug.buggy now has extended storage:
155 ALTER TABLE toast_bug ALTER COLUMN buggy SET STORAGE extended;
156 -- Insert compressible heap tuple (comfortably exceeds TOAST_TUPLE_THRESHOLD):
157 INSERT INTO toast_bug SELECT repeat('a', 2200);
158 -- Should not get false positive report of corruption:
159 SELECT bt_index_check('toasty', true);
160  bt_index_check 
161 ----------------
162  
163 (1 row)
164
165 -- cleanup
166 DROP TABLE bttest_a;
167 DROP TABLE bttest_b;
168 DROP TABLE bttest_multi;
169 DROP TABLE delete_test_table;
170 DROP TABLE toast_bug;
171 DROP OWNED BY bttest_role; -- permissions
172 DROP ROLE bttest_role;