From: OU <moebius444@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Separating data sets in a table
Date: Sat, 24 Aug 2002 23:52:23 +0200
Message-ID: <ak8sqe$1lbh$1@news.hub.org> (raw)
References: <Pine.LNX.4.44.0208221126490.1478-100000@wr-linux02.rki.ivbb.bund.de>
"Andreas Tille" <tillea@rki.de> a écrit dans le message de news:
Pine.LNX.4.44.0208221126490.1478-100000@wr-linux02.rki.ivbb.bund.de...
...
> I tried to do the following approach:
>
> CREATE LOCAL TEMPORARY TABLE ImportOK () INHERITS (Import) ;
>
> INSERT INTO ImportOK SELECT * FROM Import i
> INNER JOIN Ref r ON i.Id = r.Id;
>
> DELETE FROM Import WHERE Id IN (SELECT Id FROM ImportOK) ;
...
> Unfortunately the latest statement is so terribly slow that I can't
> imagine that there is a better way to do this.
>
You must use EXISTS if you work with big tables.
EXISTS use indexes, and IN use temporary tables.
-- this change nothing for IN :
CREATE INDEX import_id_index ON import(id);
CREATE INDEX import_ok_id_index ON import_ok(id);
-- slow :
-- DELETE FROM import WHERE id IN (SELECT id FROM import_ok) ;
DELETE FROM import WHERE EXISTS (
SELECT id FROM import_ok AS ok
WHERE ok.id = import.id
);
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-sql@postgresql.org
Cc: moebius444@hotmail.com
Subject: Re: Separating data sets in a table
In-Reply-To: <ak8sqe$1lbh$1@news.hub.org>
* 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