from pgAdmin, it takes 1 second. When I run this command from script it takes 11 minutes!Any idea why running this command from script takes 11 minutes?Different plans maybe? Try EXPLAIN ANALYZE in both cases.
Thank you. I tried explain analyze SELECT r.dokumnr FROM rid r LEFT JOIN dok d USING (dokumnr) WHERE d.dokumnr IS NULL with small database.