前段时间一位同事收到某开发部门一位同事求助,希望帮忙优化一条Mysql的sql语句,大体如下:select n.id ,nc.contentfrom news n force index (category1_status,category2_status,category3_status),news_content ncwhere n.id=nc.idand n.status=2 and (n.category_id_1 in (5003107,5003108)or n.category_id_2 in (5003107,5003108)or n.category_id_3 in (5003107,5003108)调试的时候发现怎么都不能走index_merge的执行计划(我们所期望的),后来临时给他们一个union的解决方案。后来下班吃完晚饭后一起找问题,发现即使只有单个表,也没办法走到index_merge的执行计划,不管是加提示还是不加提示,调试过程如下:mysql> explain select n.id ,nc.content-> from news n force index (category1_status,category2_status,category3_status),news_content nc-> where n.id=nc.id-> and n.s
...
继续阅读
(8)