Re: DELETE with filter on ctid - Mailing list pgsql-performance

From Tom Lane
Subject Re: DELETE with filter on ctid
Date
Msg-id 10502.1176152127@sss.pgh.pa.us
Whole thread Raw
In response to DELETE with filter on ctid  ("Spiegelberg, Greg" <gspiegelberg@cranel.com>)
Responses Re: DELETE with filter on ctid  ("Spiegelberg, Greg" <gspiegelberg@cranel.com>)
List pgsql-performance
"Spiegelberg, Greg" <gspiegelberg@cranel.com> writes:
> We have a query which generates a small set of rows (~1,000) which are
> to be used in a DELETE on the same table.  The problem we have is that
> we need to join on 5 different columns and it takes far too long.  I
> have a solution but I'm not sure it's the right one.  Instead of joining
> on 5 columns in the DELETE the join uses the ctid column.

> BEGIN;
> CREATE INDEX gregs_table_ctid_idx ON gregs_table(ctid);
> DELETE FROM gregs_table gt
>    USING (SELECT ctid FROM gregs_table WHERE ...) as s
>    WHERE gt.ctid=s.ctid;
> DROP INDEX gregs_table_ctid_idx;
> COMMIT;

Forget the index, it's useless here (hint: ctid is a physical address).
I'm wondering though why you don't just transpose the subquery's WHERE
condition into the DELETE's WHERE?  Or is this example oversimplified?

            regards, tom lane

pgsql-performance by date:

Previous
From: Drew Wilson
Date:
Subject: how to efficiently update tuple in many-to-many relationship?
Next
From: Jeff Davis
Date:
Subject: Re: Please humor me ...