Re: DROP OWNED BY doesn't work

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-patches(at)postgreSQL(dot)org
Subject: Re: DROP OWNED BY doesn't work
Date: 2006-08-20 05:01:04
Message-ID: 20060820050104.GG10267@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Tom Lane wrote:

> What I was thinking of was
>
> find all target objects using pg_shdepend, make an
> ObjectAddresses list of them
>
> for (each item of list)
> {
> if (already deleted)
> continue;
> if (implicit dependency of some later list item)
> continue;
> pass item to performDeletion, with entire list
> as oktodelete context
> }

Ok, this patch implements more or less this idea; except that instead of
checking the list of implicit dependencies for later objects, we iterate
twice on the list of objects to delete, and create a list of implicit
dependencies on all of them the first time, and delete those not on that
list the second time.

Regression tests pass. This patch makes the following example work as
expected. Note that the first "drop owned" is stopped by the FK on tt3;
by adding the cascade, it drops the foreign key.

Let me know if it fixes your problem, and I'll commit it early tomorrow.
(Or you can do it if you're in a hurry ...)

create user foo;
create user bar;

\c - bar
create table tt3 (f1 int);

\c - foo
create table tt1 (f1 int);
create table tt2 (f1 int primary key);
alter table tt1 add foreign key (f1) references tt2;
grant references on table tt2 to bar;

\c - bar
alter table tt3 add foreign key (f1) references tt2;

\c - foo
drop owned by foo;
drop owned by foo cascade;

--
Alvaro Herrera http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support

Attachment Content-Type Size
drop-owned-bug.patch text/plain 21.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message dror 2006-08-20 08:27:12 Re: Bug with initDB under windows 2003
Previous Message Tom Lane 2006-08-20 03:39:14 Re: OTRS

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2006-08-20 16:05:57 Re: DROP OWNED BY doesn't work
Previous Message Tom Lane 2006-08-20 01:01:05 Re: DROP OWNED BY doesn't work