Re: DROP OWNED BY doesn't work - Mailing list pgsql-patches

From Alvaro Herrera
Subject Re: DROP OWNED BY doesn't work
Date
Msg-id 20060820050104.GG10267@alvh.no-ip.org
Whole thread Raw
Responses Re: DROP OWNED BY doesn't work  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-patches by date:

Previous
From: Gregory Stark
Date:
Subject: Concurrent connections in psql patch
Next
From: Tom Lane
Date:
Subject: Re: DROP OWNED BY doesn't work