From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Spiegelberg, Greg" <gspiegelberg(at)cranel(dot)com> |
Cc: | pgsql-performance(at)postgresql(dot)org |
Subject: | Re: DELETE with filter on ctid |
Date: | 2007-04-09 20:55:27 |
Message-ID: | 10502.1176152127@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
"Spiegelberg, Greg" <gspiegelberg(at)cranel(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2007-04-09 21:05:44 | Re: Please humor me ... |
Previous Message | Drew Wilson | 2007-04-09 20:46:59 | how to efficiently update tuple in many-to-many relationship? |