Commit 15c194c1 authored by Tom Lane's avatar Tom Lane

Add GUC parameter check_function_bodies to control whether validation

of function bodies is done at CREATE FUNCTION time.  This is normally
true but can be set false to avoid problems with forward references,
wrong schema search path, etc.  This is just the backend patch, still
need to adjust pg_dump to make use of it.
parent 25103318
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.209 2003/09/20 20:12:05 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.210 2003/10/03 19:26:49 tgl Exp $
--> -->
<Chapter Id="runtime"> <Chapter Id="runtime">
...@@ -2085,6 +2085,17 @@ SET ENABLE_SEQSCAN TO OFF; ...@@ -2085,6 +2085,17 @@ SET ENABLE_SEQSCAN TO OFF;
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>check_function_bodies</varname> (<type>boolean</type>)</term>
<listitem>
<para>
This parameter is normally true. When set false, it disables
validation of the function body string in <command>CREATE FUNCTION</>.
Disabling validation is occasionally useful to avoid problems such as
forward references when restoring function definitions from a dump.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<indexterm> <indexterm>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.108 2003/09/29 00:05:24 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.109 2003/10/03 19:26:49 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,6 +34,10 @@ ...@@ -34,6 +34,10 @@
#include "utils/syscache.h" #include "utils/syscache.h"
/* GUC parameter */
bool check_function_bodies = true;
Datum fmgr_internal_validator(PG_FUNCTION_ARGS); Datum fmgr_internal_validator(PG_FUNCTION_ARGS);
Datum fmgr_c_validator(PG_FUNCTION_ARGS); Datum fmgr_c_validator(PG_FUNCTION_ARGS);
Datum fmgr_sql_validator(PG_FUNCTION_ARGS); Datum fmgr_sql_validator(PG_FUNCTION_ARGS);
...@@ -560,6 +564,11 @@ fmgr_internal_validator(PG_FUNCTION_ARGS) ...@@ -560,6 +564,11 @@ fmgr_internal_validator(PG_FUNCTION_ARGS)
Datum tmp; Datum tmp;
char *prosrc; char *prosrc;
/*
* We do not honor check_function_bodies since it's unlikely the
* function name will be found later if it isn't there now.
*/
tuple = SearchSysCache(PROCOID, tuple = SearchSysCache(PROCOID,
ObjectIdGetDatum(funcoid), ObjectIdGetDatum(funcoid),
0, 0, 0); 0, 0, 0);
...@@ -604,6 +613,12 @@ fmgr_c_validator(PG_FUNCTION_ARGS) ...@@ -604,6 +613,12 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
char *prosrc; char *prosrc;
char *probin; char *probin;
/*
* It'd be most consistent to skip the check if !check_function_bodies,
* but the purpose of that switch is to be helpful for pg_dump loading,
* and for pg_dump loading it's much better if we *do* check.
*/
tuple = SearchSysCache(PROCOID, tuple = SearchSysCache(PROCOID,
ObjectIdGetDatum(funcoid), ObjectIdGetDatum(funcoid),
0, 0, 0); 0, 0, 0);
...@@ -633,8 +648,7 @@ fmgr_c_validator(PG_FUNCTION_ARGS) ...@@ -633,8 +648,7 @@ fmgr_c_validator(PG_FUNCTION_ARGS)
/* /*
* Validator for SQL language functions * Validator for SQL language functions
* *
* Parse it here in order to be sure that it contains no syntax * Parse it here in order to be sure that it contains no syntax errors.
* errors.
*/ */
Datum Datum
fmgr_sql_validator(PG_FUNCTION_ARGS) fmgr_sql_validator(PG_FUNCTION_ARGS)
...@@ -689,6 +703,9 @@ fmgr_sql_validator(PG_FUNCTION_ARGS) ...@@ -689,6 +703,9 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
} }
} }
/* Postpone body checks if !check_function_bodies */
if (check_function_bodies)
{
tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull); tmp = SysCacheGetAttr(PROCOID, tuple, Anum_pg_proc_prosrc, &isnull);
if (isnull) if (isnull)
elog(ERROR, "null prosrc"); elog(ERROR, "null prosrc");
...@@ -698,11 +715,11 @@ fmgr_sql_validator(PG_FUNCTION_ARGS) ...@@ -698,11 +715,11 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
/* /*
* We can't do full prechecking of the function definition if there * We can't do full prechecking of the function definition if there
* are any polymorphic input types, because actual datatypes of * are any polymorphic input types, because actual datatypes of
* expression results will be unresolvable. The check will be done at * expression results will be unresolvable. The check will be done
* runtime instead. * at runtime instead.
* *
* We can run the text through the raw parser though; this will at least * We can run the text through the raw parser though; this will at
* catch silly syntactic errors. * least catch silly syntactic errors.
*/ */
if (!haspolyarg) if (!haspolyarg)
{ {
...@@ -713,6 +730,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS) ...@@ -713,6 +730,7 @@ fmgr_sql_validator(PG_FUNCTION_ARGS)
} }
else else
querytree_list = pg_parse_query(prosrc); querytree_list = pg_parse_query(prosrc);
}
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>. * Written by Peter Eisentraut <peter_e@gmx.net>.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.161 2003/09/29 00:05:25 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.162 2003/10/03 19:26:49 tgl Exp $
* *
*-------------------------------------------------------------------- *--------------------------------------------------------------------
*/ */
...@@ -66,6 +66,7 @@ ...@@ -66,6 +66,7 @@
/* XXX these should appear in other modules' header files */ /* XXX these should appear in other modules' header files */
extern bool Log_connections; extern bool Log_connections;
extern bool check_function_bodies;
extern int PreAuthDelay; extern int PreAuthDelay;
extern int AuthenticationTimeout; extern int AuthenticationTimeout;
extern int CheckPointTimeout; extern int CheckPointTimeout;
...@@ -821,6 +822,14 @@ static struct config_bool ConfigureNamesBool[] = ...@@ -821,6 +822,14 @@ static struct config_bool ConfigureNamesBool[] =
&add_missing_from, &add_missing_from,
true, NULL, NULL true, NULL, NULL
}, },
{
{"check_function_bodies", PGC_USERSET, CLIENT_CONN_STATEMENT,
gettext_noop("check function bodies during CREATE FUNCTION"),
NULL
},
&check_function_bodies,
true, NULL, NULL
},
/* End-of-list marker */ /* End-of-list marker */
{ {
......
...@@ -205,6 +205,7 @@ ...@@ -205,6 +205,7 @@
# - Statement Behavior - # - Statement Behavior -
#search_path = '$user,public' # schema names #search_path = '$user,public' # schema names
#check_function_bodies = true
#default_transaction_isolation = 'read committed' #default_transaction_isolation = 'read committed'
#default_transaction_read_only = false #default_transaction_read_only = false
#statement_timeout = 0 # 0 is disabled, in milliseconds #statement_timeout = 0 # 0 is disabled, in milliseconds
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment