Check for duplicates using indexes.