Re: dropping column prevented due to inherited index

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: dropping column prevented due to inherited index
Date: 2019-10-08 08:42:36
Message-ID: CA+HiwqFb=tqLFN5KB+OcN+SS9W4b=_+dXNfaRe2HCngmFS=a_g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Ashutosh,

On Mon, Oct 7, 2019 at 1:39 PM Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-10-08 08:55:01 Re: Remove some code for old unsupported versions of MSVC
Previous Message ideriha.takeshi@fujitsu.com 2019-10-08 08:36:10 RE: Global shared meta cache