Optimize duplicate checks: don't open new cursors just to check for dups.