|
20 | 20 | 'postgres', q(
|
21 | 21 | CREATE EXTENSION amcheck;
|
22 | 22 |
|
| 23 | + CREATE SCHEMA test_amcheck; |
| 24 | + SET search_path = test_amcheck; |
| 25 | +
|
23 | 26 | CREATE FUNCTION ok_cmp (int4, int4)
|
24 |
| - RETURNS int LANGUAGE sql AS |
| 27 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
25 | 28 | $$
|
26 | 29 | SELECT
|
27 | 30 | CASE WHEN $1 < $2 THEN -1
|
|
34 | 37 | --- Check 1: uniqueness violation.
|
35 | 38 | ---
|
36 | 39 | CREATE FUNCTION ok_cmp1 (int4, int4)
|
37 |
| - RETURNS int LANGUAGE sql AS |
| 40 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
38 | 41 | $$
|
39 | 42 | SELECT ok_cmp($1, $2);
|
40 | 43 | $$;
|
|
43 | 46 | --- Make values 768 and 769 look equal.
|
44 | 47 | ---
|
45 | 48 | CREATE FUNCTION bad_cmp1 (int4, int4)
|
46 |
| - RETURNS int LANGUAGE sql AS |
| 49 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
47 | 50 | $$
|
48 | 51 | SELECT
|
49 | 52 | CASE WHEN ($1 = 768 AND $2 = 769) OR
|
|
56 | 59 | --- Check 2: uniqueness violation without deduplication.
|
57 | 60 | ---
|
58 | 61 | CREATE FUNCTION ok_cmp2 (int4, int4)
|
59 |
| - RETURNS int LANGUAGE sql AS |
| 62 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
60 | 63 | $$
|
61 | 64 | SELECT ok_cmp($1, $2);
|
62 | 65 | $$;
|
63 | 66 |
|
64 | 67 | CREATE FUNCTION bad_cmp2 (int4, int4)
|
65 |
| - RETURNS int LANGUAGE sql AS |
| 68 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
66 | 69 | $$
|
67 | 70 | SELECT
|
68 | 71 | CASE WHEN $1 = $2 AND $1 = 400 THEN -1
|
|
74 | 77 | --- Check 3: uniqueness violation with deduplication.
|
75 | 78 | ---
|
76 | 79 | CREATE FUNCTION ok_cmp3 (int4, int4)
|
77 |
| - RETURNS int LANGUAGE sql AS |
| 80 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
78 | 81 | $$
|
79 | 82 | SELECT ok_cmp($1, $2);
|
80 | 83 | $$;
|
81 | 84 |
|
82 | 85 | CREATE FUNCTION bad_cmp3 (int4, int4)
|
83 |
| - RETURNS int LANGUAGE sql AS |
| 86 | + RETURNS int LANGUAGE sql SET search_path = test_amcheck AS |
84 | 87 | $$
|
85 | 88 | SELECT bad_cmp2($1, $2);
|
86 | 89 | $$;
|
|
142 | 145 | # We have not yet broken the index, so we should get no corruption
|
143 | 146 | $result = $node->safe_psql(
|
144 | 147 | 'postgres', q(
|
145 |
| - SELECT bt_index_check('bttest_unique_idx1', true, true); |
| 148 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx1', true, true); |
146 | 149 | ));
|
147 | 150 | is($result, '', 'run amcheck on non-broken bttest_unique_idx1');
|
148 | 151 |
|
149 | 152 | # Change the operator class to use a function which considers certain different
|
150 | 153 | # values to be equal.
|
151 | 154 | $node->safe_psql(
|
152 | 155 | 'postgres', q(
|
| 156 | + SET search_path = test_amcheck; |
153 | 157 | UPDATE pg_catalog.pg_amproc SET
|
154 | 158 | amproc = 'bad_cmp1'::regproc
|
155 | 159 | WHERE amproc = 'ok_cmp1'::regproc;
|
156 | 160 | ));
|
157 | 161 |
|
158 | 162 | ($result, $stdout, $stderr) = $node->psql(
|
159 | 163 | 'postgres', q(
|
160 |
| - SELECT bt_index_check('bttest_unique_idx1', true, true); |
| 164 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx1', true, true); |
161 | 165 | ));
|
162 | 166 | ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx1"/,
|
163 | 167 | 'detected uniqueness violation for index "bttest_unique_idx1"');
|
|
175 | 179 | # but no uniqueness violation.
|
176 | 180 | ($result, $stdout, $stderr) = $node->psql(
|
177 | 181 | 'postgres', q(
|
178 |
| - SELECT bt_index_check('bttest_unique_idx2', true, true); |
| 182 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx2', true, true); |
179 | 183 | ));
|
180 | 184 | ok( $stderr =~ /item order invariant violated for index "bttest_unique_idx2"/,
|
181 | 185 | 'detected item order invariant violation for index "bttest_unique_idx2"');
|
182 | 186 |
|
183 | 187 | $node->safe_psql(
|
184 | 188 | 'postgres', q(
|
| 189 | + SET search_path = test_amcheck; |
185 | 190 | UPDATE pg_catalog.pg_amproc SET
|
186 | 191 | amproc = 'ok_cmp2'::regproc
|
187 | 192 | WHERE amproc = 'bad_cmp2'::regproc;
|
188 | 193 | ));
|
189 | 194 |
|
190 | 195 | ($result, $stdout, $stderr) = $node->psql(
|
191 | 196 | 'postgres', q(
|
192 |
| - SELECT bt_index_check('bttest_unique_idx2', true, true); |
| 197 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx2', true, true); |
193 | 198 | ));
|
194 | 199 | ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx2"/,
|
195 | 200 | 'detected uniqueness violation for index "bttest_unique_idx2"');
|
|
206 | 211 | # but no uniqueness violation.
|
207 | 212 | ($result, $stdout, $stderr) = $node->psql(
|
208 | 213 | 'postgres', q(
|
209 |
| - SELECT bt_index_check('bttest_unique_idx3', true, true); |
| 214 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx3', true, true); |
210 | 215 | ));
|
211 | 216 | ok( $stderr =~ /item order invariant violated for index "bttest_unique_idx3"/,
|
212 | 217 | 'detected item order invariant violation for index "bttest_unique_idx3"');
|
|
215 | 220 | # with different visibility.
|
216 | 221 | $node->safe_psql(
|
217 | 222 | 'postgres', q(
|
| 223 | + SET search_path = test_amcheck; |
218 | 224 | DELETE FROM bttest_unique3 WHERE 380 <= i AND i <= 420;
|
219 | 225 | INSERT INTO bttest_unique3 (SELECT * FROM generate_series(380, 420));
|
220 | 226 | INSERT INTO bttest_unique3 VALUES (400);
|
|
228 | 234 |
|
229 | 235 | $node->safe_psql(
|
230 | 236 | 'postgres', q(
|
| 237 | + SET search_path = test_amcheck; |
231 | 238 | UPDATE pg_catalog.pg_amproc SET
|
232 | 239 | amproc = 'ok_cmp3'::regproc
|
233 | 240 | WHERE amproc = 'bad_cmp3'::regproc;
|
234 | 241 | ));
|
235 | 242 |
|
236 | 243 | ($result, $stdout, $stderr) = $node->psql(
|
237 | 244 | 'postgres', q(
|
238 |
| - SELECT bt_index_check('bttest_unique_idx3', true, true); |
| 245 | + SELECT bt_index_check('test_amcheck.bttest_unique_idx3', true, true); |
239 | 246 | ));
|
240 | 247 | ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx3"/,
|
241 | 248 | 'detected uniqueness violation for index "bttest_unique_idx3"');
|
|
0 commit comments