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

Commit 59825d1

Browse files
committed
Fix buildfarm failures from 2af07e2.
Use GUC_ACTION_SAVE rather than GUC_ACTION_SET, necessary for working with parallel query. Now that the call requires more arguments, wrap the call in a new function to avoid code duplication and offer a place for a comment. Discussion: https://postgr.es/m/E1rhJpO-0027Wf-9L@gemulon.postgresql.org
1 parent a37a3e2 commit 59825d1

File tree

11 files changed

+52
-60
lines changed

11 files changed

+52
-60
lines changed

contrib/amcheck/t/004_verify_nbtree_unique.pl

+19-26
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@
2020
'postgres', q(
2121
CREATE EXTENSION amcheck;
2222
23-
CREATE SCHEMA test_amcheck;
24-
SET search_path = test_amcheck;
25-
2623
CREATE FUNCTION ok_cmp (int4, int4)
27-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
24+
RETURNS int LANGUAGE sql AS
2825
$$
2926
SELECT
3027
CASE WHEN $1 < $2 THEN -1
@@ -37,55 +34,55 @@
3734
--- Check 1: uniqueness violation.
3835
---
3936
CREATE FUNCTION ok_cmp1 (int4, int4)
40-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
37+
RETURNS int LANGUAGE sql AS
4138
$$
42-
SELECT ok_cmp($1, $2);
39+
SELECT public.ok_cmp($1, $2);
4340
$$;
4441
4542
---
4643
--- Make values 768 and 769 look equal.
4744
---
4845
CREATE FUNCTION bad_cmp1 (int4, int4)
49-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
46+
RETURNS int LANGUAGE sql AS
5047
$$
5148
SELECT
5249
CASE WHEN ($1 = 768 AND $2 = 769) OR
5350
($1 = 769 AND $2 = 768) THEN 0
54-
ELSE ok_cmp($1, $2)
51+
ELSE public.ok_cmp($1, $2)
5552
END;
5653
$$;
5754
5855
---
5956
--- Check 2: uniqueness violation without deduplication.
6057
---
6158
CREATE FUNCTION ok_cmp2 (int4, int4)
62-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
59+
RETURNS int LANGUAGE sql AS
6360
$$
64-
SELECT ok_cmp($1, $2);
61+
SELECT public.ok_cmp($1, $2);
6562
$$;
6663
6764
CREATE FUNCTION bad_cmp2 (int4, int4)
68-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
65+
RETURNS int LANGUAGE sql AS
6966
$$
7067
SELECT
7168
CASE WHEN $1 = $2 AND $1 = 400 THEN -1
72-
ELSE ok_cmp($1, $2)
69+
ELSE public.ok_cmp($1, $2)
7370
END;
7471
$$;
7572
7673
---
7774
--- Check 3: uniqueness violation with deduplication.
7875
---
7976
CREATE FUNCTION ok_cmp3 (int4, int4)
80-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
77+
RETURNS int LANGUAGE sql AS
8178
$$
82-
SELECT ok_cmp($1, $2);
79+
SELECT public.ok_cmp($1, $2);
8380
$$;
8481
8582
CREATE FUNCTION bad_cmp3 (int4, int4)
86-
RETURNS int LANGUAGE sql SET search_path = test_amcheck AS
83+
RETURNS int LANGUAGE sql AS
8784
$$
88-
SELECT bad_cmp2($1, $2);
85+
SELECT public.bad_cmp2($1, $2);
8986
$$;
9087
9188
---
@@ -145,23 +142,22 @@
145142
# We have not yet broken the index, so we should get no corruption
146143
$result = $node->safe_psql(
147144
'postgres', q(
148-
SELECT bt_index_check('test_amcheck.bttest_unique_idx1', true, true);
145+
SELECT bt_index_check('bttest_unique_idx1', true, true);
149146
));
150147
is($result, '', 'run amcheck on non-broken bttest_unique_idx1');
151148

152149
# Change the operator class to use a function which considers certain different
153150
# values to be equal.
154151
$node->safe_psql(
155152
'postgres', q(
156-
SET search_path = test_amcheck;
157153
UPDATE pg_catalog.pg_amproc SET
158154
amproc = 'bad_cmp1'::regproc
159155
WHERE amproc = 'ok_cmp1'::regproc;
160156
));
161157

162158
($result, $stdout, $stderr) = $node->psql(
163159
'postgres', q(
164-
SELECT bt_index_check('test_amcheck.bttest_unique_idx1', true, true);
160+
SELECT bt_index_check('bttest_unique_idx1', true, true);
165161
));
166162
ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx1"/,
167163
'detected uniqueness violation for index "bttest_unique_idx1"');
@@ -179,22 +175,21 @@
179175
# but no uniqueness violation.
180176
($result, $stdout, $stderr) = $node->psql(
181177
'postgres', q(
182-
SELECT bt_index_check('test_amcheck.bttest_unique_idx2', true, true);
178+
SELECT bt_index_check('bttest_unique_idx2', true, true);
183179
));
184180
ok( $stderr =~ /item order invariant violated for index "bttest_unique_idx2"/,
185181
'detected item order invariant violation for index "bttest_unique_idx2"');
186182

187183
$node->safe_psql(
188184
'postgres', q(
189-
SET search_path = test_amcheck;
190185
UPDATE pg_catalog.pg_amproc SET
191186
amproc = 'ok_cmp2'::regproc
192187
WHERE amproc = 'bad_cmp2'::regproc;
193188
));
194189

195190
($result, $stdout, $stderr) = $node->psql(
196191
'postgres', q(
197-
SELECT bt_index_check('test_amcheck.bttest_unique_idx2', true, true);
192+
SELECT bt_index_check('bttest_unique_idx2', true, true);
198193
));
199194
ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx2"/,
200195
'detected uniqueness violation for index "bttest_unique_idx2"');
@@ -211,7 +206,7 @@
211206
# but no uniqueness violation.
212207
($result, $stdout, $stderr) = $node->psql(
213208
'postgres', q(
214-
SELECT bt_index_check('test_amcheck.bttest_unique_idx3', true, true);
209+
SELECT bt_index_check('bttest_unique_idx3', true, true);
215210
));
216211
ok( $stderr =~ /item order invariant violated for index "bttest_unique_idx3"/,
217212
'detected item order invariant violation for index "bttest_unique_idx3"');
@@ -220,7 +215,6 @@
220215
# with different visibility.
221216
$node->safe_psql(
222217
'postgres', q(
223-
SET search_path = test_amcheck;
224218
DELETE FROM bttest_unique3 WHERE 380 <= i AND i <= 420;
225219
INSERT INTO bttest_unique3 (SELECT * FROM generate_series(380, 420));
226220
INSERT INTO bttest_unique3 VALUES (400);
@@ -234,15 +228,14 @@
234228

235229
$node->safe_psql(
236230
'postgres', q(
237-
SET search_path = test_amcheck;
238231
UPDATE pg_catalog.pg_amproc SET
239232
amproc = 'ok_cmp3'::regproc
240233
WHERE amproc = 'bad_cmp3'::regproc;
241234
));
242235

243236
($result, $stdout, $stderr) = $node->psql(
244237
'postgres', q(
245-
SELECT bt_index_check('test_amcheck.bttest_unique_idx3', true, true);
238+
SELECT bt_index_check('bttest_unique_idx3', true, true);
246239
));
247240
ok( $stderr =~ /index uniqueness is violated for index "bttest_unique_idx3"/,
248241
'detected uniqueness violation for index "bttest_unique_idx3"');

contrib/amcheck/verify_nbtree.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ bt_index_check_internal(Oid indrelid, bool parentcheck, bool heapallindexed,
313313
SetUserIdAndSecContext(heaprel->rd_rel->relowner,
314314
save_sec_context | SECURITY_RESTRICTED_OPERATION);
315315
save_nestlevel = NewGUCNestLevel();
316-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
317-
PGC_S_SESSION);
316+
RestrictSearchPath();
318317
}
319318
else
320319
{

src/backend/access/brin/brin.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,7 @@ brin_summarize_range(PG_FUNCTION_ARGS)
14121412
SetUserIdAndSecContext(heapRel->rd_rel->relowner,
14131413
save_sec_context | SECURITY_RESTRICTED_OPERATION);
14141414
save_nestlevel = NewGUCNestLevel();
1415-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
1416-
PGC_S_SESSION);
1415+
RestrictSearchPath();
14171416
}
14181417
else
14191418
{

src/backend/catalog/index.c

+4-9
Original file line numberDiff line numberDiff line change
@@ -1464,8 +1464,7 @@ index_concurrently_build(Oid heapRelationId,
14641464
SetUserIdAndSecContext(heapRel->rd_rel->relowner,
14651465
save_sec_context | SECURITY_RESTRICTED_OPERATION);
14661466
save_nestlevel = NewGUCNestLevel();
1467-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
1468-
PGC_S_SESSION);
1467+
RestrictSearchPath();
14691468

14701469
indexRelation = index_open(indexRelationId, RowExclusiveLock);
14711470

@@ -3018,9 +3017,7 @@ index_build(Relation heapRelation,
30183017
SetUserIdAndSecContext(heapRelation->rd_rel->relowner,
30193018
save_sec_context | SECURITY_RESTRICTED_OPERATION);
30203019
save_nestlevel = NewGUCNestLevel();
3021-
if (!IsBootstrapProcessingMode())
3022-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
3023-
PGC_S_SESSION);
3020+
RestrictSearchPath();
30243021

30253022
/* Set up initial progress report status */
30263023
{
@@ -3356,8 +3353,7 @@ validate_index(Oid heapId, Oid indexId, Snapshot snapshot)
33563353
SetUserIdAndSecContext(heapRelation->rd_rel->relowner,
33573354
save_sec_context | SECURITY_RESTRICTED_OPERATION);
33583355
save_nestlevel = NewGUCNestLevel();
3359-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
3360-
PGC_S_SESSION);
3356+
RestrictSearchPath();
33613357

33623358
indexRelation = index_open(indexId, RowExclusiveLock);
33633359

@@ -3619,8 +3615,7 @@ reindex_index(const ReindexStmt *stmt, Oid indexId,
36193615
SetUserIdAndSecContext(heapRelation->rd_rel->relowner,
36203616
save_sec_context | SECURITY_RESTRICTED_OPERATION);
36213617
save_nestlevel = NewGUCNestLevel();
3622-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
3623-
PGC_S_SESSION);
3618+
RestrictSearchPath();
36243619

36253620
if (progress)
36263621
{

src/backend/commands/analyze.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
339339
SetUserIdAndSecContext(onerel->rd_rel->relowner,
340340
save_sec_context | SECURITY_RESTRICTED_OPERATION);
341341
save_nestlevel = NewGUCNestLevel();
342-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
343-
PGC_S_SESSION);
342+
RestrictSearchPath();
344343

345344
/* measure elapsed time iff autovacuum logging requires it */
346345
if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)

