我必須使用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