Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfde440e

Browse files
committed
Don't fail for bad GUCs in CREATE FUNCTION with check_function_bodies off.
The previous coding attempted to activate all the GUC settings specifiedin SET clauses, so that the function validator could operate in the GUCenvironment expected by the function body. However, this is problematicwhen restoring a dump, since the SET clauses might refer to databaseobjects that don't exist yet. We already have the parametercheck_function_bodies that's meant to prevent forward references infunction definitions from breaking dumps, so let's change CREATE FUNCTIONto not install the SET values if check_function_bodies is off.Authors of function validators were already advised not to make any"context sensitive" checks when check_function_bodies is off, if indeedthey're checking anything at all in that mode. But extend thedocumentation to point out the GUC issue in particular.(Note that we still check the SET clauses to some extent; the behaviorwith !check_function_bodies is now approximately equivalent to what ALTERDATABASE/ROLE have been doing for awhile with context-dependent GUCs.)This problem can be demonstrated in all active branches, so back-patchall the way.
1 parentcec83f6 commitfde440e

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

‎doc/src/sgml/plhandler.sgml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ CREATE LANGUAGE plsample
201201
of having a validator is not to let the call handler omit checks, but
202202
to notify the user immediately if there are obvious errors in a
203203
<command>CREATE FUNCTION</> command.)
204+
While the choice of exactly what to check is mostly left to the
205+
discretion of the validator function, note that the core
206+
<command>CREATE FUNCTION</> code only executes <literal>SET</> clauses
207+
attached to a function when <varname>check_function_bodies</> is on.
208+
Therefore, checks whose results might be affected by GUC parameters
209+
definitely should be skipped when <varname>check_function_bodies</> is
210+
off, to avoid false failures when reloading a dump.
204211
</para>
205212

206213
<para>

‎src/backend/catalog/pg_proc.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -626,24 +626,34 @@ ProcedureCreate(const char *procedureName,
626626
/* Verify function body */
627627
if (OidIsValid(languageValidator))
628628
{
629-
ArrayType*set_items;
630-
intsave_nestlevel;
629+
ArrayType*set_items=NULL;
630+
intsave_nestlevel=0;
631631

632632
/* Advance command counter so new tuple can be seen by validator */
633633
CommandCounterIncrement();
634634

635-
/* Set per-function configuration parameters */
636-
set_items= (ArrayType*)DatumGetPointer(proconfig);
637-
if (set_items)/* Need a new GUC nesting level */
635+
/*
636+
* Set per-function configuration parameters so that the validation is
637+
* done with the environment the function expects.However, if
638+
* check_function_bodies is off, we don't do this, because that would
639+
* create dump ordering hazards that pg_dump doesn't know how to deal
640+
* with. (For example, a SET clause might refer to a not-yet-created
641+
* text search configuration.)This means that the validator
642+
* shouldn't complain about anything that might depend on a GUC
643+
* parameter when check_function_bodies is off.
644+
*/
645+
if (check_function_bodies)
638646
{
639-
save_nestlevel=NewGUCNestLevel();
640-
ProcessGUCArray(set_items,
641-
(superuser() ?PGC_SUSET :PGC_USERSET),
642-
PGC_S_SESSION,
643-
GUC_ACTION_SAVE);
647+
set_items= (ArrayType*)DatumGetPointer(proconfig);
648+
if (set_items)/* Need a new GUC nesting level */
649+
{
650+
save_nestlevel=NewGUCNestLevel();
651+
ProcessGUCArray(set_items,
652+
(superuser() ?PGC_SUSET :PGC_USERSET),
653+
PGC_S_SESSION,
654+
GUC_ACTION_SAVE);
655+
}
644656
}
645-
else
646-
save_nestlevel=0;/* keep compiler quiet */
647657

648658
OidFunctionCall1(languageValidator,ObjectIdGetDatum(retval));
649659

‎src/test/regress/expected/guc.out

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,3 +699,19 @@ select myfunc(1), current_setting('work_mem');
699699
2MB | 2MB
700700
(1 row)
701701

702+
-- Normally, CREATE FUNCTION should complain about invalid values in
703+
-- function SET options; but not if check_function_bodies is off,
704+
-- because that creates ordering hazards for pg_dump
705+
create function func_with_bad_set() returns int as $$ select 1 $$
706+
language sql
707+
set default_text_search_config = no_such_config;
708+
NOTICE: text search configuration "no_such_config" does not exist
709+
ERROR: invalid value for parameter "default_text_search_config": "no_such_config"
710+
set check_function_bodies = off;
711+
create function func_with_bad_set() returns int as $$ select 1 $$
712+
language sql
713+
set default_text_search_config = no_such_config;
714+
NOTICE: text search configuration "no_such_config" does not exist
715+
select func_with_bad_set();
716+
ERROR: invalid value for parameter "default_text_search_config": "no_such_config"
717+
reset check_function_bodies;

‎src/test/regress/sql/guc.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,21 @@ set work_mem = '1MB';
251251
select myfunc(0);
252252
select current_setting('work_mem');
253253
select myfunc(1), current_setting('work_mem');
254+
255+
-- Normally, CREATE FUNCTION should complain about invalid values in
256+
-- function SET options; but not if check_function_bodies is off,
257+
-- because that creates ordering hazards for pg_dump
258+
259+
createfunctionfunc_with_bad_set() returnsintas $$select1 $$
260+
language sql
261+
set default_text_search_config= no_such_config;
262+
263+
set check_function_bodies= off;
264+
265+
createfunctionfunc_with_bad_set() returnsintas $$select1 $$
266+
language sql
267+
set default_text_search_config= no_such_config;
268+
269+
select func_with_bad_set();
270+
271+
reset check_function_bodies;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp