Skip to content

Commit 24bd944

Browse files
committed
Clean up recent patch for PL handler functions in pg_catalog: the patch
caused PL languages and handlers to be dumped ALWAYS, even in the face of contrary --schema or --table switches. Adopt a slightly saner definition.
1 parent 9a93280 commit 24bd944

File tree

2 files changed

+59
-23
lines changed

2 files changed

+59
-23
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* by PostgreSQL
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.417 2005/08/15 02:36:29 tgl Exp $
15+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.418 2005/08/15 21:50:15 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -2305,9 +2305,9 @@ getFuncs(int *numFuncs)
23052305
if (g_fout->remoteVersion >= 70300)
23062306
{
23072307
/*
2308-
* We now collect info on pg_catalog resident functions, but
2309-
* only if they are language call handlers or validators, and
2310-
* only for non-default languages (i.e. not internal/C/SQL).
2308+
* For 7.3 and up, we consider it's user-defined if it's not in
2309+
* pg_catalog. We also collect info on functions in pg_catalog, but
2310+
* only if they are call handlers or validators for PL languages.
23112311
*/
23122312
appendPQExpBuffer(query,
23132313
"SELECT tableoid, oid, proname, prolang, "
@@ -2316,10 +2316,10 @@ getFuncs(int *numFuncs)
23162316
"(%s proowner) as rolname, "
23172317
"CASE WHEN oid IN "
23182318
" (select lanplcallfoid from pg_language "
2319-
" where lanplcallfoid != 0) THEN true "
2319+
" where lanispl) THEN true "
23202320
" WHEN oid IN "
23212321
" (select lanvalidator from pg_language "
2322-
" where lanplcallfoid != 0) THEN true "
2322+
" where lanispl) THEN true "
23232323
" ELSE false END AS is_pl_handler "
23242324
"FROM pg_proc "
23252325
"WHERE NOT proisagg "
@@ -2328,10 +2328,10 @@ getFuncs(int *numFuncs)
23282328
" where nspname = 'pg_catalog')"
23292329
" OR oid IN "
23302330
" (select lanplcallfoid from pg_language "
2331-
" where lanplcallfoid != 0) "
2331+
" where lanispl) "
23322332
" OR oid IN "
23332333
" (select lanvalidator from pg_language "
2334-
" where lanplcallfoid != 0))",
2334+
" where lanispl))",
23352335
username_subquery);
23362336
}
23372337
else if (g_fout->remoteVersion >= 70100)
@@ -2402,7 +2402,7 @@ getFuncs(int *numFuncs)
24022402
finfo[i].prorettype = atooid(PQgetvalue(res, i, i_prorettype));
24032403
finfo[i].proacl = strdup(PQgetvalue(res, i, i_proacl));
24042404
finfo[i].nargs = atoi(PQgetvalue(res, i, i_pronargs));
2405-
finfo[i].isProlangFunc =
2405+
finfo[i].islanghandler =
24062406
strcmp(PQgetvalue(res, i, i_is_pl_handler), "t") == 0;
24072407
if (finfo[i].nargs == 0)
24082408
finfo[i].argtypes = NULL;
@@ -5095,6 +5095,29 @@ dumpCompositeType(Archive *fout, TypeInfo *tinfo)
50955095
destroyPQExpBuffer(query);
50965096
}
50975097

