消息关闭
    暂无新消息!
有一段SQL执行:


MariaDB [db2_art]> explain SELECT *  FROM `tt_art`
 WHERE ((`status` IN (1, 2))
 OR ((`status`=-2) AND (`uptime` > 1497420704)) 
 OR ((`status`=0) AND (`uptime` > 1497766304))) AND (`uptime` > 1482300704);



字段 uptime是存放文章最后更新时间,可以在这个上面加索引吗?
表 info的 已经加了索引 status 、uptime之后的 explain


+------+-------------+----------+-------------+------------------------+------------------------+---------+------+--------+-------------------------------------------------------+
| id   | select_type | table    | type        | possible_keys          | key                    | key_len | ref  | rows   | Extra                                                 |
+------+-------------+----------+-------------+------------------------+------------------------+---------+------+--------+-------------------------------------------------------+
|    1 | SIMPLE      | tt_art | index_merge | idx-tt-status,uptime | idx-tt-status,uptime | 2,4     | NULL | 272407 | Using sort_union(idx-tt-status,uptime); Using where |
+------+-------------+----------+-------------+------------------------+------------------------+---------+------+--------+-------------------------------------------------------+
1 row in set (0.00 sec)




1个回答