20 April 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
昨天写代码的时候发现 MySQL 的 SELECT 条件多反而比条件少要快很多。
其实我可以用
SELECT * FROM comment WHERE reply_to = ?
来得到我想要的结果。但是我用
SELECT * FROM comment WHERE reply_to = ? AND object_id = ? AND object_type = ?
时,结果是一样的,但是速度从 7-9s 提高到 0.07-0.09, 速度提升了百倍。这东西可能在表的 rows 比较少的时候效果不明显。但在 rows 是 4,530,000 时就有百倍的提升。

又学会一手。


blog comments powered by Disqus