Andrus Moor wrote:
> 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;
Cheers,
Ezequiel Tolnay