pgsql: Fix dependency searching for case where column is visited before - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix dependency searching for case where column is visited before
Date
Msg-id E1XoJUa-0005cK-4i@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix dependency searching for case where column is visited before table.

When the recursive search in dependency.c visits a column and then later
visits the whole table containing the column, it needs to propagate the
drop-context flags for the table to the existing target-object entry for
the column.  Otherwise we might refuse the DROP (if not CASCADE) on the
incorrect grounds that there was no automatic drop pathway to the column.
Remarkably, this has not been reported before, though it's possible at
least when an extension creates both a datatype and a table using that
datatype.

Rather than just marking the column as allowed to be dropped, it might
seem good to skip the DROP COLUMN step altogether, since the later DROP
of the table will surely get the job done.  The problem with that is that
the datatype would then be dropped before the table (since the whole
situation occurred because we visited the datatype, and then recursed to
the dependent column, before visiting the table).  That seems pretty risky,
and the case is rare enough that it doesn't seem worth expending a lot of
effort or risk to make the drops happen in a safe order.  So we just play
dumb and delete the column separately according to the existing drop
ordering rules.

Per report from Petr Jelinek, though this is different from his proposed
patch.

Back-patch to 9.1, where extensions were introduced.  There's currently
no evidence that such cases can arise before 9.1, and in any case we would
also need to back-patch cb5c2ba2d82688d29b5902d86b993a54355cad4d to 9.0
if we wanted to back-patch this.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/1c2f9a4f6e07d7870e2fed1cb314e673a6f4858d

Modified Files
--------------
src/backend/catalog/dependency.c |   74 ++++++++++++++++++++++++++++----------
1 file changed, 56 insertions(+), 18 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Fix dependency searching for case where column is visited before
Next
From: Tom Lane
Date:
Subject: pgsql: Loop when necessary in contrib/pgcrypto's pktreader_pull().