From: Tom Lane <tgl@sss.pgh.pa.us>
To: Spiegelberg, Greg <gspiegelberg@cranel.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: DELETE with filter on ctid
Date: Mon, 09 Apr 2007 16:55:27 -0400
Message-ID: <10502.1176152127@sss.pgh.pa.us> (raw)
In-Reply-To: <82E74D266CB9B44390D3CCE44A781ED90B6ADC@POSTOFFICE.cranel.local>
References: <82E74D266CB9B44390D3CCE44A781ED90B6ADC@POSTOFFICE.cranel.local>
"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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, gspiegelberg@cranel.com
Subject: Re: DELETE with filter on ctid
In-Reply-To: <10502.1176152127@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox