According to the docs:
If [columns
a
andb
are] unique, theINSERT
is equivalent to thisUPDATE
statement instead:UPDATE table SET c=c+1 WHERE a=1 OR b=2 LIMIT 1;
If
a=1 OR b=2
matches several rows, only one row is updated. In general, you should try to avoid using anON DUPLICATE KEY UPDATE
clause on tables with multiple unique indexes.
This is fair enough, but what if I have this as the only key:
PRIMARY KEY (`a`,`b`)
Since the duplicate key is dependant on both fields simultaneously, would the update reliably affect the specific row where the duplicate occurs, or does it do the same as if the fields were individually unique?