Bug #54312 | insert ... select .. order by rand(): difference depending on indexes. | ||
---|---|---|---|
Submitted: | 7 Jun 2010 22:19 | Modified: | 8 Jun 2010 4:50 |
Reporter: | Some One | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
Version: | 5.1.47, 5.1.48-bzr | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[7 Jun 2010 22:19]
Some One
[8 Jun 2010 4:50]
Valeriy Kravchuk
It is easy to repeat on 5.1.48 as well. The difference is explained by the following results to some extent: mysql> explain select * from test2 order by rand(); +----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+ | 1 | SIMPLE | test2 | index | NULL | PRIMARY | 4 | NULL | 5 | Using index; Using temporary; Using filesort | +----+-------------+-------+-------+---------------+---------+---------+------+------+----------------------------------------------+ 1 row in set (0.03 sec) mysql> explain select * from test1 order by rand(); +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ | 1 | SIMPLE | test1 | ALL | NULL | NULL | NULL | NULL | 5 | Using temporary; Using filesort | +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ 1 row in set (0.00 sec) That is, when you add index it is used to scan all rows instead of the table itself. But as filesort is applied in both cases I'd expect for ORDER BY rand() to still work. So, I'd call this a bug.