This is an automated email from the ASF dual-hosted git repository.

tuhaihe pushed a commit to branch REL_2_STABLE
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 3beba4e620927ac2531ac3e2018b9a4d0f720770
Author: Tom Lane <[email protected]>
AuthorDate: Mon Dec 6 13:14:29 2021 -0500

    Use PREPARE/EXECUTE for repetitive per-object queries in pg_dump.
    
    Backported from PG15 be85727a3d
    
    Conflicts resolved:
    * Reject changes to dumpTableAttach, which
      added a query for partbound details in
      e3fcbbd623b9ccc16cdbda374654d91a4727d173
      and wasn't backported as it was considered
      too invasive.
    * Handle GPDB specific callbackfunc and
      prodataaccess fields in dumpFunc
    
    Original commit message follows:
    
    For objects such as functions, pg_dump issues the same secondary
    data-collection query against each object to be dumped.  This can't
    readily be refactored to avoid the repetitive queries, but we can
    PREPARE these queries to reduce planning costs.
    
    This patch applies the idea to functions, aggregates, operators, and
    data types.  While it could be carried further, the remaining sorts of
    objects aren't likely to appear in typical databases enough times to
    be worth worrying over.  Moreover, doing the PREPARE is likely to be a
    net loss if there aren't at least some dozens of objects to apply the
    prepared query to.
    
    Discussion: 
https://postgr.es/m/[email protected]
---
 src/bin/pg_dump/pg_backup.h |  20 ++
 src/bin/pg_dump/pg_dump.c   | 849 ++++++++++++++++++++++++--------------------
 2 files changed, 486 insertions(+), 383 deletions(-)

diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 5f414e18686..07d207f9593 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -58,6 +58,23 @@ typedef enum _teSection
        SECTION_POST_DATA                       /* stuff to be processed after 
data */
 } teSection;
 
