我必须使用MYSQL query
中的RAND函数。如果我在sql查询中使用这个函数,那么这需要大约0.7962秒。但如果我没有使用它,那么这个工作在0.0009秒内就可以完成。如何使用RAND函数更快地进行sql查询。ORDER BY RAND()函数花费很长时间在mysql中执行
我的查询
SELECT
posts.ID,
posts.post_content,
posts.post_title,
posts.post_date,
posts.post_name
FROM posts
WHERE posts.post_type = 'post'
AND posts.post_status = 'publish'
ORDER BY RAND() LIMIT 0, 24
请参阅此文章http://explainextended.com/2009/03/01/selecting-random-rows/ – Girish 2014-10-11 10:48:01
您是否在“冷”服务器上没有'ORDER BY'的查询时间?听起来像从缓存中获得结果的时间为0.0009秒。 – dasblinkenlight 2014-10-11 10:48:07