Re: Query runs very slowly in Postgres, but very fast in other DBMS - Mailing list pgsql-sql

From Andrus
Subject Re: Query runs very slowly in Postgres, but very fast in other DBMS
Date
Msg-id d3g6pg$nik$1@news.hub.org
Whole thread Raw
In response to Query runs very slowly in Postgres, but very fast in other DBMS  ("Andrus Moor" <eetasoft@online.ee>)
List pgsql-sql
>> SELECT dokumnr FROM rid WHERE dokumnr NOT IN
>> (select dokumnr FROM dok);
> ...
>> Is it possible to speed up this query is Postgres ? How to force Postgres 
>> to use indexes for this query ?
>
> Use IN and NOT IN only for small sets. Use JOIN (instead of IN) and LEFT 
> JOIN (instead of NOT IN) for larger sets. e.g.:
>
> SELECT rid.dokumnr
> FROM rid
> LEFT JOIN dok ON (dok.dokumnr = rid.dokumnr)
> WHERE dok.dokumnr iS NULL;

Thank you.
How to use this technique to speed up the update statement

UPDATE rid SET dokumnr=NULL WHERE  dokumnr NOT IN (SELECT dokumnr FROM dok);

and DELETE statement

DELETE FROM rid WHERE  dokumnr NOT IN (SELECT dokumnr FROM dok);

Andrus 




pgsql-sql by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: getting count for a specific querry
Next
From: "Dan Feiveson"
Date:
Subject: Re: Query runs very slowly in Postgres, but very fast in other DBMS