在 INSERT 语句中使用 rand() 也很慢吗?
MYSQL rand() 函数在 select 语句中非常慢,对于 insert 语句也是如此吗?我想通过以下方式插入一个带有随机数的新行:
insert into new_table (field1, field2, randomField) values ('Hello', 'Ola', rand());
随着表变得越来越大,rand() 函数会变得很慢吗?
The MYSQL rand() function is notoriously slow in select statements, is this true for insert statements as well? I would like to insert a new row with random number in the following way:
insert into new_table (field1, field2, randomField) values ('Hello', 'Ola', rand());
Will the rand() function become slow as the table gets larger and larger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。RAND() 在大表上变慢的情况通常是与
ORDER BY
或WHERE
结合使用时。在您的示例中,您对RAND()
进行一次调用,这不会造成性能问题。No. RAND() getting slower on big tables is usually when it is used in conjunction with
ORDER BY
orWHERE
. In your example, you are making one call toRAND()
which will not be a performance problem.