Commit 299990ba authored by Tom Lane's avatar Tom Lane

Repair incorrect pg_dump labeling for some comments and security labels.

We attached no schema label to comments for procedural languages, casts,
transforms, operator classes, operator families, or text search objects.
The first three categories of objects don't really have schemas, but
pg_dump treats them as if they do, and it seems like the TocEntry fields
for their comments had better match the TocEntry fields for the parent
objects.  (As an example of a possible hazard, the type names in a CAST
will be formatted with the assumption of a particular search_path, so
failing to ensure that this same path is active for the COMMENT ON command
could lead to an error or to attaching the comment to the wrong cast.)
In the last six cases, this was a flat-out error --- possibly mine to
begin with, but it was a long time ago.

The security label for a procedural language was likewise not correctly
labeled as to schema, and both the comment and security label for a
procedural language were not correctly labeled as to owner.

In simple cases the restore would accidentally work correctly anyway, since
these comments and security labels would normally get emitted right after
the owning object, and so the search path and active user would be correct
anyhow.  But it could fail in corner cases; for example a schema-selective
restore would omit comments it should include.

Giuseppe Broccolo noted the oversight, and proposed the correct fix, for
text search dictionary objects; I found the rest by cross-checking other
dumpComment() calls.  These oversights are ancient, so back-patch all
the way.

Discussion: https://postgr.es/m/CAFzmHiWwwzLjzwM4x5ki5s_PDMR6NrkipZkjNnO3B0xEpBgJaA@mail.gmail.com
parent d4c62a6b
...@@ -10830,12 +10830,12 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -10830,12 +10830,12 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
/* Dump Proc Lang Comments and Security Labels */ /* Dump Proc Lang Comments and Security Labels */
if (plang->dobj.dump & DUMP_COMPONENT_COMMENT) if (plang->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, "", lanschema, plang->lanowner,
plang->dobj.catId, 0, plang->dobj.dumpId); plang->dobj.catId, 0, plang->dobj.dumpId);
if (plang->dobj.dump & DUMP_COMPONENT_SECLABEL) if (plang->dobj.dump & DUMP_COMPONENT_SECLABEL)
dumpSecLabel(fout, labelq->data, dumpSecLabel(fout, labelq->data,
NULL, "", lanschema, plang->lanowner,
plang->dobj.catId, 0, plang->dobj.dumpId); plang->dobj.catId, 0, plang->dobj.dumpId);
if (plang->lanpltrusted && plang->dobj.dump & DUMP_COMPONENT_ACL) if (plang->lanpltrusted && plang->dobj.dump & DUMP_COMPONENT_ACL)
...@@ -11585,7 +11585,7 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -11585,7 +11585,7 @@ dumpCast(Archive *fout, CastInfo *cast)
/* Dump Cast Comments */ /* Dump Cast Comments */
if (cast->dobj.dump & DUMP_COMPONENT_COMMENT) if (cast->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, "", "pg_catalog", "",
cast->dobj.catId, 0, cast->dobj.dumpId); cast->dobj.catId, 0, cast->dobj.dumpId);
free(sourceType); free(sourceType);
...@@ -11709,7 +11709,7 @@ dumpTransform(Archive *fout, TransformInfo *transform) ...@@ -11709,7 +11709,7 @@ dumpTransform(Archive *fout, TransformInfo *transform)
/* Dump Transform Comments */ /* Dump Transform Comments */
if (transform->dobj.dump & DUMP_COMPONENT_COMMENT) if (transform->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, "", "pg_catalog", "",
transform->dobj.catId, 0, transform->dobj.dumpId); transform->dobj.catId, 0, transform->dobj.dumpId);
free(lanname); free(lanname);
...@@ -12483,7 +12483,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -12483,7 +12483,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
/* Dump Operator Class Comments */ /* Dump Operator Class Comments */
if (opcinfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (opcinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, opcinfo->rolname, opcinfo->dobj.namespace->dobj.name, opcinfo->rolname,
opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId); opcinfo->dobj.catId, 0, opcinfo->dobj.dumpId);
free(amname); free(amname);
...@@ -12756,7 +12756,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -12756,7 +12756,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
/* Dump Operator Family Comments */ /* Dump Operator Family Comments */
if (opfinfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (opfinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, opfinfo->rolname, opfinfo->dobj.namespace->dobj.name, opfinfo->rolname,
opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId); opfinfo->dobj.catId, 0, opfinfo->dobj.dumpId);
free(amname); free(amname);
...@@ -13474,7 +13474,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo) ...@@ -13474,7 +13474,7 @@ dumpTSParser(Archive *fout, TSParserInfo *prsinfo)
/* Dump Parser Comments */ /* Dump Parser Comments */
if (prsinfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (prsinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, "", prsinfo->dobj.namespace->dobj.name, "",
prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId); prsinfo->dobj.catId, 0, prsinfo->dobj.dumpId);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
...@@ -13564,7 +13564,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -13564,7 +13564,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
/* Dump Dictionary Comments */ /* Dump Dictionary Comments */
if (dictinfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (dictinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, dictinfo->rolname, dictinfo->dobj.namespace->dobj.name, dictinfo->rolname,
dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId); dictinfo->dobj.catId, 0, dictinfo->dobj.dumpId);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
...@@ -13633,7 +13633,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo) ...@@ -13633,7 +13633,7 @@ dumpTSTemplate(Archive *fout, TSTemplateInfo *tmplinfo)
/* Dump Template Comments */ /* Dump Template Comments */
if (tmplinfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (tmplinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, "", tmplinfo->dobj.namespace->dobj.name, "",
tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId); tmplinfo->dobj.catId, 0, tmplinfo->dobj.dumpId);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
...@@ -13764,7 +13764,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -13764,7 +13764,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
/* Dump Configuration Comments */ /* Dump Configuration Comments */
if (cfginfo->dobj.dump & DUMP_COMPONENT_COMMENT) if (cfginfo->dobj.dump & DUMP_COMPONENT_COMMENT)
dumpComment(fout, labelq->data, dumpComment(fout, labelq->data,
NULL, cfginfo->rolname, cfginfo->dobj.namespace->dobj.name, cfginfo->rolname,
cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId); cfginfo->dobj.catId, 0, cfginfo->dobj.dumpId);
destroyPQExpBuffer(q); destroyPQExpBuffer(q);
......
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