>> 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