diff options
author | Noah Misch <noah@leadboat.com> | 2025-07-31 06:37:56 -0700 |
---|---|---|
committer | Noah Misch <noah@leadboat.com> | 2025-07-31 06:38:03 -0700 |
commit | 04bc2c42f765f16e1df4d1504b871d638d6b47e8 (patch) | |
tree | 99a22f6a0cfffcdf37a421e056ccf5dcd7e5432f /src/bin/pg_dump/common.c | |
parent | cc9a62c51a1894a9c838becf558abb056c904fb1 (diff) |
Sort dump objects independent of OIDs, for the 7 holdout object types.
pg_dump sorts objects by their logical names, e.g. (nspname, relname,
tgname), before dependency-driven reordering. That removes one source
of logically-identical databases differing in their schema-only dumps.
In other words, it helps with schema diffing. The logical name sort
ignored essential sort keys for constraints, operators, PUBLICATION
... FOR TABLE, PUBLICATION ... FOR TABLES IN SCHEMA, operator classes,
and operator families. pg_dump's sort then depended on object OID,
yielding spurious schema diffs. After this change, OIDs affect dump
order only in the event of catalog corruption. While pg_dump also
wrongly ignored pg_collation.collencoding, CREATE COLLATION restrictions
have been keeping that imperceptible in practical use.
Use techniques like we use for object types already having full sort key
coverage. Where the pertinent queries weren't fetching the ignored sort
keys, this adds columns to those queries and stores those keys in memory
for the long term.
The ignorance of sort keys became more problematic when commit
172259afb563d35001410dc6daad78b250924038 added a schema diff test
sensitive to it. Buildfarm member hippopotamus witnessed that.
However, dump order stability isn't a new goal, and this might avoid
other dump comparison failures. Hence, back-patch to v13 (all supported
versions).
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Discussion: https://postgr.es/m/20250707192654.9e.nmisch@google.com
Backpatch-through: 13
Diffstat (limited to 'src/bin/pg_dump/common.c')
-rw-r--r-- | src/bin/pg_dump/common.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c index c68b86bc766..59f00740bfb 100644 --- a/src/bin/pg_dump/common.c +++ b/src/bin/pg_dump/common.c @@ -17,6 +17,7 @@ #include <ctype.h> +#include "catalog/pg_am_d.h" #include "catalog/pg_class_d.h" #include "fe_utils/string_utils.h" #include "pg_backup_archiver.h" @@ -49,6 +50,7 @@ static DumpableObject **tblinfoindex; static DumpableObject **typinfoindex; static DumpableObject **funinfoindex; static DumpableObject **oprinfoindex; +static DumpableObject **aminfoindex; static DumpableObject **collinfoindex; static DumpableObject **nspinfoindex; static DumpableObject **extinfoindex; @@ -57,6 +59,7 @@ static int numTables; static int numTypes; static int numFuncs; static int numOperators; +static int numAccessMethods; static int numCollations; static int numNamespaces; static int numExtensions; @@ -92,6 +95,7 @@ getSchemaData(Archive *fout, int *numTablesPtr) TypeInfo *typinfo; FuncInfo *funinfo; OprInfo *oprinfo; + AccessMethodInfo *aminfo; CollInfo *collinfo; NamespaceInfo *nspinfo; ExtensionInfo *extinfo; @@ -103,7 +107,6 @@ getSchemaData(Archive *fout, int *numTablesPtr) int numProcLangs; int numCasts; int numTransforms; - int numAccessMethods; int numOpclasses; int numOpfamilies; int numConversions; @@ -166,7 +169,8 @@ getSchemaData(Archive *fout, int *numTablesPtr) oprinfoindex = buildIndexArray(oprinfo, numOperators, sizeof(OprInfo)); pg_log_info("reading user-defined access methods"); - getAccessMethods(fout, &numAccessMethods); + aminfo = getAccessMethods(fout, &numAccessMethods); + aminfoindex = buildIndexArray(aminfo, numAccessMethods, sizeof(AccessMethodInfo)); pg_log_info("reading user-defined operator classes"); getOpclasses(fout, &numOpclasses); @@ -891,6 +895,17 @@ findOprByOid(Oid oid) } /* + * findAccessMethodByOid + * finds the DumpableObject for the access method with the given oid + * returns NULL if not found + */ +AccessMethodInfo * +findAccessMethodByOid(Oid oid) +{ + return (AccessMethodInfo *) findObjectByOid(oid, aminfoindex, numAccessMethods); +} + +/* * findCollationByOid * finds the entry (in collinfo) of the collation with the given oid * returns NULL if not found |