Can anyone suggest how I might INSERT batched queries into an Apache Derby DB whilst still handling duplicate entries with good performance?
As a last resort to try and balance performance with the ability to handle duplicate keys on INSERT, I decided to let JDBC / Derby tell me when a batched query would result in a duplicate key, catch the error, and then continue with the remaining batched queries.
Unfortunately, as soon as an error is detected, it seems to clear out the whole batch of queries which means that I lose all of the remaining records.
Things I've tried:
- Perform a programmatic query to determine if the entry is already in there. Abandoned this because the data may currently be in a batch, so it will be missed.
- Use SQL queries to only INSERT if record is not already present. Abandoned this because it resulted in awful INSERT performance (down by almost 70%).
- Let the DB tell me about duplicate keys, catch the error and continue processing batch. About to abandon this because it 'forgets' that there are other queries to process in the batch.
If only Derby supported INSERT IGNORE.
Thanks