Add UNIQUE index fails with duplicate entry error, but no duplicates found
There is no guarantee that the valueaaaaaaaaaaaaaaa-11111
in the message
[23000][1062] Duplicate entry 'aaaaaaaaaaaaaaa-11111' for key 'mykey'
is the value that actually causes the violation. Seems to be a bug in MariaDB and in MySQL.
Plan A: Use INSERT IGNORE
in your batched inserts. That way the dup keys do not cause trouble.
Plan B: Insert into a table with INDEX
, not UNIQUE
. Then you can investigate the duplicates before deciding what to do with them.
You understand that CHAR(15) utf8
occupies 45 bytes always for most ROW_FORMATs
? Perhaps VARCHAR(15)
would be better? (Please don't quote the debunked wives' tale about FIXED
being better in MyISAM.)
Or maybe the data is, say, old IPv4 strings? They work fine with CHARACTER SET ascii
-- 15 bytes for CHAR(15)
or 1-16 bytes for VARCHAR(15)
. Then, what about IPv6? And about inability to compare ranges?