5098+
/*
5099+
* Determine whether we want to dump definitions for procedural languages.
5100+
* Since the languages themselves don't have schemas, we can't rely on
5101+
* the normal schema-based selection mechanism. We choose to dump them
5102+
* whenever neither --schema nor --table was given. (Before 8.1, we used
5103+
* the dump flag of the PL's call handler function, but in 8.1 this will
5104+
* probably always be false since call handlers are created in pg_catalog.)
5105+
*
5106+
* For some backwards compatibility with the older behavior, we forcibly
5107+
* dump a PL if its handler function (and validator if any) are in a
5108+
* dumpable namespace. That case is not checked here.
5109+
*/
5110+
static bool
5111+
shouldDumpProcLangs(void)
5112+
{
5113+
if (selectTableName != NULL || selectSchemaName != NULL)
5114+
return false;
5115+
/* And they're schema not data */
5116+
if (dataOnly)
5117+
return false;
5118+
return true;
5119+
}
5120+
50985121
/*
50995122
* dumpProcLang
51005123
* writes out to fout the queries to recreate a user-defined
@@ -5113,28 +5136,33 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51135136
return;
51145137

51155138
/*
5116-
* We dump PLs iff their underlying call handler functions have been
5117-
* marked as language functions (or have a non-system OID in
5118-
* pre-7.3 databases). We treat the PL itself as being in
5119-
* the underlying function's namespace, though it isn't really. This
5120-
* avoids searchpath problems for the HANDLER clause.
5121-
*
5139+
* Find the support functions, complaining if not there.
51225140
*/
5123-
51245141
funcInfo = findFuncByOid(plang->lanplcallfoid);
51255142
if (funcInfo == NULL)
5143+
{
5144+
write_msg(NULL, "WARNING: handler function for language \"%s\" not found\n",
5145+
plang->dobj.name);
51265146
return;
5127-
5128-
if (!funcInfo->isProlangFunc && !funcInfo->dobj.namespace->dump)
5129-
return;
5147+
}
51305148

51315149
if (OidIsValid(plang->lanvalidator))
51325150
{
51335151
validatorInfo = findFuncByOid(plang->lanvalidator);
51345152
if (validatorInfo == NULL)
5153+
{
5154+
write_msg(NULL, "WARNING: validator function for language \"%s\" not found\n",
5155+
plang->dobj.name);
51355156
return;
5157+
}
51365158
}
51375159

5160+
/* Dump if we should, or if both support functions are dumpable */
5161+
if (!shouldDumpProcLangs() &&
5162+
!(funcInfo->dobj.namespace->dump &&
5163+
(validatorInfo == NULL || validatorInfo->dobj.namespace->dump)))
5164+
return;
5165+
51385166
defqry = createPQExpBuffer();
51395167
delqry = createPQExpBuffer();
51405168

@@ -5160,6 +5188,11 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
51605188
}
51615189
appendPQExpBuffer(defqry, ";\n");
51625190

5191+
/*
5192+
* We mark the PL's archive entry as being in the call handler's
5193+
* namespace; this is what makes it OK to refer to the handler with
5194+
* an unqualified name above.
5195+
*/
51635196
ArchiveEntry(fout, plang->dobj.catId, plang->dobj.dumpId,
51645197
plang->dobj.name,
51655198
funcInfo->dobj.namespace->dobj.name, NULL, "",
@@ -5323,10 +5356,13 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
53235356
char **argmodes = NULL;
53245357
char **argnames = NULL;
53255358

5326-
/* Dump only funcs in dumpable namespaces, or needed language handlers */
5327-
if ((!finfo->isProlangFunc && !finfo->dobj.namespace->dump) || dataOnly)
5359+
if (dataOnly)
53285360
return;
53295361

5362+
/* Dump only funcs in dumpable namespaces, or needed language handlers */
5363+
if (!finfo->dobj.namespace->dump &&
5364+
(!finfo->islanghandler || !shouldDumpProcLangs()))
5365+
return;
53305366

53315367
query = createPQExpBuffer();
53325368
q = createPQExpBuffer();

src/bin/pg_dump/pg_dump.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.118 2005/08/15 02:36:30 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.h,v 1.119 2005/08/15 21:50:15 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -132,7 +132,7 @@ typedef struct _funcInfo
132132
Oid *argtypes;
133133
Oid prorettype;
134134
char *proacl;
135-
bool isProlangFunc;
135+
bool islanghandler;
136136
} FuncInfo;
137137

138138
/* AggInfo is a superset of FuncInfo */

0 commit comments

Comments
 (0)