src/backend/commands/cluster.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ cluster_rel(Oid tableOid, Oid indexOid, ClusterParams *params)
350350
SetUserIdAndSecContext(OldHeap->rd_rel->relowner,
351351
save_sec_context | SECURITY_RESTRICTED_OPERATION);
352352
save_nestlevel = NewGUCNestLevel();
353-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
354-
PGC_S_SESSION);
353+
RestrictSearchPath();
355354

356355
/*
357356
* Since we may open a new transaction for each relation, we have to check

src/backend/commands/indexcmds.c

+3-7
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,7 @@ DefineIndex(Oid tableId,
585585

586586
root_save_nestlevel = NewGUCNestLevel();
587587

588-
if (!IsBootstrapProcessingMode())
589-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
590-
PGC_S_SESSION);
588+
RestrictSearchPath();
591589

592590
/*
593591
* Some callers need us to run with an empty default_tablespace; this is a
@@ -1344,8 +1342,7 @@ DefineIndex(Oid tableId,
13441342
SetUserIdAndSecContext(childrel->rd_rel->relowner,
13451343
child_save_sec_context | SECURITY_RESTRICTED_OPERATION);
13461344
child_save_nestlevel = NewGUCNestLevel();
1347-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
1348-
PGC_S_SESSION);
1345+
RestrictSearchPath();
13491346

13501347
/*
13511348
* Don't try to create indexes on foreign tables, though. Skip
@@ -3887,8 +3884,7 @@ ReindexRelationConcurrently(const ReindexStmt *stmt, Oid relationOid, const Rein
38873884
SetUserIdAndSecContext(heapRel->rd_rel->relowner,
38883885
save_sec_context | SECURITY_RESTRICTED_OPERATION);
38893886
save_nestlevel = NewGUCNestLevel();
3890-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
3891-
PGC_S_SESSION);
3887+
RestrictSearchPath();
38923888

38933889
/* determine safety of this index for set_indexsafe_procflags */
38943890
idx->safe = (indexRel->rd_indexprs == NIL &&

src/backend/commands/matview.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
173173
SetUserIdAndSecContext(relowner,
174174
save_sec_context | SECURITY_RESTRICTED_OPERATION);
175175
save_nestlevel = NewGUCNestLevel();
176-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
177-
PGC_S_SESSION);
176+
RestrictSearchPath();
178177

