性能问题:重复键更新与更新(MySQL) [英] Performance question: ON DUPLICATE KEY UPDATE vs UPDATE (MySQL)
问题描述
INSERT INTO ON DUPLICATE KEY UPDATE和UPDATE之间是否存在性能差异?
Is there performance difference between INSERT INTO ON DUPLICATE KEY UPDATE and UPDATE?
如果我知道可以更新的值-我应该使用UPDATE还是没有关系?
If I know the values that can be UPDATEd - should I use UPDATE or it does not really matter?
推荐答案
有区别.
INSERT
查询必须检查每列上的约束,以通过添加该行来查看是否违反了约束.如果是这样,则需要找到匹配的行以进行更新并执行更新.
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.
UPDATE
查询只需找到要更新的行并执行更新.
An UPDATE
query only has to find the row to update and perform the update.
如果您知道该行已经存在,则只需UPDATE
即可.
If you know the row already exists, you should just UPDATE
it.
这篇关于性能问题:重复键更新与更新(MySQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!