长时间运行的查询中的 SQL NOW()
假设我有长时间运行的更新查询
update some_table
set modification_time = now()
where (something incredibly complex);
some_table 中的modification_time 的值是多少?它们是相同还是不同(例如,查询执行需要 2 天)。
如果它们不同,我该如何编写这个查询以使它们都相同?
Say I have long running update query
update some_table
set modification_time = now()
where (something incredibly complex);
What will be values of modification_time in some_table? Will they be same or different (say, it took 2 days for query to execute).
And if they will be different, how do I write this query so that they all are same?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们都是相同的,因为 NOW() 在查询开始时被锁定。
这个答案是否太短了?
好的,更多信息 NOW 的 MySQL 参考( )
阅读 SYSDATE() 但是,其中包含此代码段
您问的有什么有趣的。注意到您可以在查询中SLEEP?考虑此查询(子查询仅模拟 3 条记录的表)
您将得到:
They will all be the same, since NOW() is locked in at the time of query start.
Is this too short as an answer?
Okay, more info MySQL reference for NOW()
It is actually more interesting to read the manual entry for SYSDATE() however, which contains this snippet
What's so interesting you ask.. notice that you can SLEEP in a query?? Consider this query (the sub-query just emulates a 3-record table)
You get: