@@ -184,14 +184,12 @@ static inline void dumpComment(Archive *fout, const char *type,
184184 const char *name, const char *namespace,
185185 const char *owner, CatalogId catalogId,
186186 int subid, DumpId dumpId);
187- static int findComments(Archive *fout, Oid classoid, Oid objoid,
188- CommentItem **items);
187+ static int findComments(Oid classoid, Oid objoid, CommentItem **items);
189188static void collectComments(Archive *fout);
190189static void dumpSecLabel(Archive *fout, const char *type, const char *name,
191190 const char *namespace, const char *owner,
192191 CatalogId catalogId, int subid, DumpId dumpId);
193- static int findSecLabels(Archive *fout, Oid classoid, Oid objoid,
194- SecLabelItem **items);
192+ static int findSecLabels(Oid classoid, Oid objoid, SecLabelItem **items);
195193static void collectSecLabels(Archive *fout);
196194static void dumpDumpableObject(Archive *fout, DumpableObject *dobj);
197195static void dumpNamespace(Archive *fout, const NamespaceInfo *nspinfo);
@@ -203,7 +201,8 @@ static void dumpRangeType(Archive *fout, const TypeInfo *tyinfo);
203201static void dumpUndefinedType(Archive *fout, const TypeInfo *tyinfo);
204202static void dumpDomain(Archive *fout, const TypeInfo *tyinfo);
205203static void dumpCompositeType(Archive *fout, const TypeInfo *tyinfo);
206- static void dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo);
204+ static void dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo,
205+ PGresult *res);
207206static void dumpShellType(Archive *fout, const ShellTypeInfo *stinfo);
208207static void dumpProcLang(Archive *fout, const ProcLangInfo *plang);
209208static void dumpFunc(Archive *fout, const FuncInfo *finfo);
@@ -9154,7 +9153,7 @@ dumpCommentExtended(Archive *fout, const char *type,
91549153 }
91559154
91569155 /* Search for comments associated with catalogId, using table */
9157- ncomments = findComments(fout, catalogId.tableoid, catalogId.oid,
9156+ ncomments = findComments(catalogId.tableoid, catalogId.oid,
91589157 &comments);
91599158
91609159 /* Is there one matching the subid? */
@@ -9260,8 +9259,7 @@ dumpTableComment(Archive *fout, const TableInfo *tbinfo,
92609259 return;
92619260
92629261 /* Search for comments associated with relation, using table */
9263- ncomments = findComments(fout,
9264- tbinfo->dobj.catId.tableoid,
9262+ ncomments = findComments(tbinfo->dobj.catId.tableoid,
92659263 tbinfo->dobj.catId.oid,
92669264 &comments);
92679265
@@ -9341,8 +9339,7 @@ dumpTableComment(Archive *fout, const TableInfo *tbinfo,
93419339 * one search.
93429340 */
93439341static int
9344- findComments(Archive *fout, Oid classoid, Oid objoid,
9345- CommentItem **items)
9342+ findComments(Oid classoid, Oid objoid, CommentItem **items)
93469343{
93479344 CommentItem *middle = NULL;
93489345 CommentItem *low;
@@ -10740,7 +10737,7 @@ dumpCompositeType(Archive *fout, const TypeInfo *tyinfo)
1074010737 */
1074110738 appendPQExpBufferStr(query,
1074210739 "PREPARE dumpCompositeType(pg_catalog.oid) AS\n"
10743- "SELECT a.attname, "
10740+ "SELECT a.attname, a.attnum, "
1074410741 "pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
1074510742 "a.attlen, a.attalign, a.attisdropped, "
1074610743 "CASE WHEN a.attcollation <> at.typcollation "
@@ -10891,92 +10888,71 @@ dumpCompositeType(Archive *fout, const TypeInfo *tyinfo)
1089110888 tyinfo->dobj.namespace->dobj.name,
1089210889 tyinfo->rolname, &tyinfo->dacl);
1089310890
10891+ /* Dump any per-column comments */
10892+ if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10893+ dumpCompositeTypeColComments(fout, tyinfo, res);
10894+
1089410895 PQclear(res);
1089510896 destroyPQExpBuffer(q);
1089610897 destroyPQExpBuffer(dropped);
1089710898 destroyPQExpBuffer(delq);
1089810899 destroyPQExpBuffer(query);
1089910900 free(qtypname);
1090010901 free(qualtypname);
10901-
10902- /* Dump any per-column comments */
10903- if (tyinfo->dobj.dump & DUMP_COMPONENT_COMMENT)
10904- dumpCompositeTypeColComments(fout, tyinfo);
1090510902}
1090610903
1090710904/*
1090810905 * dumpCompositeTypeColComments
1090910906 * writes out to fout the queries to recreate comments on the columns of
10910- * a user-defined stand-alone composite type
10907+ * a user-defined stand-alone composite type.
10908+ *
10909+ * The caller has already made a query to collect the names and attnums
10910+ * of the type's columns, so we just pass that result into here rather
10911+ * than reading them again.
1091110912 */
1091210913static void
10913- dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo)
10914+ dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo,
10915+ PGresult *res)
1091410916{
1091510917 CommentItem *comments;
1091610918 int ncomments;
10917- PGresult *res;
1091810919 PQExpBuffer query;
1091910920 PQExpBuffer target;
10920- Oid pgClassOid;
1092110921 int i;
1092210922 int ntups;
1092310923 int i_attname;
1092410924 int i_attnum;
10925+ int i_attisdropped;
1092510926
1092610927 /* do nothing, if --no-comments is supplied */
1092710928 if (fout->dopt->no_comments)
1092810929 return;
1092910930
10930- query = createPQExpBuffer();
10931-
10932- appendPQExpBuffer(query,
10933- "SELECT c.tableoid, a.attname, a.attnum "
10934- "FROM pg_catalog.pg_class c, pg_catalog.pg_attribute a "
10935- "WHERE c.oid = '%u' AND c.oid = a.attrelid "
10936- " AND NOT a.attisdropped "
10937- "ORDER BY a.attnum ",
10938- tyinfo->typrelid);
10939-
10940- /* Fetch column attnames */
10941- res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
10942-
10943- ntups = PQntuples(res);
10944- if (ntups < 1)
10945- {
10946- PQclear(res);
10947- destroyPQExpBuffer(query);
10948- return;
10949- }
10950-
10951- pgClassOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "tableoid")));
10952-
1095310931 /* Search for comments associated with type's pg_class OID */
10954- ncomments = findComments(fout,
10955- pgClassOid,
10956- tyinfo->typrelid,
10932+ ncomments = findComments(RelationRelationId, tyinfo->typrelid,
1095710933 &comments);
1095810934
1095910935 /* If no comments exist, we're done */
1096010936 if (ncomments <= 0)
10961- {
10962- PQclear(res);
10963- destroyPQExpBuffer(query);
1096410937 return;
10965- }
1096610938
1096710939 /* Build COMMENT ON statements */
10940+ query = createPQExpBuffer();
1096810941 target = createPQExpBuffer();
1096910942
10943+ ntups = PQntuples(res);
1097010944 i_attnum = PQfnumber(res, "attnum");
1097110945 i_attname = PQfnumber(res, "attname");
10946+ i_attisdropped = PQfnumber(res, "attisdropped");
1097210947 while (ncomments > 0)
1097310948 {
1097410949 const char *attname;
1097510950
1097610951 attname = NULL;
1097710952 for (i = 0; i < ntups; i++)
1097810953 {
10979- if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid)
10954+ if (atoi(PQgetvalue(res, i, i_attnum)) == comments->objsubid &&
10955+ PQgetvalue(res, i, i_attisdropped)[0] != 't')
1098010956 {
1098110957 attname = PQgetvalue(res, i, i_attname);
1098210958 break;
@@ -11013,7 +10989,6 @@ dumpCompositeTypeColComments(Archive *fout, const TypeInfo *tyinfo)
1101310989 ncomments--;
1101410990 }
1101510991
11016- PQclear(res);
1101710992 destroyPQExpBuffer(query);
1101810993 destroyPQExpBuffer(target);
1101910994}
@@ -14254,7 +14229,7 @@ dumpSecLabel(Archive *fout, const char *type, const char *name,
1425414229 }
1425514230
1425614231 /* Search for security labels associated with catalogId, using table */
14257- nlabels = findSecLabels(fout, catalogId.tableoid, catalogId.oid, &labels);
14232+ nlabels = findSecLabels(catalogId.tableoid, catalogId.oid, &labels);
1425814233
1425914234 query = createPQExpBuffer();
1426014235
@@ -14321,8 +14296,7 @@ dumpTableSecLabel(Archive *fout, const TableInfo *tbinfo, const char *reltypenam
1432114296 return;
1432214297
1432314298 /* Search for comments associated with relation, using table */
14324- nlabels = findSecLabels(fout,
14325- tbinfo->dobj.catId.tableoid,
14299+ nlabels = findSecLabels(tbinfo->dobj.catId.tableoid,
1432614300 tbinfo->dobj.catId.oid,
1432714301 &labels);
1432814302
@@ -14386,7 +14360,7 @@ dumpTableSecLabel(Archive *fout, const TableInfo *tbinfo, const char *reltypenam
1438614360 * found with one search.
1438714361 */
1438814362static int
14389- findSecLabels(Archive *fout, Oid classoid, Oid objoid, SecLabelItem **items)
14363+ findSecLabels(Oid classoid, Oid objoid, SecLabelItem **items)
1439014364{
1439114365 SecLabelItem *middle = NULL;
1439214366 SecLabelItem *low;
0 commit comments