在 INSERT 语句中使用 rand() 也很慢吗?

发布于 2024-09-25 03:51:23 字数 223 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风和你 2024-10-02 03:51:23

随着表越来越大,rand()函数会变慢吗?

不会。RAND() 在大表上变慢的情况通常是与 ORDER BYWHERE 结合使用时。在您的示例中,您对 RAND() 进行一次调用,这不会造成性能问题。

Will the rand() function become slow as the table gets larger and larger?

No. RAND() getting slower on big tables is usually when it is used in conjunction with ORDER BY or WHERE. In your example, you are making one call to RAND() which will not be a performance problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文