Re: dropping column prevented due to inherited index - Mailing list pgsql-hackers

From Amit Langote
Subject Re: dropping column prevented due to inherited index
Date
Msg-id CA+HiwqFb=tqLFN5KB+OcN+SS9W4b=_+dXNfaRe2HCngmFS=a_g@mail.gmail.com
Whole thread Raw
In response to Re: dropping column prevented due to inherited index  (Ashutosh Sharma <ashu.coek88@gmail.com>)
Responses Re: dropping column prevented due to inherited index  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Re: dropping column prevented due to inherited index  (Ashutosh Sharma <ashu.coek88@gmail.com>)
List pgsql-hackers
Hi Ashutosh,

On Mon, Oct 7, 2019 at 1:39 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> I think we could have first deleted all the dependency of child object
> on parent and then deleted the child itself using performDeletion().

So, there are two objects to consider in this case -- column and an
index that depends on it.

For columns, we don't store any dependency records for the dependency
between a child column and its corresponding parent column.  That
dependency is explicitly managed by the code and the attinhcount flag,
which if set, prevents the column from being dropped on its own.

Indexes do rely on dependency records for the dependency between a
child index and its corresponding parent index.  This dependency
prevents a child index from being dropped if the corresponding parent
index is also not being dropped.

In this case, recursively dropping a child's column will in turn try
to drop the depending child index.  findDependentObject() complains
because it can't allow a child index to be dropped, because it can't
establish that the corresponding parent index is also being dropped.
That's because the parent index will be dropped when the parent's
column will be dropped, which due to current coding of
ATExecDropColumn() is *after* all the child columns and indexes are
dropped.  If we drop the parent column and depending index first and
then recurse to children as my proposed patch does, then the parent
index would already have been dropped when dropping the child column
and the depending index.

> As an example let's consider the case of toast table where we first
> delete the dependency of toast relation on main relation and then
> delete the toast table itself otherwise the toast table deletion would
> fail. But, the problem I see here is that currently we do not have any
> entry in pg_attribute table that would tell us about the dependency of
> child column on parent.

I couldn't imagine how that trick could be implemented for this case. :(

Thanks,
Amit



pgsql-hackers by date:

Previous
From: "ideriha.takeshi@fujitsu.com"
Date:
Subject: RE: Global shared meta cache
Next
From: Peter Eisentraut
Date:
Subject: Re: Remove some code for old unsupported versions of MSVC