sbargay
sbargay

Reputation: 81

Performance question: ON DUPLICATE KEY UPDATE vs UPDATE (MySQL)

Is there performance difference between INSERT INTO ON DUPLICATE KEY UPDATE and UPDATE?

If I know the values that can be UPDATEd - should I use UPDATE or it does not really matter?

Upvotes: 5

Views: 4534

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52372

There is a difference.

The INSERT query has to check the constraints on every column to see if they're violated by adding that row. If so, it then needs to find the matching row to update and perform the update.

An UPDATE query only has to find the row to update and perform the update.

If you know the row already exists, you should just UPDATE it.

Upvotes: 10

Related Questions