mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
Fix pg_dump's handling of dependencies for custom opclasses.
Since pg_dump doesn't treat the member operators and functions of operator classes/families (that is, the pg_amop and pg_amproc entries, not the underlying operators/functions) as separate dumpable objects, it missed their dependency information. I think this was safe when the code was designed, because the default object sorting rule emits operators and functions before opclasses, and there were no dependency types that could mess that up. However, the introduction of range types in 9.2 broke it: now a type can have a dependency on an opclass, allowing dependency rules to push the opclass before the type and hence before custom operators. Lacking any information showing that it shouldn't do so, pg_dump emitted the objects in the wrong order. Fix by teaching getDependencies() to translate pg_depend entries for pg_amop/amproc rows to look like dependencies for their parent opfamily. I added a regression test for this in HEAD/v12, but not further back; life is too short to fight with 002_pg_dump.pl. Per bug #15934 from Tom Gottfried. Back-patch to all supported branches. Discussion: https://postgr.es/m/15934-58b8c8ab7a09ea15@postgresql.org
This commit is contained in:
parent
35fc44b58c
commit
7615afa48e
@ -17162,14 +17162,45 @@ getDependencies(Archive *fout)
|
|||||||
query = createPQExpBuffer();
|
query = createPQExpBuffer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Messy query to collect the dependency data we need. Note that we
|
||||||
|
* ignore the sub-object column, so that dependencies of or on a column
|
||||||
|
* look the same as dependencies of or on a whole table.
|
||||||
|
*
|
||||||
* PIN dependencies aren't interesting, and EXTENSION dependencies were
|
* PIN dependencies aren't interesting, and EXTENSION dependencies were
|
||||||
* already processed by getExtensionMembership.
|
* already processed by getExtensionMembership.
|
||||||
*/
|
*/
|
||||||
appendPQExpBufferStr(query, "SELECT "
|
appendPQExpBufferStr(query, "SELECT "
|
||||||
"classid, objid, refclassid, refobjid, deptype "
|
"classid, objid, refclassid, refobjid, deptype "
|
||||||
"FROM pg_depend "
|
"FROM pg_depend "
|
||||||
"WHERE deptype != 'p' AND deptype != 'e' "
|
"WHERE deptype != 'p' AND deptype != 'e'\n");
|
||||||
"ORDER BY 1,2");
|
|
||||||
|
/*
|
||||||
|
* Since we don't treat pg_amop entries as separate DumpableObjects, we
|
||||||
|
* have to translate their dependencies into dependencies of their parent
|
||||||
|
* opfamily. Ignore internal dependencies though, as those will point to
|
||||||
|
* their parent opclass, which we needn't consider here (and if we did,
|
||||||
|
* it'd just result in circular dependencies). Also, "loose" opfamily
|
||||||
|
* entries will have dependencies on their parent opfamily, which we
|
||||||
|
* should drop since they'd likewise become useless self-dependencies.
|
||||||
|
* (But be sure to keep deps on *other* opfamilies; see amopsortfamily.)
|
||||||
|
*/
|
||||||
|
appendPQExpBufferStr(query, "UNION ALL\n"
|
||||||
|
"SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
|
||||||
|
"FROM pg_depend d, pg_amop o "
|
||||||
|
"WHERE deptype NOT IN ('p', 'e', 'i') AND "
|
||||||
|
"classid = 'pg_amop'::regclass AND objid = o.oid "
|
||||||
|
"AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
|
||||||
|
|
||||||
|
/* Likewise for pg_amproc entries */
|
||||||
|
appendPQExpBufferStr(query, "UNION ALL\n"
|
||||||
|
"SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
|
||||||
|
"FROM pg_depend d, pg_amproc p "
|
||||||
|
"WHERE deptype NOT IN ('p', 'e', 'i') AND "
|
||||||
|
"classid = 'pg_amproc'::regclass AND objid = p.oid "
|
||||||
|
"AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
|
||||||
|
|
||||||
|
/* Sort the output for efficiency below */
|
||||||
|
appendPQExpBufferStr(query, "ORDER BY 1,2");
|
||||||
|
|
||||||
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
|
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user