Re: how to speed up query - Mailing list pgsql-general

From Erwin Brandstetter
Subject Re: how to speed up query
Date
Msg-id 1181402070.769668.269750@q75g2000hsh.googlegroups.com
Whole thread Raw
In response to Re: how to speed up query  (Erwin Brandstetter <brsaweda@gmail.com>)
Responses Re: how to speed up query  ("Andrus" <kobruleht2@hot.ee>)
List pgsql-general
On Jun 9, 12:15 am, Erwin Brandstetter <brsaw...@gmail.com> wrote:
> 3.) Write results of the subquery in a temp table, then DELETE:
>
> CREATE TEMP TABLE mydel AS SELECT DISTINCT dokumnr  FROM firma1.rid;
> DELETE FROM firma1.dok USING mydel WHERE firma1.rid.doumnr =
> mydel.doumnr;

Ah! 3.) should read:
CREATE TEMP TABLE mydel AS SELECT DISTINCT dokumnr  FROM firma1.rid;
DELETE FROM firma1.dok WHERE dokumnr NOT IN (SELECT dukumnr FROM
mydel);

Or 4.)
If "NOT IN" should be the culprit, there is an alternative:
( I seem to remember issues with its performance in the past, but
hasn't that been improved? Not sure.)
Haven't tested, whether the temp table is useful here:

CREATE TEMP TABLE mydel AS
SELECT d.dokumnr
FROM firma1.dok d
LEFT JOIN (SELECT DISTINCT dokumnr FROM firma1.rid) r USING (dokumnr)
WHERE r.dokumnr IS NULL;
DELETE FROM firma1.dok USING mydel WHERE firma1.dok.doumnr =
mydel.documnr;


Regards
Erwin


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: insane index scan times
Next
From: Andreas
Date:
Subject: odbc with encrypted ssl key?