Why don't use mysql ORDER BY RAND()?

后端 未结 1 499
梦谈多话
梦谈多话 2020-12-06 14:26

I saw many websites saying don\'t use ORDER BY RAND(), eg http://forge.mysql.com/wiki/Top10SQLPerformanceTips So I run a test, I have tested the speed and performance on 20k

1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-06 15:11

    The problem of ORDER BY RAND() is that as your explain tells you the "Using temporary" and the "Using filesort". For each request a temporary table is created and sorted. Thats a pretty heavy operation. It will probably not matter when your database is not under heavy load but it will cost a lot of performance.

    0 讨论(0)
提交回复
热议问题