mysql UPDATE语句-对于相同值的开销? [英] mysql UPDATE statement - overhead for same values?

查看:163
本文介绍了mysql UPDATE语句-对于相同值的开销?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拥有成千上万条记录的大型MYSQL数据库.我想更新其中的一个字段,但我不知道该字段是否已更新.

如果我调用一个将authortype = 10设置为authortype且已将authortype设置为10的更新语句,这会比执行单独的查询来仅选择不是authortype = 10的查询然后更新它们的速度更快吗?

换句话说,如果我将值设置为已经等于的值,这是否比我将值更新为新值快?再次有无数的记录,我想提高效率.

预先感谢

解决方案

为什么不只是使用

UPDATE  dbo.Authors
SET     AuthorType = 10
WHERE   AuthorType <> 10

并且两全其美.

请注意,对于任何现代数据库引擎而言,数十万条记录都不会造成任何问题.

次要编辑

i have a large MYSQL database with hundreds of thousands of records. i want to update a field in a large number of them, but I am unaware if that field has been updated yet or not.

if i call an update statement that sets authortype=10 and authortype is already 10 will this be faster than doing a separate query to only select those that aren't authortype=10 and then update them?

in other words, if I set a value equal to what it is already, is that any faster than if I am updating a value to something new? again this is with tons and tons of records and I want to be efficient.

thanks in advance

解决方案

Why not just use

UPDATE  dbo.Authors
SET     AuthorType = 10
WHERE   AuthorType <> 10

and have the best of both worlds.

Note that a few hundred thousands records should pose no problem for any modern database engine.

Minor edit

这篇关于mysql UPDATE语句-对于相同值的开销?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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