+/* We need one enum entry per prepared query in pg_dump */
+enum _dumpPreparedQueries
+{
+       PREPQUERY_DUMPAGG,
+       PREPQUERY_DUMPBASETYPE,
+       PREPQUERY_DUMPCOMPOSITETYPE,
+       PREPQUERY_DUMPDOMAIN,
+       PREPQUERY_DUMPENUMTYPE,
+       PREPQUERY_DUMPFUNC,
+       PREPQUERY_DUMPOPR,
+       PREPQUERY_DUMPRANGETYPE,
+       PREPQUERY_DUMPTABLEATTACH,
+       PREPQUERY_GETCOLUMNACLS,
+       PREPQUERY_GETDOMAINCONSTRAINTS,
+       NUM_PREP_QUERIES                        /* must be last */
+};
+
 /* Parameters needed by ConnectDatabase; same for dump and restore */
 typedef struct _connParams
 {
@@ -234,6 +251,9 @@ typedef struct Archive
 
        DatabaseVersion version;
 
+       /* prepared-query status */
+       bool       *is_prepared;        /* indexed by enum _dumpPreparedQueries 
*/
+
        /* The rest is private */
 } Archive;
 
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 211209f7b45..be9290b49bf 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -1494,6 +1494,12 @@ setup_connection(Archive *AH, const char *dumpencoding,
         */
        set_restrict_relation_kind(AH, "view, foreign-table");
 
+       /*
+        * Initialize prepared-query state to "nothing prepared".  We do this 
here
+        * so that a parallel dump worker will have its own state.
+        */
+       AH->is_prepared = (bool *) pg_malloc0(NUM_PREP_QUERIES * sizeof(bool));
+
        /*
         * Start transaction-snapshot mode transaction to dump consistent data.
         */
@@ -8519,7 +8525,7 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
 {
        int                     i;
        ConstraintInfo *constrinfo;
-       PQExpBuffer query;
+       PQExpBuffer query = createPQExpBuffer();
        PGresult   *res;
        int                     i_tableoid,
                                i_oid,
@@ -8527,25 +8533,35 @@ getDomainConstraints(Archive *fout, TypeInfo *tyinfo)
                                i_consrc;
        int                     ntups;
 
-       query = createPQExpBuffer();
+       if (!fout->is_prepared[PREPQUERY_GETDOMAINCONSTRAINTS])
+       {
+               /* Set up query for constraint-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
getDomainConstraints(pg_catalog.oid) AS\n");
+
+               if (fout->remoteVersion >= 90100)
+                       appendPQExpBufferStr(query, "SELECT tableoid, oid, 
conname, "
+                                                                
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
+                                                                "convalidated "
+                                                                "FROM 
pg_catalog.pg_constraint "
+                                                                "WHERE 
contypid = $1 "
+                                                                "ORDER BY 
conname");
+               else
+                       appendPQExpBufferStr(query, "SELECT tableoid, oid, 
conname, "
+                                                                
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
+                                                                "true as 
convalidated "
+                                                                "FROM 
pg_catalog.pg_constraint "
+                                                                "WHERE 
contypid = $1 "
+                                                                "ORDER BY 
conname");
 
-       if (fout->remoteVersion >= 90100)
-               appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
-                                                 
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
-                                                 "convalidated "
-                                                 "FROM 
pg_catalog.pg_constraint "
-                                                 "WHERE contypid = 
'%u'::pg_catalog.oid "
-                                                 "ORDER BY conname",
-                                                 tyinfo->dobj.catId.oid);
+               ExecuteSqlStatement(fout, query->data);
 
-       else
-               appendPQExpBuffer(query, "SELECT tableoid, oid, conname, "
-                                                 
"pg_catalog.pg_get_constraintdef(oid) AS consrc, "
-                                                 "true as convalidated "
-                                                 "FROM 
pg_catalog.pg_constraint "
-                                                 "WHERE contypid = 
'%u'::pg_catalog.oid "
-                                                 "ORDER BY conname",
-                                                 tyinfo->dobj.catId.oid);
+               fout->is_prepared[PREPQUERY_GETDOMAINCONSTRAINTS] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE getDomainConstraints('%u')",
+                                         tyinfo->dobj.catId.oid);
 
        res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
@@ -11645,18 +11661,31 @@ dumpEnumType(Archive *fout, const TypeInfo *tyinfo)
        int                     i_enumlabel;
        int                     i_oid;
 
-       if (fout->remoteVersion >= 90100)
-               appendPQExpBuffer(query, "SELECT oid, enumlabel "
-                                                 "FROM pg_catalog.pg_enum "
-                                                 "WHERE enumtypid = '%u'"
-                                                 "ORDER BY enumsortorder",
-                                                 tyinfo->dobj.catId.oid);
-       else
-               appendPQExpBuffer(query, "SELECT oid, enumlabel "
-                                                 "FROM pg_catalog.pg_enum "
-                                                 "WHERE enumtypid = '%u'"
-                                                 "ORDER BY oid",
-                                                 tyinfo->dobj.catId.oid);
+       if (!fout->is_prepared[PREPQUERY_DUMPENUMTYPE])
+       {
+               /* Set up query for enum-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpEnumType(pg_catalog.oid) AS\n");
+
+               if (fout->remoteVersion >= 90100)
+                       appendPQExpBufferStr(query, "SELECT oid, enumlabel "
+                                                                "FROM 
pg_catalog.pg_enum "
+                                                                "WHERE 
enumtypid = $1 "
+                                                                "ORDER BY 
enumsortorder");
+               else
+                       appendPQExpBufferStr(query, "SELECT oid, enumlabel "
+                                                                "FROM 
pg_catalog.pg_enum "
+                                                                "WHERE 
enumtypid = $1 "
+                                                                "ORDER BY 
oid");
+
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPENUMTYPE] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpEnumType('%u')",
+                                         tyinfo->dobj.catId.oid);
 
        res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
@@ -11777,29 +11806,43 @@ dumpRangeType(Archive *fout, const TypeInfo *tyinfo)
        char       *qualtypname;
        char       *procname;
 
-       appendPQExpBuffer(query,
-                                         "SELECT ");
+       if (!fout->is_prepared[PREPQUERY_DUMPRANGETYPE])
+       {
+               /* Set up query for range-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpRangeType(pg_catalog.oid) AS\n");
 
-       if (fout->remoteVersion >= 140000)
-               appendPQExpBuffer(query,
-                                                 
"pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
-       else
-               appendPQExpBuffer(query,
-                                                 "NULL AS rngmultitype, ");
+               appendPQExpBufferStr(query,
+                                                        "SELECT ");
 
-       appendPQExpBuffer(query,
-                                         "pg_catalog.format_type(rngsubtype, 
NULL) AS rngsubtype, "
-                                         "opc.opcname AS opcname, "
-                                         "(SELECT nspname FROM 
pg_catalog.pg_namespace nsp "
-                                         "  WHERE nsp.oid = opc.opcnamespace) 
AS opcnsp, "
-                                         "opc.opcdefault, "
-                                         "CASE WHEN rngcollation = 
st.typcollation THEN 0 "
-                                         "     ELSE rngcollation END AS 
collation, "
-                                         "rngcanonical, rngsubdiff "
-                                         "FROM pg_catalog.pg_range r, 
pg_catalog.pg_type st, "
-                                         "     pg_catalog.pg_opclass opc "
-                                         "WHERE st.oid = rngsubtype AND 
opc.oid = rngsubopc AND "
-                                         "rngtypid = '%u'",
+               if (fout->remoteVersion >= 140000)
+                       appendPQExpBuffer(query,
+                                                       
"pg_catalog.format_type(rngmultitypid, NULL) AS rngmultitype, ");
+               else
+                       appendPQExpBuffer(query,
+                                                       "NULL AS rngmultitype, 
");
+
+               appendPQExpBufferStr(query,
+                                                        
"pg_catalog.format_type(rngsubtype, NULL) AS rngsubtype, "
+                                                        "opc.opcname AS 
opcname, "
+                                                        "(SELECT nspname FROM 
pg_catalog.pg_namespace nsp "
+                                                        "  WHERE nsp.oid = 
opc.opcnamespace) AS opcnsp, "
+                                                        "opc.opcdefault, "
+                                                        "CASE WHEN 
rngcollation = st.typcollation THEN 0 "
+                                                        "     ELSE 
rngcollation END AS collation, "
+                                                        "rngcanonical, 
rngsubdiff "
+                                                        "FROM 
pg_catalog.pg_range r, pg_catalog.pg_type st, "
+                                                        "     
pg_catalog.pg_opclass opc "
+                                                        "WHERE st.oid = 
rngsubtype AND opc.oid = rngsubopc AND "
+                                                        "rngtypid = $1");
+
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPRANGETYPE] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpRangeType('%u')",
                                          tyinfo->dobj.catId.oid);
 
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
@@ -12011,55 +12054,68 @@ dumpBaseType(Archive *fout, const TypeInfo *tyinfo)
        char       *typdefault;
        bool            typdefault_is_literal = false;
 
-       /* Fetch type-specific details */
-       appendPQExpBufferStr(query, "SELECT typlen, "
-                                                "typinput, typoutput, 
typreceive, typsend, "
-                                                "typreceive::pg_catalog.oid AS 
typreceiveoid, "
-                                                "typsend::pg_catalog.oid AS 
typsendoid, "
-                                                "typanalyze, "
-                                                "typanalyze::pg_catalog.oid AS 
typanalyzeoid, "
-                                                "typdelim, typbyval, typalign, 
typstorage, ");
-
-       if (fout->remoteVersion >= 80300)
-               appendPQExpBufferStr(query,
-                                                        "typmodin, typmodout, "
-                                                        
"typmodin::pg_catalog.oid AS typmodinoid, "
-                                                        
"typmodout::pg_catalog.oid AS typmodoutoid, ");
-       else
+       if (!fout->is_prepared[PREPQUERY_DUMPBASETYPE])
+       {
+               /* Set up query for type-specific details */
                appendPQExpBufferStr(query,
-                                                        "'-' AS typmodin, '-' 
AS typmodout, "
-                                                        "0 AS typmodinoid, 0 
AS typmodoutoid, ");
+                                                       "PREPARE 
dumpBaseType(pg_catalog.oid) AS\n");
 
-       if (fout->remoteVersion >= 80400)
-               appendPQExpBufferStr(query,
-                                                        "typcategory, 
typispreferred, ");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'U' AS typcategory, 
false AS typispreferred, ");
+               appendPQExpBufferStr(query, "SELECT typlen, "
+                                                       "typinput, typoutput, 
typreceive, typsend, "
+                                                       
"typreceive::pg_catalog.oid AS typreceiveoid, "
+                                                       
"typsend::pg_catalog.oid AS typsendoid, "
+                                                       "typanalyze, "
+                                                       
"typanalyze::pg_catalog.oid AS typanalyzeoid, "
+                                                       "typdelim, typbyval, 
typalign, typstorage, ");
 
-       if (fout->remoteVersion >= 90100)
-               appendPQExpBufferStr(query, "(typcollation <> 0) AS 
typcollatable, ");
-       else
-               appendPQExpBufferStr(query, "false AS typcollatable, ");
+               if (fout->remoteVersion >= 80300)
+                       appendPQExpBufferStr(query,
+                                                               "typmodin, 
typmodout, "
+                                                               
"typmodin::pg_catalog.oid AS typmodinoid, "
+                                                               
"typmodout::pg_catalog.oid AS typmodoutoid, ");
+               else
+                       appendPQExpBufferStr(query,
+                                                               "'-' AS 
typmodin, '-' AS typmodout, "
+                                                               "0 AS 
typmodinoid, 0 AS typmodoutoid, ");
 
-       if (fout->remoteVersion >= 140000)
-               appendPQExpBufferStr(query,
-                                                        "typsubscript, "
-                                                        
"typsubscript::pg_catalog.oid AS typsubscriptoid, ");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'-' AS typsubscript, 
0 AS typsubscriptoid, ");
+               if (fout->remoteVersion >= 80400)
+                       appendPQExpBufferStr(query,
+                                                               "typcategory, 
typispreferred, ");
+               else
+                       appendPQExpBufferStr(query,
+                                                               "'U' AS 
typcategory, false AS typispreferred, ");
 
-       /* Before 8.4, pg_get_expr does not allow 0 for its second arg */
-       if (fout->remoteVersion >= 80400)
-               appendPQExpBufferStr(query,
-                                                        
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault ");
-       else
-               appendPQExpBufferStr(query,
-                                                        
"pg_catalog.pg_get_expr(typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault ");
+               if (fout->remoteVersion >= 140000)
+                       appendPQExpBufferStr(query,
+                                                               "typsubscript, "
+                                                               
"typsubscript::pg_catalog.oid AS typsubscriptoid, ");
+               else
+                       appendPQExpBufferStr(query,
+                                                               "'-' AS 
typsubscript, 0 AS typsubscriptoid, ");
+               
+               if (fout->remoteVersion >= 90100)
+                       appendPQExpBufferStr(query, "(typcollation <> 0) AS 
typcollatable, ");
+               else
+                       appendPQExpBufferStr(query, "false AS typcollatable, ");
 
-       appendPQExpBuffer(query, "FROM pg_catalog.pg_type "
-                                         "WHERE oid = '%u'::pg_catalog.oid",
+               /* Before 8.4, pg_get_expr does not allow 0 for its second arg 
*/
+               if (fout->remoteVersion >= 80400)
+                       appendPQExpBufferStr(query,
+                                                               
"pg_catalog.pg_get_expr(typdefaultbin, 0) AS typdefaultbin, typdefault ");
+               else
+                       appendPQExpBufferStr(query,
+                                                               
"pg_catalog.pg_get_expr(typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, typdefault ");
+
+               appendPQExpBuffer(query, "FROM pg_catalog.pg_type "
+                                                       "WHERE oid = $1");
+
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPBASETYPE] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpBaseType('%u')",
                                          tyinfo->dobj.catId.oid);
 
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
@@ -12285,32 +12341,44 @@ dumpDomain(Archive *fout, const TypeInfo *tyinfo)
        Oid                     typcollation;
        bool            typdefault_is_literal = false;
 
-       /* Fetch domain specific details */
-       if (fout->remoteVersion >= 90100)
+       if (!fout->is_prepared[PREPQUERY_DUMPDOMAIN])
        {
-               /* typcollation is new in 9.1 */
-               appendPQExpBuffer(query, "SELECT t.typnotnull, "
-                                                 
"pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
-                                                 
"pg_catalog.pg_get_expr(t.typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
-                                                 "t.typdefault, "
-                                                 "CASE WHEN t.typcollation <> 
u.typcollation "
-                                                 "THEN t.typcollation ELSE 0 
END AS typcollation "
-                                                 "FROM pg_catalog.pg_type t "
-                                                 "LEFT JOIN pg_catalog.pg_type 
u ON (t.typbasetype = u.oid) "
-                                                 "WHERE t.oid = 
'%u'::pg_catalog.oid",
-                                                 tyinfo->dobj.catId.oid);
-       }
-       else
-       {
-               appendPQExpBuffer(query, "SELECT typnotnull, "
-                                                 
"pg_catalog.format_type(typbasetype, typtypmod) AS typdefn, "
-                                                 
"pg_catalog.pg_get_expr(typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
-                                                 "typdefault, 0 AS 
typcollation "
-                                                 "FROM pg_catalog.pg_type "
-                                                 "WHERE oid = 
'%u'::pg_catalog.oid",
-                                                 tyinfo->dobj.catId.oid);
+               /* Set up query for domain-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpDomain(pg_catalog.oid) AS\n");
+
+               if (fout->remoteVersion >= 90100)
+               {
+                       /* typcollation is new in 9.1 */
+                       appendPQExpBufferStr(query, "SELECT t.typnotnull, "
+                                                                
"pg_catalog.format_type(t.typbasetype, t.typtypmod) AS typdefn, "
+                                                                
"pg_catalog.pg_get_expr(t.typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
+                                                                "t.typdefault, 
"
+                                                                "CASE WHEN 
t.typcollation <> u.typcollation "
+                                                                "THEN 
t.typcollation ELSE 0 END AS typcollation "
+                                                                "FROM 
pg_catalog.pg_type t "
+                                                                "LEFT JOIN 
pg_catalog.pg_type u ON (t.typbasetype = u.oid) "
+                                                                "WHERE t.oid = 
$1");
+               }
+               else
+               {
+                       appendPQExpBufferStr(query, "SELECT typnotnull, "
+                                                                
"pg_catalog.format_type(typbasetype, typtypmod) AS typdefn, "
+                                                                
"pg_catalog.pg_get_expr(typdefaultbin, 
'pg_catalog.pg_type'::pg_catalog.regclass) AS typdefaultbin, "
+                                                                "typdefault, 0 
AS typcollation "
+                                                                "FROM 
pg_catalog.pg_type "
+                                                                "WHERE oid = 
$1");
+               }
+
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPDOMAIN] = true;
        }
 
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpDomain('%u')",
+                                         tyinfo->dobj.catId.oid);
+
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
 
        typnotnull = PQgetvalue(res, 0, PQfnumber(res, "typnotnull"));
@@ -12465,45 +12533,57 @@ dumpCompositeType(Archive *fout, const TypeInfo 
*tyinfo)
        int                     i;
        int                     actual_atts;
 
-       /* Fetch type specific details */
-       if (fout->remoteVersion >= 90100)
-       {
-               /*
-                * attcollation is new in 9.1.  Since we only want to dump 
COLLATE
-                * clauses for attributes whose collation is different from 
their
-                * type's default, we use a CASE here to suppress uninteresting
-                * attcollations cheaply.  atttypid will be 0 for dropped 
columns;
-                * collation does not matter for those.
-                */
-               appendPQExpBuffer(query, "SELECT a.attname, "
-                                                 
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
-                                                 "a.attlen, a.attalign, 
a.attisdropped, "
-                                                 "CASE WHEN a.attcollation <> 
at.typcollation "
-                                                 "THEN a.attcollation ELSE 0 
END AS attcollation "
-                                                 "FROM pg_catalog.pg_type ct "
-                                                 "JOIN pg_catalog.pg_attribute 
a ON a.attrelid = ct.typrelid "
-                                                 "LEFT JOIN pg_catalog.pg_type 
at ON at.oid = a.atttypid "
-                                                 "WHERE ct.oid = 
'%u'::pg_catalog.oid "
-                                                 "ORDER BY a.attnum ",
-                                                 tyinfo->dobj.catId.oid);
-       }
-       else
+       if (!fout->is_prepared[PREPQUERY_DUMPCOMPOSITETYPE])
        {
-               /*
-                * Since ALTER TYPE could not drop columns until 9.1, 
attisdropped
-                * should always be false.
-                */
-               appendPQExpBuffer(query, "SELECT a.attname, "
-                                                 
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
-                                                 "a.attlen, a.attalign, 
a.attisdropped, "
-                                                 "0 AS attcollation "
-                                                 "FROM pg_catalog.pg_type ct, 
pg_catalog.pg_attribute a "
-                                                 "WHERE ct.oid = 
'%u'::pg_catalog.oid "
-                                                 "AND a.attrelid = ct.typrelid 
"
-                                                 "ORDER BY a.attnum ",
-                                                 tyinfo->dobj.catId.oid);
+               /* Set up query for type-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpCompositeType(pg_catalog.oid) AS\n");
+
+               if (fout->remoteVersion >= 90100)
+               {
+                       /*
+                        * attcollation is new in 9.1.  Since we only want to 
dump COLLATE
+                        * clauses for attributes whose collation is different 
from their
+                        * type's default, we use a CASE here to suppress 
uninteresting
+                        * attcollations cheaply.  atttypid will be 0 for 
dropped columns;
+                        * collation does not matter for those.
+                        */
+                       appendPQExpBufferStr(query, "SELECT a.attname, "
+                                                                
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
+                                                                "a.attlen, 
a.attalign, a.attisdropped, "
+                                                                "CASE WHEN 
a.attcollation <> at.typcollation "
+                                                                "THEN 
a.attcollation ELSE 0 END AS attcollation "
+                                                                "FROM 
pg_catalog.pg_type ct "
+                                                                "JOIN 
pg_catalog.pg_attribute a ON a.attrelid = ct.typrelid "
+                                                                "LEFT JOIN 
pg_catalog.pg_type at ON at.oid = a.atttypid "
+                                                                "WHERE ct.oid 
= $1 "
+                                                                "ORDER BY 
a.attnum");
+               }
+               else
+               {
+                       /*
+                        * Since ALTER TYPE could not drop columns until 9.1, 
attisdropped
+                        * should always be false.
+                        */
+                       appendPQExpBufferStr(query, "SELECT a.attname, "
+                                                                
"pg_catalog.format_type(a.atttypid, a.atttypmod) AS atttypdefn, "
+                                                                "a.attlen, 
a.attalign, a.attisdropped, "
+                                                                "0 AS 
attcollation "
+                                                                "FROM 
pg_catalog.pg_type ct, pg_catalog.pg_attribute a "
+                                                                "WHERE ct.oid 
= $1 "
+                                                                "AND 
a.attrelid = ct.typrelid "
+                                                                "ORDER BY 
a.attnum");
+               }
+
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPCOMPOSITETYPE] = true;
        }
 
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpCompositeType('%u')",
+                                         tyinfo->dobj.catId.oid);
+
        res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
        ntups = PQntuples(res);
@@ -13214,118 +13294,94 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
        q = createPQExpBuffer();
        delqry = createPQExpBuffer();
        asPart = createPQExpBuffer();
+       
+       if (!fout->is_prepared[PREPQUERY_DUMPFUNC])
+       {
+               /* GPDB_95_MERGE_FIXME: use isGE70 instead? */
+               /* Set up query for function-specific details */
+               appendPQExpBufferStr(query, "PREPARE dumpFunc(pg_catalog.oid) 
AS\n");
 
-       /* Fetch function-specific details */
-       appendPQExpBufferStr(query,
-                                                "SELECT\n"
-                                                "proretset,\n"
-                                                "prosrc,\n"
-                                                "probin,\n"
-                                                "provolatile,\n"
-                                                "proisstrict,\n"
-                                                "prosecdef,\n"
-                                                "lanname,\n");
+               appendPQExpBuffer(query,
+                                                       "SELECT\n"
+                                                       "proretset,\n"
+                                                       "prosrc,\n"
+                                                       "probin,\n"
+                                                       "provolatile,\n"
+                                                       "proisstrict,\n"
+                                                       "prosecdef,\n"
+                                                       "(SELECT lanname FROM 
pg_catalog.pg_language WHERE oid = prolang) AS lanname,\n "
+                                                       "proconfig,\n"
+                                                       "procost,\n"
+                                                       "prorows,\n"
+                                                       "prodataaccess,\n"
+                                                       
"pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
+                                                       
"pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
+                                                       
"pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n"
+                                                       "(SELECT procallback 
FROM pg_catalog.pg_proc_callback WHERE profnoid::pg_catalog.oid = p.oid) as 
callbackfunc,\n");
 
-       if (fout->remoteVersion >= 80300)
-       {
-               appendPQExpBufferStr(query,
-                                                        "proconfig,\n"
-                                                        "procost,\n"
-                                                        "prorows,\n");
+               if (fout->remoteVersion >= 90200)
+                       appendPQExpBuffer(query,
+                                                               
"proleakproof,\n");
+               else
+                       appendPQExpBuffer(query,
+                                                               "false AS 
proleakproof,\n");
 
-               if (isGE50 && fout->remoteVersion < 90200)
-               {
-                       appendPQExpBufferStr(query,
-                                                                
"prodataaccess,\n"
-                                                                "'a' as 
proexeclocation,\n"
-                                                                "(SELECT 
procallback FROM pg_catalog.pg_proc_callback WHERE profnoid::pg_catalog.oid = 
p.oid) as callbackfunc,\n");
-               }
-       }
-       else
-       {
-               appendPQExpBufferStr(query,
-                                                        "null AS proconfig,\n"
-                                                        "0 AS procost,\n"
-                                                        "0 AS prorows,\n");
+               /* GPDB6 added proexeclocation */
+               if (fout->remoteVersion >= 90400)
+                               appendPQExpBuffer(query,
+                                                               
"proexeclocation,\n");
+               else
+                               appendPQExpBuffer(query,
+                                                               "'a' as 
proexeclocation,\n");
 
-               appendPQExpBuffer(query,
-                                                        "%s\n"
-                                                        "'a' as 
proexeclocation,\n"
-                                                        "(SELECT procallback 
FROM pg_catalog.pg_proc_callback WHERE profnoid::pg_catalog.oid = p.oid) as 
callbackfunc,\n",
-                                                        "prodataaccess,");
-       }
+               if (fout->remoteVersion >= 90500)
+                       appendPQExpBuffer(query,
+                                                               
"array_to_string(protrftypes, ' ') AS protrftypes,\n");
 
-       if (fout->remoteVersion >= 80400)
-       {
-               /*
-                * In GPDB 5.0 and up we rely on pg_get_function_arguments and
-                * pg_get_function_result instead of examining proallargtypes 
etc.
-                */
-               appendPQExpBufferStr(query,
-                                                        
"pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
-                                                        
"pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n"
-                                                        
"pg_catalog.pg_get_function_result(p.oid) AS funcresult,\n");
-       }
-       else if (fout->remoteVersion >= 80100)
-               appendPQExpBufferStr(query,
-                                                        "proallargtypes,\n"
-                                                        "proargmodes,\n"
-                                                        "proargnames,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "null AS 
proallargtypes,\n"
-                                                        "null AS 
proargmodes,\n"
-                                                        "proargnames,\n");
+               if (fout->remoteVersion >= 90600)
+                       appendPQExpBuffer(query,
+                                                               
"proparallel,\n");
+               else
+                       appendPQExpBuffer(query,
+                                                               "'u' AS 
proparallel,\n");
 
-       if (fout->remoteVersion >= 90200)
-               appendPQExpBufferStr(query,
-                                                        "prodataaccess,\n"
-                                                        "proexeclocation,\n"
-                                                       "(SELECT procallback 
FROM pg_catalog.pg_proc_callback WHERE profnoid::pg_catalog.oid = p.oid) as 
callbackfunc,\n"
-                                                        "proleakproof,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "false AS 
proleakproof,\n");
+               if (fout->remoteVersion >= 110000)
+                       appendPQExpBuffer(query,
+                                                               "prokind,\n");
+               else if (fout->remoteVersion >= 80400)
+                       appendPQExpBuffer(query,
+                                                               "CASE WHEN 
proiswindow THEN 'w' ELSE 'f' END AS prokind,\n");
+               else
+                       appendPQExpBuffer(query,
+                                                               "CASE WHEN 
proiswin THEN 'w' ELSE 'f' END AS prokind,\n");
 
-       if (fout->remoteVersion >= 90500)
-               appendPQExpBufferStr(query,
-                                                        
"array_to_string(protrftypes, ' ') AS protrftypes,\n");
+               if (fout->remoteVersion >= 120000)
+                       appendPQExpBuffer(query,
+                                                               
"prosupport,\n");
+               else
+                       appendPQExpBuffer(query,
+                                                               "'-' AS 
prosupport,\n");
 
-       if (fout->remoteVersion >= 90600)
-               appendPQExpBufferStr(query,
-                                                        "proparallel,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'u' AS 
proparallel,\n");
+               if (fout->remoteVersion >= 140000)
+                       appendPQExpBufferStr(query,
+                                                               
"pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                               "NULL AS 
prosqlbody\n");
 
-       if (fout->remoteVersion >= 110000)
-               appendPQExpBufferStr(query,
-                                                        "prokind,\n");
-       else if (fout->remoteVersion >= 80400)
-               appendPQExpBufferStr(query,
-                                                        "CASE WHEN proiswindow 
THEN 'w' ELSE 'f' END AS prokind,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'f' AS prokind,\n");
+               appendPQExpBuffer(query,
+                                                        "FROM 
pg_catalog.pg_proc p, pg_catalog.pg_language l\n"
+                                                        "WHERE p.oid = $1 "
+                                                        "AND l.oid = 
p.prolang");
 
-       if (fout->remoteVersion >= 120000)
-               appendPQExpBufferStr(query,
-                                                        "prosupport,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'-' AS 
prosupport,\n");
+               ExecuteSqlStatement(fout, query->data);
 
-       if (fout->remoteVersion >= 140000)
-               appendPQExpBufferStr(query,
-                                                        
"pg_get_function_sqlbody(p.oid) AS prosqlbody\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "NULL AS 
prosqlbody\n");
+               fout->is_prepared[PREPQUERY_DUMPFUNC] = true;
 
-       appendPQExpBuffer(query,
-                                         "FROM pg_catalog.pg_proc p, 
pg_catalog.pg_language l\n"
-                                         "WHERE p.oid = '%u'::pg_catalog.oid "
-                                         "AND l.oid = p.prolang",
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpFunc('%u')",
                                          finfo->dobj.catId.oid);
 
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
@@ -13777,6 +13833,7 @@ dumpFunc(Archive *fout, const FuncInfo *finfo)
 }
 
 
+
 /*
  * Dump a user-defined cast
  */
@@ -14064,19 +14121,32 @@ dumpOpr(Archive *fout, const OprInfo *oprinfo)
        oprid = createPQExpBuffer();
        details = createPQExpBuffer();
 
+       if (!fout->is_prepared[PREPQUERY_DUMPOPR])
+       {
+               /* Set up query for operator-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpOpr(pg_catalog.oid) AS\n");
+
+               appendPQExpBuffer(query, "SELECT oprkind, "
+                                                       
"oprcode::pg_catalog.regprocedure, "
+                                                       
"oprleft::pg_catalog.regtype, "
+                                                       
"oprright::pg_catalog.regtype, "
+                                                       "oprcom, "
+                                                       "oprnegate, "
+                                                       
"oprrest::pg_catalog.regprocedure, "
+                                                       
"oprjoin::pg_catalog.regprocedure, "
+                                                       "oprcanmerge, 
oprcanhash "
+                                                       "FROM 
pg_catalog.pg_operator "
+                                                       "WHERE oid = $1");
 
-       appendPQExpBuffer(query, "SELECT oprkind, "
-                                               
"oprcode::pg_catalog.regprocedure, "
-                                               "oprleft::pg_catalog.regtype, "
-                                               "oprright::pg_catalog.regtype, "
-                                               "oprcom, "
-                                               "oprnegate, "
-                                               
"oprrest::pg_catalog.regprocedure, "
-                                               
"oprjoin::pg_catalog.regprocedure, "
-                                               "oprcanmerge, oprcanhash "
-                                               "FROM pg_catalog.pg_operator "
-                                               "WHERE oid = 
'%u'::pg_catalog.oid",
-                                               oprinfo->dobj.catId.oid);
+               ExecuteSqlStatement(fout, query->data);
+
+               fout->is_prepared[PREPQUERY_DUMPOPR] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpOpr('%u')",
+                                         oprinfo->dobj.catId.oid);
 
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
 
@@ -15344,97 +15414,97 @@ dumpAgg(Archive *fout, const AggInfo *agginfo)
        delq = createPQExpBuffer();
        details = createPQExpBuffer();
 
+       if (!fout->is_prepared[PREPQUERY_DUMPAGG])
+       {
+               /* Set up query for aggregate-specific details */
+               appendPQExpBufferStr(query,
+                                                        "PREPARE 
dumpAgg(pg_catalog.oid) AS\n");
 
-       /*
-       * GPDB_14_MERGE_FIXME:
-       * Some fields:
-       * aggcombinefn, aggserialfn,
-       * aggdeserialfn, aggmtransfn,
-       * aggminvtransfn, aggmfinalfn,
-       * aggmtranstype::pg_catalog.regtype, aggfinalextra,
-       * aggmfinalextra,
-       * diffs from upsreaam in certain versions between [80100, 90600].
-       * But others versions are same.
-       * I think we should keep the same with upsream here, special
-       * handles are not need in such versions.
-       * Need to recheck.
-       */
+               appendPQExpBufferStr(query,
+                                                        "SELECT "
+                                                        "aggtransfn,\n"
+                                                        "aggfinalfn,\n"
+                                                        
"aggtranstype::pg_catalog.regtype,\n"
+                                                        "agginitval,\n");
 
-       /* Get aggregate-specific details */
-       appendPQExpBufferStr(query,
-                                                "SELECT\n"
-                                                "aggtransfn,\n"
-                                                "aggfinalfn,\n"
-                                                
"aggtranstype::pg_catalog.regtype,\n"
-                                                "agginitval,\n");
+               if (fout->remoteVersion >= 80100)
+                       appendPQExpBufferStr(query,
+                                                                
"aggsortop,\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                                "0 AS 
aggsortop,\n");
 
-       if (fout->remoteVersion >= 80100)
-               appendPQExpBufferStr(query,
-                                                        "aggsortop,\n");
+               if (fout->remoteVersion >= 80400)
+                       appendPQExpBufferStr(query,
+                                                                
"pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
+                                                                
"pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
 
-       if (fout->remoteVersion >= 80400)
-               appendPQExpBufferStr(query,
-                                                        
"pg_catalog.pg_get_function_arguments(p.oid) AS funcargs,\n"
-                                                        
"pg_catalog.pg_get_function_identity_arguments(p.oid) AS funciargs,\n");
+               if (fout->remoteVersion >= 90400)
+                       appendPQExpBufferStr(query,
+                                                                "aggkind,\n"
+                                                                
"aggmtransfn,\n"
+                                                                
"aggminvtransfn,\n"
+                                                                
"aggmfinalfn,\n"
+                                                                
"aggmtranstype::pg_catalog.regtype,\n"
+                                                                
"aggfinalextra,\n"
+                                                                
"aggmfinalextra,\n"
+                                                                
"aggtransspace,\n"
+                                                                
"aggmtransspace,\n"
+                                                                
"aggminitval,\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                                "'n' AS 
aggkind,\n"
+                                                                "'-' AS 
aggmtransfn,\n"
+                                                                "'-' AS 
aggminvtransfn,\n"
+                                                                "'-' AS 
aggmfinalfn,\n"
+                                                                "0 AS 
aggmtranstype,\n"
+                                                                "false AS 
aggfinalextra,\n"
+                                                                "false AS 
aggmfinalextra,\n"
+                                                                "0 AS 
aggtransspace,\n"
+                                                                "0 AS 
aggmtransspace,\n"
+                                                                "NULL AS 
aggminitval,\n");
 
-       if (fout->remoteVersion >= 90400)
-               appendPQExpBufferStr(query,
-                                                        "aggkind,\n"
-                                                        "aggmtransfn,\n"
-                                                        "aggminvtransfn,\n"
-                                                        "aggmfinalfn,\n"
-                                                        
"aggmtranstype::pg_catalog.regtype,\n"
-                                                        "aggfinalextra,\n"
-                                                        "aggmfinalextra,\n"
-                                                        "aggtransspace,\n"
-                                                        "aggmtransspace,\n"
-                                                        "aggminitval,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'n' AS aggkind,\n"
-                                                        "'-' AS aggmtransfn,\n"
-                                                        "'-' AS 
aggminvtransfn,\n"
-                                                        "'-' AS aggmfinalfn,\n"
-                                                        "0 AS aggmtranstype,\n"
-                                                        "false AS 
aggfinalextra,\n"
-                                                        "false AS 
aggmfinalextra,\n"
-                                                        "0 AS aggtransspace,\n"
-                                                        "0 AS 
aggmtransspace,\n"
-                                                        "NULL AS 
aggminitval,\n");
+               if (fout->remoteVersion >= 90600)
+                       appendPQExpBufferStr(query,
+                                                                
"aggcombinefn,\n"
+                                                                
"aggserialfn,\n"
+                                                                
"aggdeserialfn,\n"
+                                                                
"proparallel,\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                                "'-' AS 
aggcombinefn,\n"
+                                                                "'-' AS 
aggserialfn,\n"
+                                                                "'-' AS 
aggdeserialfn,\n"
+                                                                "'u' AS 
proparallel,\n");
 
-       if (fout->remoteVersion >= 90600)
-               appendPQExpBufferStr(query,
-                                                        "aggcombinefn,\n"
-                                                        "aggserialfn,\n"
-                                                        "aggdeserialfn,\n"
-                                                        "proparallel,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'-' AS 
aggcombinefn,\n"
-                                                        "'-' AS aggserialfn,\n"
-                                                        "'-' AS 
aggdeserialfn,\n"
-                                                        "'u' AS 
proparallel,\n");
+               if (fout->remoteVersion >= 110000)
+                       appendPQExpBufferStr(query,
+                                                                
"aggfinalmodify,\n"
+                                                                
"aggmfinalmodify\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                                "'0' AS 
aggfinalmodify,\n"
+                                                                "'0' AS 
aggmfinalmodify\n");
+               
+               if (fout->remoteVersion >= 140000 && fout->version.type == 
Cloudberry && fout->version.version >= 2)
+                       appendPQExpBufferStr(query,
+                                                                       
"aggrepsafeexec\n");
+               else
+                       appendPQExpBufferStr(query,
+                                                                       "false 
AS aggrepsafeexec\n");
 
-       if (fout->remoteVersion >= 110000)
                appendPQExpBufferStr(query,
-                                                        "aggfinalmodify,\n"
-                                                        "aggmfinalmodify,\n");
-       else
-               appendPQExpBufferStr(query,
-                                                        "'0' AS 
aggfinalmodify,\n"
-                                                        "'0' AS 
aggmfinalmodify,\n");
+                                                        "FROM 
pg_catalog.pg_aggregate a, pg_catalog.pg_proc p "
+                                                        "WHERE a.aggfnoid = 
p.oid "
+                                                        "AND p.oid = $1");
 
-       if (fout->remoteVersion >= 140000 && fout->version.type == Cloudberry 
&& fout->version.version >= 2)
-               appendPQExpBufferStr(query,
-                                                               
"aggrepsafeexec\n");
-       else
-               appendPQExpBufferStr(query,
-                                                                "false AS 
aggrepsafeexec\n");
+               ExecuteSqlStatement(fout, query->data);
 
-       appendPQExpBuffer(query,
-                                         "FROM pg_catalog.pg_aggregate a, 
pg_catalog.pg_proc p "
-                                         "WHERE a.aggfnoid = p.oid "
-                                         "AND p.oid = '%u'::pg_catalog.oid",
+               fout->is_prepared[PREPQUERY_DUMPAGG] = true;
+       }
+
+       printfPQExpBuffer(query,
+                                         "EXECUTE dumpAgg('%u')",
                                          agginfo->aggfn.dobj.catId.oid);
 
        res = ExecuteSqlQueryForSingleRow(fout, query->data);
@@ -17074,46 +17144,59 @@ dumpTable(Archive *fout, const TableInfo *tbinfo)
                PGresult   *res;
                int                     i;
 
-               if (fout->remoteVersion >= 90600)
-               {
-                       /*
-                        * In principle we should call acldefault('c', 
relowner) to get
-                        * the default ACL for a column.  However, we don't 
currently
-                        * store the numeric OID of the relowner in TableInfo.  
We could
-                        * convert the owner name using regrole, but that 
creates a risk
-                        * of failure due to concurrent role renames.  Given 
that the
-                        * default ACL for columns is empty and is likely to 
stay that
-                        * way, it's not worth extra cycles and risk to avoid 
hard-wiring
-                        * that knowledge here.
-                        */
-                       appendPQExpBuffer(query,
-                                                         "SELECT at.attname, "
-                                                         "at.attacl, "
-                                                         "'{}' AS acldefault, "
-                                                         "pip.privtype, 
pip.initprivs "
-                                                         "FROM 
pg_catalog.pg_attribute at "
-                                                         "LEFT JOIN 
pg_catalog.pg_init_privs pip ON "
-                                                         "(at.attrelid = 
pip.objoid "
-                                                         "AND pip.classoid = 
'pg_catalog.pg_class'::pg_catalog.regclass "
-                                                         "AND at.attnum = 
pip.objsubid) "
-                                                         "WHERE at.attrelid = 
'%u'::pg_catalog.oid AND "
-                                                         "NOT at.attisdropped "
-                                                         "AND (at.attacl IS 
NOT NULL OR pip.initprivs IS NOT NULL) "
-                                                         "ORDER BY at.attnum",
-                                                         
tbinfo->dobj.catId.oid);
-               }
-               else
+               if (!fout->is_prepared[PREPQUERY_GETCOLUMNACLS])
                {
-                       appendPQExpBuffer(query,
-                                                         "SELECT attname, 
attacl, '{}' AS acldefault, "
-                                                         "NULL AS privtype, 
NULL AS initprivs "
-                                                         "FROM 
pg_catalog.pg_attribute "
-                                                         "WHERE attrelid = 
'%u'::pg_catalog.oid AND NOT attisdropped "
-                                                         "AND attacl IS NOT 
NULL "
-                                                         "ORDER BY attnum",
-                                                         
tbinfo->dobj.catId.oid);
+                       /* Set up query for column ACLs */
+                       appendPQExpBufferStr(query,
+                                                                "PREPARE 
getColumnACLs(pg_catalog.oid) AS\n");
+
+                       if (fout->remoteVersion >= 90600)
+                       {
+                               /*
+                                * In principle we should call acldefault('c', 
relowner) to
+                                * get the default ACL for a column.  However, 
we don't
+                                * currently store the numeric OID of the 
relowner in
+                                * TableInfo.  We could convert the owner name 
using regrole,
+                                * but that creates a risk of failure due to 
concurrent role
+                                * renames.  Given that the default ACL for 
columns is empty
+                                * and is likely to stay that way, it's not 
worth extra cycles
+                                * and risk to avoid hard-wiring that knowledge 
here.
+                                */
+                               appendPQExpBufferStr(query,
+                                                                        
"SELECT at.attname, "
+                                                                        
"at.attacl, "
+                                                                        "'{}' 
AS acldefault, "
+                                                                        
"pip.privtype, pip.initprivs "
+                                                                        "FROM 
pg_catalog.pg_attribute at "
+                                                                        "LEFT 
JOIN pg_catalog.pg_init_privs pip ON "
+                                                                        
"(at.attrelid = pip.objoid "
+                                                                        "AND 
pip.classoid = 'pg_catalog.pg_class'::pg_catalog.regclass "
+                                                                        "AND 
at.attnum = pip.objsubid) "
+                                                                        "WHERE 
at.attrelid = $1 AND "
+                                                                        "NOT 
at.attisdropped "
+                                                                        "AND 
(at.attacl IS NOT NULL OR pip.initprivs IS NOT NULL) "
+                                                                        "ORDER 
BY at.attnum");
+                       }
+                       else
+                       {
+                               appendPQExpBufferStr(query,
+                                                                        
"SELECT attname, attacl, '{}' AS acldefault, "
+                                                                        "NULL 
AS privtype, NULL AS initprivs "
+                                                                        "FROM 
pg_catalog.pg_attribute "
+                                                                        "WHERE 
attrelid = $1 AND NOT attisdropped "
+                                                                        "AND 
attacl IS NOT NULL "
+                                                                        "ORDER 
BY attnum");
+                       }
+
+                       ExecuteSqlStatement(fout, query->data);
+
+                       fout->is_prepared[PREPQUERY_GETCOLUMNACLS] = true;
                }
 
+               printfPQExpBuffer(query,
+                                                 "EXECUTE getColumnACLs('%u')",
+                                                 tbinfo->dobj.catId.oid);
+
                res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
 
                for (i = 0; i < PQntuples(res); i++)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to