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

Commit15c194c

Browse files
committed
Add GUC parameter check_function_bodies to control whether validation
of function bodies is done at CREATE FUNCTION time. This is normallytrue but can be set false to avoid problems with forward references,wrong schema search path, etc. This is just the backend patch, stillneed to adjust pg_dump to make use of it.
1 parent2510331 commit15c194c

File tree

4 files changed

+65
-26
lines changed

4 files changed

+65
-26
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.209 2003/09/20 20:12:05 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.210 2003/10/03 19:26:49 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -2085,6 +2085,17 @@ SET ENABLE_SEQSCAN TO OFF;
20852085
</listitem>
20862086
</varlistentry>
20872087

2088+
<varlistentry>
2089+
<term><varname>check_function_bodies</varname> (<type>boolean</type>)</term>
2090+
<listitem>
2091+
<para>
2092+
This parameter is normally true. When set false, it disables
2093+
validation of the function body string in <command>CREATE FUNCTION</>.
2094+
Disabling validation is occasionally useful to avoid problems such as
2095+
forward references when restoring function definitions from a dump.
2096+
</para>
2097+
</listitem>
2098+
</varlistentry>
20882099

20892100
<varlistentry>
20902101
<indexterm>

‎src/backend/catalog/pg_proc.c

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.108 2003/09/29 00:05:24 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.109 2003/10/03 19:26:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -34,6 +34,10 @@
3434
#include"utils/syscache.h"
3535

3636

37+
/* GUC parameter */
38+
boolcheck_function_bodies= true;
39+
40+
3741
Datumfmgr_internal_validator(PG_FUNCTION_ARGS);
3842
Datumfmgr_c_validator(PG_FUNCTION_ARGS);
3943
Datumfmgr_sql_validator(PG_FUNCTION_ARGS);
@@ -560,6 +564,11 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
560564
Datumtmp;
561565
char*prosrc;
562566

567+
/*
568+
* We do not honor check_function_bodies since it's unlikely the
569+
* function name will be found later if it isn't there now.
570+
*/
571+
563572
tuple=SearchSysCache(PROCOID,
564573
ObjectIdGetDatum(funcoid),
565574
0,0,0);
@@ -604,6 +613,12 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
604613
char*prosrc;
605614
char*probin;
606615

616+
/*
617+
* It'd be most consistent to skip the check if !check_function_bodies,
618+
* but the purpose of that switch is to be helpful for pg_dump loading,
619+
* and for pg_dump loading it's much better if we *do* check.
620+
*/
621+
607622
tuple=SearchSysCache(PROCOID,
608623
ObjectIdGetDatum(funcoid),
609624
0,0,0);
@@ -633,8 +648,7 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
633648
/*
634649
* Validator for SQL language functions
635650
*
636-
* Parse it here in order to be sure that it contains no syntax
637-
* errors.
651+
* Parse it here in order to be sure that it contains no syntax errors.
638652
*/
639653
Datum
640654
fmgr_sql_validator(PG_FUNCTION_ARGS)
@@ -689,30 +703,34 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
689703
}
690704
}
691705

692-
tmp=SysCacheGetAttr(PROCOID,tuple,Anum_pg_proc_prosrc,&isnull);
693-
if (isnull)
694-
elog(ERROR,"null prosrc");
706+
/* Postpone body checks if !check_function_bodies */
707+
if (check_function_bodies)
708+
{
709+
tmp=SysCacheGetAttr(PROCOID,tuple,Anum_pg_proc_prosrc,&isnull);
710+
if (isnull)
711+
elog(ERROR,"null prosrc");
695712

696-
prosrc=DatumGetCString(DirectFunctionCall1(textout,tmp));
713+
prosrc=DatumGetCString(DirectFunctionCall1(textout,tmp));
697714

698-
/*
699-
* We can't do full prechecking of the function definition if there
700-
* are any polymorphic input types, because actual datatypes of
701-
* expression results will be unresolvable. The check will be done at
702-
* runtime instead.
703-
*
704-
* We can run the text through the raw parser though; this will at least
705-
* catch silly syntactic errors.
706-
*/
707-
if (!haspolyarg)
708-
{
709-
querytree_list=pg_parse_and_rewrite(prosrc,
710-
proc->proargtypes,
711-
proc->pronargs);
712-
check_sql_fn_retval(proc->prorettype,functyptype,querytree_list);
715+
/*
716+
* We can't do full prechecking of the function definition if there
717+
* are any polymorphic input types, because actual datatypes of
718+
* expression results will be unresolvable. The check will be done
719+
* at runtime instead.
720+
*
721+
* We can run the text through the raw parser though; this will at
722+
* least catch silly syntactic errors.
723+
*/
724+
if (!haspolyarg)
725+
{
726+
querytree_list=pg_parse_and_rewrite(prosrc,
727+
proc->proargtypes,
728+
proc->pronargs);
729+
check_sql_fn_retval(proc->prorettype,functyptype,querytree_list);
730+
}
731+
else
732+
querytree_list=pg_parse_query(prosrc);
713733
}
714-
else
715-
querytree_list=pg_parse_query(prosrc);
716734

717735
ReleaseSysCache(tuple);
718736

‎src/backend/utils/misc/guc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.161 2003/09/29 00:05:25 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.162 2003/10/03 19:26:49 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -66,6 +66,7 @@
6666

6767
/* XXX these should appear in other modules' header files */
6868
externboolLog_connections;
69+
externboolcheck_function_bodies;
6970
externintPreAuthDelay;
7071
externintAuthenticationTimeout;
7172
externintCheckPointTimeout;
@@ -821,6 +822,14 @@ static struct config_bool ConfigureNamesBool[] =
821822
&add_missing_from,
822823
true,NULL,NULL
823824
},
825+
{
826+
{"check_function_bodies",PGC_USERSET,CLIENT_CONN_STATEMENT,
827+
gettext_noop("check function bodies during CREATE FUNCTION"),
828+
NULL
829+
},
830+
&check_function_bodies,
831+
true,NULL,NULL
832+
},
824833

825834
/* End-of-list marker */
826835
{

‎src/backend/utils/misc/postgresql.conf.sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@
205205
# - Statement Behavior -
206206

207207
#search_path = '$user,public'# schema names
208+
#check_function_bodies = true
208209
#default_transaction_isolation = 'read committed'
209210
#default_transaction_read_only = false
210211
#statement_timeout = 0# 0 is disabled, in milliseconds

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp