Is using rand() in an INSERT statement also slow?
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?
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.
精彩评论