179178
/* Make sure it is a materialized view. */
180179
if (matviewRel->rd_rel->relkind != RELKIND_MATVIEW)

src/backend/commands/vacuum.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -2166,8 +2166,7 @@ vacuum_rel(Oid relid, RangeVar *relation, VacuumParams *params,
21662166
SetUserIdAndSecContext(rel->rd_rel->relowner,
21672167
save_sec_context | SECURITY_RESTRICTED_OPERATION);
21682168
save_nestlevel = NewGUCNestLevel();
2169-
SetConfigOption("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
2170-
PGC_S_SESSION);
2169+
RestrictSearchPath();
21712170

21722171
/*
21732172
* If PROCESS_MAIN is set (the default), it's time to vacuum the main

src/backend/utils/misc/guc.c

+19
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767
*/
6868
#define REALTYPE_PRECISION 17
6969

70+
/*
71+
* Safe search path when executing code as the table owner, such as during
72+
* maintenance operations.
73+
*/
74+
#define GUC_SAFE_SEARCH_PATH "pg_catalog, pg_temp"
75+
7076
static int GUC_check_errcode_value;
7177

7278
static List *reserved_class_prefix = NIL;
@@ -2234,6 +2240,19 @@ NewGUCNestLevel(void)
22342240
return ++GUCNestLevel;
22352241
}
22362242

2243+
/*
2244+
* Set search_path to a fixed value for maintenance operations. No effect
2245+
* during bootstrap, when the search_path is already set to a fixed value and
2246+
* cannot be changed.
2247+
*/
2248+
void
2249+
RestrictSearchPath(void)
2250+
{
2251+
if (!IsBootstrapProcessingMode())
2252+
set_config_option("search_path", GUC_SAFE_SEARCH_PATH, PGC_USERSET,
2253+
PGC_S_SESSION, GUC_ACTION_SAVE, true, 0, false);
2254+
}
2255+
22372256
/*
22382257
* Do GUC processing at transaction or subtransaction commit or abort, or
22392258
* when exiting a function that has proconfig settings, or when undoing a

src/include/utils/guc.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ typedef enum
203203

204204
#define GUC_QUALIFIER_SEPARATOR '.'
205205

206-
/*
207-
* Safe search path when executing code as the table owner, such as during
208-
* maintenance operations.
209-
*/
210-
#define GUC_SAFE_SEARCH_PATH "pg_catalog, pg_temp"
211-
212206
/*
213207
* Bit values in "flags" of a GUC variable. Note that these don't appear
214208
* on disk, so we can reassign their values freely.
@@ -378,6 +372,7 @@ extern bool SelectConfigFiles(const char *userDoption, const char *progname);
378372
extern void ResetAllOptions(void);
379373
extern void AtStart_GUC(void);
380374
extern int NewGUCNestLevel(void);
375+
extern void RestrictSearchPath(void);
381376
extern void AtEOXact_GUC(bool isCommit, int nestLevel);
382377
extern void BeginReportingGUCOptions(void);
383378
extern void ReportChangedGUCOptions(void);

0 commit comments

Comments
 (0)