性能问题:重复键更新与更新(MySQL) [英] Performance question: ON DUPLICATE KEY UPDATE vs UPDATE (MySQL)

查看:102
本文介绍了性能问题:重复键更新与更新(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