Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc64e297

Browse files
committed
Fix pg_dump's handling of dependencies for custom opclasses.
Since pg_dump doesn't treat the member operators and functions of operatorclasses/families (that is, the pg_amop and pg_amproc entries, not theunderlying operators/functions) as separate dumpable objects, it missedtheir dependency information. I think this was safe when the code wasdesigned, because the default object sorting rule emits operators andfunctions before opclasses, and there were no dependency types that couldmess 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 rulesto push the opclass before the type and hence before custom operators.Lacking any information showing that it shouldn't do so, pg_dump emittedthe objects in the wrong order.Fix by teaching getDependencies() to translate pg_depend entries forpg_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
1 parenta6380f8 commitc64e297

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17875,14 +17875,45 @@ getDependencies(Archive *fout)
1787517875
query = createPQExpBuffer();
1787617876

1787717877
/*
17878+
* Messy query to collect the dependency data we need. Note that we
17879+
* ignore the sub-object column, so that dependencies of or on a column
17880+
* look the same as dependencies of or on a whole table.
17881+
*
1787817882
* PIN dependencies aren't interesting, and EXTENSION dependencies were
1787917883
* already processed by getExtensionMembership.
1788017884
*/
1788117885
appendPQExpBufferStr(query, "SELECT "
1788217886
"classid, objid, refclassid, refobjid, deptype "
1788317887
"FROM pg_depend "
17884-
"WHERE deptype != 'p' AND deptype != 'e' "
17885-
"ORDER BY 1,2");
17888+
"WHERE deptype != 'p' AND deptype != 'e'\n");
17889+
17890+
/*
17891+
* Since we don't treat pg_amop entries as separate DumpableObjects, we
17892+
* have to translate their dependencies into dependencies of their parent
17893+
* opfamily. Ignore internal dependencies though, as those will point to
17894+
* their parent opclass, which we needn't consider here (and if we did,
17895+
* it'd just result in circular dependencies). Also, "loose" opfamily
17896+
* entries will have dependencies on their parent opfamily, which we
17897+
* should drop since they'd likewise become useless self-dependencies.
17898+
* (But be sure to keep deps on *other* opfamilies; see amopsortfamily.)
17899+
*/
17900+
appendPQExpBufferStr(query, "UNION ALL\n"
17901+
"SELECT 'pg_opfamily'::regclass AS classid, amopfamily AS objid, refclassid, refobjid, deptype "
17902+
"FROM pg_depend d, pg_amop o "
17903+
"WHERE deptype NOT IN ('p', 'e', 'i') AND "
17904+
"classid = 'pg_amop'::regclass AND objid = o.oid "
17905+
"AND NOT (refclassid = 'pg_opfamily'::regclass AND amopfamily = refobjid)\n");
17906+
17907+
/* Likewise for pg_amproc entries */
17908+
appendPQExpBufferStr(query, "UNION ALL\n"
17909+
"SELECT 'pg_opfamily'::regclass AS classid, amprocfamily AS objid, refclassid, refobjid, deptype "
17910+
"FROM pg_depend d, pg_amproc p "
17911+
"WHERE deptype NOT IN ('p', 'e', 'i') AND "
17912+
"classid = 'pg_amproc'::regclass AND objid = p.oid "
17913+
"AND NOT (refclassid = 'pg_opfamily'::regclass AND amprocfamily = refobjid)\n");
17914+
17915+
/* Sort the output for efficiency below */
17916+
appendPQExpBufferStr(query, "ORDER BY 1,2");
1788617917

1788717918
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
1788817919

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp