• Tom Lane's avatar
    Fix dependency searching for case where column is visited before table. · 2edfc021
    Tom Lane authored
    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 cb5c2ba2 to 9.0
    if we wanted to back-patch this.
    2edfc021
dependency.c 68.8 KB