Skip to content

Commit 9194c42

Browse files
committed
Avoid sometimes printing both tables and their columns in DROP CASCADE.
A cascaded drop might find independent reasons to drop both a table and some column of the table (for instance, a schema drop might include dropping a data type used in some table in the schema). Depending on the order of visitation of pg_depend entries, we might report the table column and the whole table as separate objects-to-be-dropped, or we might only report the table. This is confusing and leads to unstable regression test output, so fix it to report only the table regardless of visitation order. Per gripe from Peter Geoghegan. This is just cosmetic from a user's standpoint, and we haven't actually seen regression test problems in practice (yet), so I'll refrain from back-patching. Discussion: https://postgr.es/m/[email protected]
1 parent f04ad77 commit 9194c42

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/backend/catalog/dependency.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ typedef struct
102102
#define DEPFLAG_INTERNAL 0x0008 /* reached via internal dependency */
103103
#define DEPFLAG_EXTENSION 0x0010 /* reached via extension dependency */
104104
#define DEPFLAG_REVERSE 0x0020 /* reverse internal/extension link */
105+
#define DEPFLAG_SUBOBJECT 0x0040 /* subobject of another deletable object */
105106

106107

107108
/* expansible list of ObjectAddresses */
@@ -886,6 +887,10 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
886887
if (extra->flags & DEPFLAG_ORIGINAL)
887888
continue;
888889

890+
/* Also ignore sub-objects; we'll report the whole object elsewhere */
891+
if (extra->flags & DEPFLAG_SUBOBJECT)
892+
continue;
893+
889894
objDesc = getObjectDescription(obj);
890895

891896
/*
@@ -2320,13 +2325,19 @@ object_address_present_add_flags(const ObjectAddress *object,
23202325
* DROP COLUMN action even though we know we're gonna delete
23212326
* the table later.
23222327
*
2328+
* What we can do, though, is mark this as a subobject so that
2329+
* we don't report it separately, which is confusing because
2330+
* it's unpredictable whether it happens or not. But do so
2331+
* only if flags != 0 (flags == 0 is a read-only probe).
2332+
*
23232333
* Because there could be other subobjects of this object in
23242334
* the array, this case means we always have to loop through
23252335
* the whole array; we cannot exit early on a match.
23262336
*/
23272337
ObjectAddressExtra *thisextra = addrs->extras + i;
23282338

2329-
thisextra->flags |= flags;
2339+
if (flags)
2340+
thisextra->flags |= (flags | DEPFLAG_SUBOBJECT);
23302341
}
23312342
}
23322343
}
@@ -2374,7 +2385,8 @@ stack_address_present_add_flags(const ObjectAddress *object,
23742385
* object_address_present_add_flags(), we should propagate
23752386
* flags for the whole object to each of its subobjects.
23762387
*/
2377-
stackptr->flags |= flags;
2388+
if (flags)
2389+
stackptr->flags |= (flags | DEPFLAG_SUBOBJECT);
23782390
}
23792391
}
23802392
}

0 commit comments

Comments
 (0)