# 组合索引 Goods 表结构如下: ```mysql create table goods( id int primary key auto_increment, category_id int, category varchar(64), name varchar(256), price decimal(12, 4), stock int, upper_time timestamp ) ``` 现有大量查询 `select id, category_id, name, price, stock from goods where stock=? and category_id=? and name like ?`, Joe 应该如何优化? ## 答案 ```mysql alter table goods add index (stock, category_id, name); ``` ## 选项 ### A ```mysql alter table goods add index (stock and category_id and name); ``` ### B ```mysql alter table goods add index (concat(stock, category_id, name)); ``` ### C ```mysql alter table goods add index (stock + category_id + name); ```