Skip to content

Commit f39bb48

Browse files
committed
Fix incorrect logic for excluding range constructor functions in pg_dump.
Faulty AND/OR nesting in the WHERE clause of getFuncs' SQL query led to dumping range constructor functions if they are part of an extension and we're in binary-upgrade mode. Actually, we don't want to dump them separately even then, since CREATE TYPE AS RANGE will create the range's constructor functions regardless. Per report from Andrew Dunstan. It looks like this mistake was introduced by me, in commit b985d48, in perhaps-overzealous refactoring to reduce code duplication. I'm suitably embarrassed. Report: <34854939-02d7-f591-5677-ce2994104599@dunslane.net>
1 parent 73df86a commit f39bb48

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4179,19 +4179,22 @@ getFuncs(Archive *fout, int *numFuncs)
41794179
selectSourceSchema(fout, "pg_catalog");
41804180

41814181
/*
4182-
* Find all user-defined functions. Normally we can exclude functions in
4183-
* pg_catalog, which is worth doing since there are several thousand of
4184-
* 'em. However, there are some extensions that create functions in
4185-
* pg_catalog. In normal dumps we can still ignore those --- but in
4186-
* binary-upgrade mode, we must dump the member objects of the extension,
4187-
* so be sure to fetch any such functions.
4182+
* Find all interesting functions. This is a bit complicated:
41884183
*
4189-
* Also, in 9.2 and up, exclude functions that are internally dependent on
4190-
* something else, since presumably those will be created as a result of
4191-
* creating the something else. This currently only acts to suppress
4192-
* constructor functions for range types. Note that this is OK only
4193-
* because the constructors don't have any dependencies the range type
4194-
* doesn't have; otherwise we might not get creation ordering correct.
4184+
* 1. Always exclude aggregates; those are handled elsewhere.
4185+
*
4186+
* 2. Always exclude functions that are internally dependent on something
4187+
* else, since presumably those will be created as a result of creating
4188+
* the something else. This currently acts only to suppress constructor
4189+
* functions for range types (so we only need it in 9.2 and up). Note
4190+
* this is OK only because the constructors don't have any dependencies
4191+
* the range type doesn't have; otherwise we might not get creation
4192+
* ordering correct.
4193+
*
4194+
* 3. Otherwise, we normally exclude functions in pg_catalog. However, if
4195+
* they're members of extensions and we are in binary-upgrade mode then
4196+
* include them, since we want to dump extension members individually in
4197+
* that mode.
41954198
*/
41964199

41974200
if (fout->remoteVersion >= 70300)
@@ -4202,16 +4205,18 @@ getFuncs(Archive *fout, int *numFuncs)
42024205
"pronamespace, "
42034206
"(%s proowner) AS rolname "
42044207
"FROM pg_proc p "
4205-
"WHERE NOT proisagg AND ("
4206-
"pronamespace != "
4207-
"(SELECT oid FROM pg_namespace "
4208-
"WHERE nspname = 'pg_catalog')",
4208+
"WHERE NOT proisagg",
42094209
username_subquery);
42104210
if (fout->remoteVersion >= 90200)
42114211
appendPQExpBuffer(query,
42124212
"\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
42134213
"WHERE classid = 'pg_proc'::regclass AND "
42144214
"objid = p.oid AND deptype = 'i')");
4215+
appendPQExpBuffer(query,
4216+
"\n AND ("
4217+
"\n pronamespace != "
4218+
"(SELECT oid FROM pg_namespace "
4219+
"WHERE nspname = 'pg_catalog')");
42154220
if (binary_upgrade && fout->remoteVersion >= 90100)
42164221
appendPQExpBuffer(query,
42174222
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "

0 commit comments

Comments
 (0)