I have a table in my database with a string for a primary_key, which I set. I need to check frequently if around 1000 "items" exist in that table before adding them, because there must not be any duplicates. The result is 2 queries per Item, or 2000 total, which is 1-2 seconds of extra loading time.
If I try to insert the new row anyway, without checking for duplicates it doesn't get inserted and that's great, but mysql returns an error, which crashes my service.
My questions:
- Can I turn off those errors?
- Is there a better way to prevent inserting duplicates than making an extra query?