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 ad69a307dd813275075035c998a95fb56cb62d56 Author: Tom Lane <[email protected]> AuthorDate: Tue Oct 19 17:22:22 2021 -0400 pg_dump: Reorganize getTables() Backported from PG15 4438eb4a49 Conflicts resolved by CBDB: * get foreignserver back * add islvm, isdynamic and amoid Conflicts resolved by GP7: * Include GPDB specific fields: relstorage, parrelid, parlevel * Excluded BM_BITMAPINDEX_NAMESPACE * Excluded upstream foreignserver field * Removed checks for version <= 80200 Original commit message follows: Along the same lines as 047329624, ed2c7f65b and daa9fe8a5, reduce code duplication by having just one copy of the parts of the query that are the same across all server versions; and make the conditionals control the smallest possible amount of code. This also gets rid of the confusing assortment of different ways to accomplish the same result that we had here before. While at it, make sure all three relevant parts of the function list the fields in the same order. This is just neatnik-ism, of course. Discussion: https://postgr.es/m/[email protected] --- src/bin/pg_dump/pg_dump.c | 871 ++++++++++++++++------------------------------ 1 file changed, 297 insertions(+), 574 deletions(-) diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index 7702d689d52..6926e9f4bdf 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -7310,7 +7310,6 @@ getTables(Archive *fout, int *numTables) int i_relname; int i_relnamespace; int i_relkind; - int i_relstorage; int i_relacl; int i_rrelacl; int i_initrelacl; @@ -7351,6 +7350,7 @@ getTables(Archive *fout, int *numTables) int i_amoid; int i_isivm; int i_isdynamic; + int i_relstorage; /* * Find all the tables and table-like objects. @@ -7370,53 +7370,155 @@ getTables(Archive *fout, int *numTables) * information about each table, basically just enough to decide if it is * interesting. We must fetch all tables in this phase because otherwise * we cannot correctly identify inherited columns, owned sequences, etc. - * - * We purposefully ignore toast OIDs for partitioned tables; the reason is - * that versions 10 and 11 have them, but 12 does not, so emitting them - * causes the upgrade to fail. */ + appendPQExpBuffer(query, + "SELECT c.tableoid, c.oid, c.relname, " + "c.relnamespace, c.relkind, " + "(%s c.relowner) AS rolname, " + "c.relchecks, " + "c.relhasindex, c.relhasrules, c.relpages, " + "d.refobjid AS owning_tab, " + "d.refobjsubid AS owning_col, " + "tsp.spcname AS reltablespace, " + "c.relfrozenxid, tc.relfrozenxid AS tfrozenxid, " + "tc.oid AS toid, ", + username_subquery); + if (fout->remoteVersion >= 90600) - { - char *partkeydef = "NULL"; - char *ispartition = "false"; - char *partbound = "NULL"; - char *relhasoids = "c.relhasoids"; + appendPQExpBufferStr(query, + "'' AS relstorage, "); + else + appendPQExpBufferStr(query, + "c.relstorage, "); + + if (fout->remoteVersion >= 120000) + appendPQExpBufferStr(query, + "false AS relhasoids, "); + else + appendPQExpBufferStr(query, + "c.relhasoids, "); + + if (fout->remoteVersion >= 80400) + appendPQExpBufferStr(query, + "c.relhastriggers, "); + else + appendPQExpBufferStr(query, + "(c.reltriggers <> 0) AS relhastriggers, "); + + if (fout->remoteVersion >= 90100) + appendPQExpBufferStr(query, + "c.relpersistence, "); + else + appendPQExpBufferStr(query, + "'p' AS relpersistence, "); + if (fout->remoteVersion >= 90300) + appendPQExpBufferStr(query, + "c.relispopulated, "); + else + appendPQExpBufferStr(query, + "'t' as relispopulated, "); + + if (fout->remoteVersion >= 90400) + appendPQExpBufferStr(query, + "c.relreplident, "); + else + appendPQExpBufferStr(query, + "'d' AS relreplident, "); + + if (fout->remoteVersion >= 90500) + appendPQExpBufferStr(query, + "c.relrowsecurity, c.relforcerowsecurity, "); + else + appendPQExpBufferStr(query, + "false AS relrowsecurity, " + "false AS relforcerowsecurity, "); + + if (fout->remoteVersion >= 90300) + appendPQExpBufferStr(query, + "c.relminmxid, tc.relminmxid AS tminmxid, "); + else + appendPQExpBufferStr(query, + "0 AS relminmxid, 0 AS tminmxid, "); + + if (fout->remoteVersion >= 90300) + appendPQExpBufferStr(query, + "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " + "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " + "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, "); + else + appendPQExpBufferStr(query, + "c.reloptions, NULL AS checkoption, "); + + if (fout->remoteVersion >= 80400) + appendPQExpBufferStr(query, + "tc.reloptions AS toast_reloptions, "); + else + appendPQExpBufferStr(query, + "NULL AS toast_reloptions, "); + + if (fout->remoteVersion >= 90000) + appendPQExpBufferStr(query, + "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, "); + else + appendPQExpBufferStr(query, + "NULL AS reloftype, "); + + if (fout->remoteVersion >= 90600) + appendPQExpBufferStr(query, + "am.amname, am.oid as amoid, "); + else + appendPQExpBufferStr(query, + "NULL AS amname, NULL as amoid, "); + + if (fout->remoteVersion >= 90600) + appendPQExpBufferStr(query, + "c.relkind = " CppAsString2(RELKIND_SEQUENCE) + "AND EXISTS (SELECT 1 FROM pg_depend " + "WHERE classid = 'pg_class'::regclass AND " + "objid = c.oid AND objsubid = 0 AND " + "refclassid = 'pg_class'::regclass AND " + "deptype = 'i') AS is_identity_sequence, "); + else + appendPQExpBufferStr(query, + "false AS is_identity_sequence, "); + + if (fout->remoteVersion >= 90600) + appendPQExpBufferStr(query, + "0 as parrelid, " + "0 as parlevel, "); + else + appendPQExpBufferStr(query, + "p.parrelid as parrelid, " + "pl.parlevel as parlevel, "); + + if (fout->remoteVersion >= 90100) + appendPQExpBufferStr(query, + "CASE WHEN c.relkind = 'f' THEN " + "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " + "ELSE 0 END AS foreignserver, "); + else + appendPQExpBufferStr(query, + "NULL AS foreignserver, "); + + if (fout->remoteVersion >= 90600) + appendPQExpBuffer(query, + "c.relisivm AS isivm, %s, ", + (fout->version.type == Cloudberry && fout->version.version >= 2) ? "c.relisdynamic AS isdynamic " : "false AS isdynamic "); + + + if (fout->remoteVersion >= 90600) + { PQExpBuffer acl_subquery = createPQExpBuffer(); PQExpBuffer racl_subquery = createPQExpBuffer(); PQExpBuffer initacl_subquery = createPQExpBuffer(); PQExpBuffer initracl_subquery = createPQExpBuffer(); - PQExpBuffer attacl_subquery = createPQExpBuffer(); PQExpBuffer attracl_subquery = createPQExpBuffer(); PQExpBuffer attinitacl_subquery = createPQExpBuffer(); PQExpBuffer attinitracl_subquery = createPQExpBuffer(); - /* - * Collect the information about any partitioned tables, which were - * added in PG10. - */ - - if (fout->remoteVersion >= 100000) - { - partkeydef = "pg_get_partkeydef(c.oid)"; - ispartition = "c.relispartition"; - partbound = "pg_get_expr(c.relpartbound, c.oid)"; - } - - /* In PG12 upwards WITH OIDS does not exist anymore. */ - if (fout->remoteVersion >= 120000) - relhasoids = "'f'::bool"; - - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - * - * Left join to detect if any privileges are still as-set-at-init, in - * which case we won't dump out ACL commands for those. - */ - buildACLQueries(acl_subquery, racl_subquery, initacl_subquery, initracl_subquery, "c.relacl", "c.relowner", "CASE WHEN c.relkind = " CppAsString2(RELKIND_SEQUENCE) @@ -7424,39 +7526,18 @@ getTables(Archive *fout, int *numTables) dopt->binary_upgrade); buildACLQueries(attacl_subquery, attracl_subquery, attinitacl_subquery, - attinitracl_subquery, "at.attacl", "c.relowner", "'c'", + attinitracl_subquery, "at.attacl", "c.relowner","'c'", dopt->binary_upgrade); appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "'' AS relstorage, " "%s AS relacl, %s as rrelacl, " - "%s AS initrelacl, %s as initrrelacl, " - "c.relkind, c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, %s AS relhasoids, " - "c.relrowsecurity, c.relforcerowsecurity, " - "c.relfrozenxid, c.relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "tc.relminmxid AS tminmxid, " - "c.relpersistence, c.relispopulated, " - "c.relreplident, c.relpages, am.amname, " - "am.oid AS amoid, " - "CASE WHEN c.relkind = 'f' THEN " - "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " - "ELSE 0 END AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, " - "tc.reloptions AS toast_reloptions, " - "0 as parrelid, " - "0 as parlevel, " - "c.relkind = '%c' AND EXISTS (SELECT 1 FROM pg_depend WHERE classid = 'pg_class'::regclass AND objid = c.oid AND objsubid = 0 AND refclassid = 'pg_class'::regclass AND deptype = 'i') AS is_identity_sequence, " + "%s AS initrelacl, %s as initrrelacl, ", + acl_subquery->data, + racl_subquery->data, + initacl_subquery->data, + initracl_subquery->data); + + appendPQExpBuffer(query, "EXISTS (SELECT 1 FROM pg_attribute at LEFT JOIN pg_init_privs pip ON " "(c.oid = pip.objoid " "AND pip.classoid = 'pg_class'::regclass " @@ -7467,472 +7548,110 @@ getTables(Archive *fout, int *numTables) "OR %s IS NOT NULL " "OR %s IS NOT NULL" "))" - "AS changed_acl, " - "%s AS partkeydef, " - "%s AS ispartition, " - "%s AS partbound, " - "c.relisivm AS isivm, " - "%s" - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype IN ('a', 'i')) " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid AND c.relkind <> '%c') " - "LEFT JOIN pg_am am ON (c.relam = am.oid) " - "LEFT JOIN pg_init_privs pip ON " - "(c.oid = pip.objoid " - "AND pip.classoid = 'pg_class'::regclass " - "AND pip.objsubid = 0) " - "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "ORDER BY c.oid", - acl_subquery->data, - racl_subquery->data, - initacl_subquery->data, - initracl_subquery->data, - username_subquery, - relhasoids, - RELKIND_SEQUENCE, + "AS changed_acl, ", attacl_subquery->data, attracl_subquery->data, attinitacl_subquery->data, - attinitracl_subquery->data, - partkeydef, - ispartition, - partbound, - (fout->version.type == Cloudberry && fout->version.version >= 2) ? "c.relisdynamic AS isdynamic " : "false AS isdynamic ", - RELKIND_SEQUENCE, - RELKIND_PARTITIONED_TABLE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE, - RELKIND_PARTITIONED_TABLE); + attinitracl_subquery->data); destroyPQExpBuffer(acl_subquery); destroyPQExpBuffer(racl_subquery); destroyPQExpBuffer(initacl_subquery); destroyPQExpBuffer(initracl_subquery); - destroyPQExpBuffer(attacl_subquery); destroyPQExpBuffer(attracl_subquery); destroyPQExpBuffer(attinitacl_subquery); destroyPQExpBuffer(attinitracl_subquery); } - else if (fout->remoteVersion >= 90500) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "c.relrowsecurity, c.relforcerowsecurity, " - "c.relfrozenxid, c.relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "tc.relminmxid AS tminmxid, " - "c.relpersistence, c.relispopulated, " - "c.relreplident, c.relpages, " - "NULL AS amname, " - "CASE WHEN c.relkind = 'f' THEN " - "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " - "ELSE 0 END AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); - } - else if (fout->remoteVersion >= 90400) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relstorage, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, c.relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "tc.relminmxid AS tminmxid, " - "c.relpersistence, c.relispopulated, " - "c.relreplident, c.relpages, " - "NULL AS amname, " - "CASE WHEN c.relkind = 'f' THEN " - "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " - "ELSE 0 END AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid AND c.relstorage <> 'c') " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); - } - else if (fout->remoteVersion >= 90300) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, c.relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "tc.relminmxid AS tminmxid, " - "c.relpersistence, c.relispopulated, " - "'d' AS relreplident, c.relpages, " - "NULL AS amname, " - "CASE WHEN c.relkind = 'f' THEN " - "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " - "ELSE 0 END AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "array_remove(array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " - "CASE WHEN 'check_option=local' = ANY (c.reloptions) THEN 'LOCAL'::text " - "WHEN 'check_option=cascaded' = ANY (c.reloptions) THEN 'CASCADED'::text ELSE NULL END AS checkoption, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); - } - else if (fout->remoteVersion >= 90100) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relstorage, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "0 AS tminmxid, " - "c.relpersistence, 't' as relispopulated, " - "'d' AS relreplident, c.relpages, " - "NULL AS amname, " - "CASE WHEN c.relkind = 'f' THEN " - "(SELECT ftserver FROM pg_catalog.pg_foreign_table WHERE ftrelid = c.oid) " - "ELSE 0 END AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "c.reloptions AS reloptions, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE, - RELKIND_MATVIEW, RELKIND_FOREIGN_TABLE); - } - else if (fout->remoteVersion >= 90000) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relstorage, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "0 AS tminmxid, " - "'p' AS relpersistence, 't' as relispopulated, " - "'d' AS relreplident, c.relpages, " - "NULL AS amname, " - "NULL AS foreignserver, " - "CASE WHEN c.reloftype <> 0 THEN c.reloftype::pg_catalog.regtype ELSE NULL END AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "c.reloptions AS reloptions, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); - } - else if (fout->remoteVersion >= 80400) - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relacl, NULL as rrelacl, " - "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, c.relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "0 AS tminmxid, " - "'p' AS relpersistence, 't' as relispopulated, " - "'d' AS relreplident, c.relpages, " - "NULL AS amname, " - "NULL AS foreignserver, " - "NULL AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "c.reloptions AS reloptions, " - "tc.reloptions AS toast_reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS changed_acl, " - "NULL AS partkeydef, " - "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " - "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " - "d.classid = c.tableoid AND d.objid = c.oid AND " - "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)" - "WHERE c.relkind in ('%c', '%c', '%c', '%c') " - "AND c.relnamespace <> 7012 " /* BM_BITMAPINDEX_NAMESPACE */ - "AND c.oid NOT IN (SELECT p.parchildrelid FROM pg_partition_rule p LEFT " - "JOIN pg_exttable e ON p.parchildrelid=e.reloid WHERE e.reloid IS NULL)" - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); - } else - { - /* - * Left join to pick up dependency info linking sequences to their - * owning column, if any (note this dependency is AUTO as of 8.2) - */ - appendPQExpBuffer(query, - "SELECT c.tableoid, c.oid, c.relname, " - "c.relstorage, " + appendPQExpBufferStr(query, "c.relacl, NULL as rrelacl, " "NULL AS initrelacl, NULL AS initrrelacl, " - "c.relkind, " - "c.relnamespace, " - "(%s c.relowner) AS rolname, " - "c.relchecks, (c.reltriggers <> 0) AS relhastriggers, " - "c.relhasindex, c.relhasrules, c.relhasoids, " - "'f'::bool AS relrowsecurity, " - "'f'::bool AS relforcerowsecurity, " - "c.relfrozenxid, 0 AS relminmxid, tc.oid AS toid, " - "tc.relfrozenxid AS tfrozenxid, " - "0 AS tminmxid, " - "'p' AS relpersistence, 't' as relispopulated, " - "'d' AS relreplident, c.relpages, " - "NULL AS amname, " - "NULL AS foreignserver, " - "NULL AS reloftype, " - "d.refobjid AS owning_tab, " - "d.refobjsubid AS owning_col, " - "(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, " - "c.reloptions AS reloptions, " - "p.parrelid as parrelid, " - "pl.parlevel as parlevel, " - "NULL AS toast_reloptions, " - "NULL AS changed_acl, " + "false AS changed_acl, "); + + if (fout->remoteVersion >= 100000) + appendPQExpBufferStr(query, + "pg_get_partkeydef(c.oid) AS partkeydef, " + "c.relispartition AS ispartition, " + "pg_get_expr(c.relpartbound, c.oid) AS partbound "); + else + appendPQExpBufferStr(query, "NULL AS partkeydef, " "false AS ispartition, " - "NULL AS partbound " - "FROM pg_class c " + "NULL AS partbound "); + + /* + * Left join to pg_depend to pick up dependency info linking sequences to + * their owning column, if any (note this dependency is AUTO as of 8.2). + * Also join to pg_tablespace to collect the spcname. + */ + appendPQExpBufferStr(query, + "\nFROM pg_class c\n" "LEFT JOIN pg_depend d ON " - "(c.relkind = '%c' AND " + "(c.relkind = " CppAsString2(RELKIND_SEQUENCE) " AND " "d.classid = c.tableoid AND d.objid = c.oid AND " "d.objsubid = 0 AND " - "d.refclassid = c.tableoid AND d.deptype = 'a') " - "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid) " - "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid " - "LEFT JOIN pg_partition p ON pr.paroid = p.oid " - "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0) " - "WHERE c.relkind in ('%c', '%c', '%c', '%c') " - "AND c.oid NOT IN (select p.parchildrelid from pg_partition_rule p " - "LEFT JOIN pg_exttable e on p.parchildrelid=e.reloid where e.reloid is null) " - "AND c.relnamespace <> 3012 " /* BM_BITMAPINDEX_NAMESPACE in GPDB 5 and below */ - "ORDER BY c.oid", - username_subquery, - RELKIND_SEQUENCE, - RELKIND_RELATION, RELKIND_SEQUENCE, - RELKIND_VIEW, RELKIND_COMPOSITE_TYPE); - } + "d.refclassid = c.tableoid AND d.deptype IN ('a', 'i'))\n" + "LEFT JOIN pg_tablespace tsp ON (tsp.oid = c.reltablespace)\n"); + + /* + * In 9.6 and up, left join to pg_init_privs to detect if any privileges + * are still as-set-at-init, in which case we won't dump out ACL commands + * for those. We also are interested in the amname as of 9.6. + * + * We purposefully ignore toast OIDs for partitioned tables; the reason is + * that versions 10 and 11 have them, but later versions do not, so + * emitting them causes the upgrade to fail. + */ + + appendPQExpBufferStr(query, + "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid" + " AND tc.relkind = " CppAsString2(RELKIND_TOASTVALUE) + " AND c.relkind <> " CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"); + + if (fout->remoteVersion <= 90426) // GPDB 6 or below + appendPQExpBufferStr(query, + "LEFT JOIN pg_class tc ON (c.reltoastrelid = tc.oid)\n" + "LEFT JOIN pg_partition_rule pr ON c.oid = pr.parchildrelid\n" + "LEFT JOIN pg_partition p ON pr.paroid = p.oid\n" + "LEFT JOIN pg_partition pl ON (c.oid = pl.parrelid AND pl.parlevel = 0)\n"); + + /* + * Restrict to interesting relkinds (in particular, not indexes). Not all + * relkinds are possible in older servers, but it's not worth the trouble + * to emit a version-dependent list. + * + * Composite-type table entries won't be dumped as such, but we have to + * make a DumpableObject for them so that we can track dependencies of the + * composite type (pg_depend entries for columns of the composite type + * link to the pg_class entry not the pg_type entry). + */ + appendPQExpBufferStr(query, + "WHERE c.relkind IN (" + CppAsString2(RELKIND_RELATION) ", " + CppAsString2(RELKIND_SEQUENCE) ", " + CppAsString2(RELKIND_VIEW) ", " + CppAsString2(RELKIND_COMPOSITE_TYPE) ", " + CppAsString2(RELKIND_MATVIEW) ", " + CppAsString2(RELKIND_FOREIGN_TABLE) ", " + CppAsString2(RELKIND_PARTITIONED_TABLE) ")\n"); + + + if (fout->remoteVersion >= 80400) + appendPQExpBufferStr(query, + "AND c.relnamespace <> 7012\n"); /* BM_BITMAPINDEX_NAMESPACE */ + else + appendPQExpBufferStr(query, + "AND c.relnamespace <> 3012\n"); /* BM_BITMAPINDEX_NAMESPACE in GPDB 5 and below */ + + if (fout->remoteVersion >= 90600) + appendPQExpBufferStr(query, + "ORDER BY c.oid"); + else + appendPQExpBufferStr(query, + "AND c.oid NOT IN (select p.parchildrelid from pg_partition_rule p\n" + "LEFT JOIN pg_exttable e on p.parchildrelid=e.reloid where e.reloid is null)\n" + "ORDER BY c.oid"); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); @@ -7955,48 +7674,48 @@ getTables(Archive *fout, int *numTables) i_reloid = PQfnumber(res, "oid"); i_relname = PQfnumber(res, "relname"); i_relnamespace = PQfnumber(res, "relnamespace"); - i_relacl = PQfnumber(res, "relacl"); - i_rrelacl = PQfnumber(res, "rrelacl"); - i_initrelacl = PQfnumber(res, "initrelacl"); - i_initrrelacl = PQfnumber(res, "initrrelacl"); i_relkind = PQfnumber(res, "relkind"); - i_relstorage = PQfnumber(res, "relstorage"); i_rolname = PQfnumber(res, "rolname"); i_relchecks = PQfnumber(res, "relchecks"); - i_relhastriggers = PQfnumber(res, "relhastriggers"); i_relhasindex = PQfnumber(res, "relhasindex"); i_relhasrules = PQfnumber(res, "relhasrules"); - i_relrowsec = PQfnumber(res, "relrowsecurity"); - i_relforcerowsec = PQfnumber(res, "relforcerowsecurity"); - i_relhasoids = PQfnumber(res, "relhasoids"); - i_relfrozenxid = PQfnumber(res, "relfrozenxid"); - i_relminmxid = PQfnumber(res, "relminmxid"); - i_toastoid = PQfnumber(res, "toid"); - i_toastfrozenxid = PQfnumber(res, "tfrozenxid"); - i_toastminmxid = PQfnumber(res, "tminmxid"); - i_relpersistence = PQfnumber(res, "relpersistence"); - i_relispopulated = PQfnumber(res, "relispopulated"); - i_relreplident = PQfnumber(res, "relreplident"); i_relpages = PQfnumber(res, "relpages"); i_foreignserver = PQfnumber(res, "foreignserver"); i_owning_tab = PQfnumber(res, "owning_tab"); i_owning_col = PQfnumber(res, "owning_col"); i_reltablespace = PQfnumber(res, "reltablespace"); + i_relhasoids = PQfnumber(res, "relhasoids"); + i_relhastriggers = PQfnumber(res, "relhastriggers"); + i_relpersistence = PQfnumber(res, "relpersistence"); + i_relispopulated = PQfnumber(res, "relispopulated"); + i_relreplident = PQfnumber(res, "relreplident"); + i_relrowsec = PQfnumber(res, "relrowsecurity"); + i_relforcerowsec = PQfnumber(res, "relforcerowsecurity"); + i_relfrozenxid = PQfnumber(res, "relfrozenxid"); + i_toastfrozenxid = PQfnumber(res, "tfrozenxid"); + i_toastoid = PQfnumber(res, "toid"); + i_relminmxid = PQfnumber(res, "relminmxid"); + i_toastminmxid = PQfnumber(res, "tminmxid"); i_reloptions = PQfnumber(res, "reloptions"); i_checkoption = PQfnumber(res, "checkoption"); i_toastreloptions = PQfnumber(res, "toast_reloptions"); i_reloftype = PQfnumber(res, "reloftype"); - i_parrelid = PQfnumber(res, "parrelid"); - i_parlevel = PQfnumber(res, "parlevel"); + i_amname = PQfnumber(res, "amname"); i_is_identity_sequence = PQfnumber(res, "is_identity_sequence"); + i_relacl = PQfnumber(res, "relacl"); + i_rrelacl = PQfnumber(res, "rrelacl"); + i_initrelacl = PQfnumber(res, "initrelacl"); + i_initrrelacl = PQfnumber(res, "initrrelacl"); i_changed_acl = PQfnumber(res, "changed_acl"); i_partkeydef = PQfnumber(res, "partkeydef"); i_ispartition = PQfnumber(res, "ispartition"); i_partbound = PQfnumber(res, "partbound"); - i_amname = PQfnumber(res, "amname"); i_amoid = PQfnumber(res, "amoid"); i_isivm = PQfnumber(res, "isivm"); i_isdynamic = PQfnumber(res, "isdynamic"); + i_relstorage = PQfnumber(res, "relstorage"); + i_parrelid = PQfnumber(res, "parrelid"); + i_parlevel = PQfnumber(res, "parlevel"); if (dopt->lockWaitTimeout) { @@ -8024,33 +7743,12 @@ getTables(Archive *fout, int *numTables) tblinfo[i].dobj.name = pg_strdup(PQgetvalue(res, i, i_relname)); tblinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_relnamespace))); - tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); - tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl)); - tblinfo[i].rrelacl = pg_strdup(PQgetvalue(res, i, i_rrelacl)); - tblinfo[i].initrelacl = pg_strdup(PQgetvalue(res, i, i_initrelacl)); - tblinfo[i].initrrelacl = pg_strdup(PQgetvalue(res, i, i_initrrelacl)); tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind)); - tblinfo[i].relstorage = *(PQgetvalue(res, i, i_relstorage)); - tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence)); + tblinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); + tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks)); tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0); tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0); - tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0); - tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0); - tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0); - tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0); - tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0); - tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident)); tblinfo[i].relpages = atoi(PQgetvalue(res, i, i_relpages)); - tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid)); - tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid)); - tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid)); - tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid)); - tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid)); - if (PQgetisnull(res, i, i_reloftype)) - tblinfo[i].reloftype = NULL; - else - tblinfo[i].reloftype = pg_strdup(PQgetvalue(res, i, i_reloftype)); - tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks)); if (PQgetisnull(res, i, i_owning_tab)) { tblinfo[i].owning_tab = InvalidOid; @@ -8062,13 +7760,42 @@ getTables(Archive *fout, int *numTables) tblinfo[i].owning_col = atoi(PQgetvalue(res, i, i_owning_col)); } tblinfo[i].reltablespace = pg_strdup(PQgetvalue(res, i, i_reltablespace)); + tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0); + tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0); + tblinfo[i].relpersistence = *(PQgetvalue(res, i, i_relpersistence)); + tblinfo[i].relispopulated = (strcmp(PQgetvalue(res, i, i_relispopulated), "t") == 0); + tblinfo[i].relreplident = *(PQgetvalue(res, i, i_relreplident)); + tblinfo[i].rowsec = (strcmp(PQgetvalue(res, i, i_relrowsec), "t") == 0); + tblinfo[i].forcerowsec = (strcmp(PQgetvalue(res, i, i_relforcerowsec), "t") == 0); + tblinfo[i].frozenxid = atooid(PQgetvalue(res, i, i_relfrozenxid)); + tblinfo[i].toast_frozenxid = atooid(PQgetvalue(res, i, i_toastfrozenxid)); + tblinfo[i].toast_oid = atooid(PQgetvalue(res, i, i_toastoid)); + tblinfo[i].minmxid = atooid(PQgetvalue(res, i, i_relminmxid)); + tblinfo[i].toast_minmxid = atooid(PQgetvalue(res, i, i_toastminmxid)); tblinfo[i].reloptions = pg_strdup(PQgetvalue(res, i, i_reloptions)); - if (i_checkoption == -1 || PQgetisnull(res, i, i_checkoption)) + if (PQgetisnull(res, i, i_checkoption)) tblinfo[i].checkoption = NULL; else tblinfo[i].checkoption = pg_strdup(PQgetvalue(res, i, i_checkoption)); tblinfo[i].toast_reloptions = pg_strdup(PQgetvalue(res, i, i_toastreloptions)); - tblinfo[i].parrelid = atooid(PQgetvalue(res, i, i_parrelid)); + if (PQgetisnull(res, i, i_reloftype)) + tblinfo[i].reloftype = NULL; + else + tblinfo[i].reloftype = pg_strdup(PQgetvalue(res, i, i_reloftype)); + if (PQgetisnull(res, i, i_amname)) + tblinfo[i].amname = NULL; + else + tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname)); + tblinfo[i].is_identity_sequence = (strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0); + tblinfo[i].relacl = pg_strdup(PQgetvalue(res, i, i_relacl)); + tblinfo[i].rrelacl = pg_strdup(PQgetvalue(res, i, i_rrelacl)); + tblinfo[i].initrelacl = pg_strdup(PQgetvalue(res, i, i_initrelacl)); + tblinfo[i].initrrelacl = pg_strdup(PQgetvalue(res, i, i_initrrelacl)); + tblinfo[i].partkeydef = pg_strdup(PQgetvalue(res, i, i_partkeydef)); + tblinfo[i].ispartition = (strcmp(PQgetvalue(res, i, i_ispartition), "t") == 0); + tblinfo[i].partbound = pg_strdup(PQgetvalue(res, i, i_partbound)); + + tblinfo[i].relstorage = *(PQgetvalue(res, i, i_relstorage)); if (tblinfo[i].parrelid != 0) { /* @@ -8084,10 +7811,6 @@ getTables(Archive *fout, int *numTables) tblinfo[i].parparent = false; else tblinfo[i].parparent = true; - if (PQgetisnull(res, i, i_amname)) - tblinfo[i].amname = NULL; - else - tblinfo[i].amname = pg_strdup(PQgetvalue(res, i, i_amname)); if (PQgetisnull(res, i, i_amoid)) tblinfo[i].amoid = InvalidOid; @@ -8104,25 +7827,10 @@ getTables(Archive *fout, int *numTables) else selectDumpableTable(&tblinfo[i], fout); - /* - * If the table-level and all column-level ACLs for this table are - * unchanged, then we don't need to worry about including the ACLs for - * this table. If any column-level ACLs have been changed, the - * 'changed_acl' column from the query will indicate that. - * - * This can result in a significant performance improvement in cases - * where we are only looking to dump out the ACL (eg: pg_catalog). - */ - if (PQgetisnull(res, i, i_relacl) && PQgetisnull(res, i, i_rrelacl) && - PQgetisnull(res, i, i_initrelacl) && - PQgetisnull(res, i, i_initrrelacl) && - strcmp(PQgetvalue(res, i, i_changed_acl), "f") == 0) - tblinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL; - tblinfo[i].interesting = tblinfo[i].dobj.dump ? true : false; tblinfo[i].dummy_view = false; /* might get set during sort */ tblinfo[i].postponed_def = false; /* might get set during sort */ - + tblinfo[i].is_identity_sequence = (i_is_identity_sequence >= 0 && strcmp(PQgetvalue(res, i, i_is_identity_sequence), "t") == 0); @@ -8136,6 +7844,21 @@ getTables(Archive *fout, int *numTables) /* foreign server */ tblinfo[i].foreign_server = atooid(PQgetvalue(res, i, i_foreignserver)); + /* + * If the table-level and all column-level ACLs for this table are + * unchanged, then we don't need to worry about including the ACLs for + * this table. If any column-level ACLs have been changed, the + * 'changed_acl' column from the query will indicate that. + * + * This can result in a significant performance improvement in cases + * where we are only looking to dump out the ACL (eg: pg_catalog). + */ + if (PQgetisnull(res, i, i_relacl) && PQgetisnull(res, i, i_rrelacl) && + PQgetisnull(res, i, i_initrelacl) && + PQgetisnull(res, i, i_initrrelacl) && + strcmp(PQgetvalue(res, i, i_changed_acl), "f") == 0) + tblinfo[i].dobj.dump &= ~DUMP_COMPONENT_ACL; + /* * Read-lock target tables to make sure they aren't DROPPED or altered * in schema before we get around to dumping them. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
