ZTE-EBASE commented on code in PR #1176:
URL: https://github.com/apache/cloudberry/pull/1176#discussion_r2253031450
##########
src/bin/pg_dump/pg_dump.c:
##########
@@ -8260,6 +8299,76 @@ getInherits(Archive *fout, int *numInherits)
return inhinfo;
}
+/*
+ * getPartitioningInfo
+ * get information about partitioning
+ *
+ * For the most part, we only collect partitioning info about tables we
+ * intend to dump. However, this function has to consider all partitioned
+ * tables in the database, because we need to know about parents of partitions
+ * we are going to dump even if the parents themselves won't be dumped.
+ *
+ * Specifically, what we need to know is whether each partitioned table
+ * has an "unsafe" partitioning scheme that requires us to force
+ * load-via-partition-root mode for its children. Currently the only case
+ * for which we force that is hash partitioning on enum columns, since the
+ * hash codes depend on enum value OIDs which won't be replicated across
+ * dump-and-reload. There are other cases in which load-via-partition-root
+ * might be necessary, but we expect users to cope with them.
+ */
+void
+getPartitioningInfo(Archive *fout)
+{
+ PQExpBuffer query;
+ PGresult *res;
+ int ntups;
+
+ /* hash partitioning didn't exist before v11 */
+ if (fout->remoteVersion < 110000)
+ return;
+ /* needn't bother if schema-only dump */
+ if (fout->dopt->schemaOnly)
+ return;
+
+ query = createPQExpBuffer();
+
+ /*
+ * Unsafe partitioning schemes are exactly those for which hash enum_ops
+ * appears among the partition opclasses. We needn't check partstrat.
+ *
+ * Note that this query may well retrieve info about tables we aren't
+ * going to dump and hence have no lock on. That's okay since we need
not
+ * invoke any unsafe server-side functions.
+ */
+ appendPQExpBufferStr(query,
+ "SELECT partrelid FROM
pg_partitioned_table WHERE\n"
+ "(SELECT c.oid FROM pg_opclass
c JOIN pg_am a "
+ "ON c.opcmethod = a.oid\n"
+ "WHERE opcname = 'enum_ops' "
+ "AND opcnamespace =
'pg_catalog'::regnamespace "
+ "AND amname = 'hash') =
ANY(partclass)");
+
+ res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
+
+ ntups = PQntuples(res);
+
+ for (int i = 0; i < ntups; i++)
+ {
+ Oid tabrelid = atooid(PQgetvalue(res, i,
0));
+ TableInfo *tbinfo;
+
+ tbinfo = findTableByOid(tabrelid);
+ if (tbinfo == NULL)
+ fatal("failed sanity check, table OID %u appearing in
pg_partitioned_table not found",
Review Comment:
In the Cloudberry codebase, there are numerous instances where fatal is
used. Similarly, in pg_dump, fatal is almost exclusively used instead of
pg_fatal. Here, in order to avoid introducing unnecessary header files, we
adopt the latest consistent approach by using fatal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]