mysql 聚合索引

一、创建索引

 
1. PRIMARY KEY (`id`),
 
2. UNIQUE KEY `uid` (`uid`,`task_id`)

查询:

explain select * from user_task where uid = 232;
explain select * from user_task where task_id = 1454;
explain select * from user_task where task_id = 1454 and uid = 232;

二、

如果(a, b, c)

查询a ; a b ; a b c 会用到索引

所以建立索引的时候 如果要查询 b c  那么可以 key(b, c)

KEY 和index 不同的是 key 可以有约束 同时会有索引

转载: https://blog.csdn.net/mingluoxuan/article/details/84598988

原文地址:https://www.cnblogs.com/brithToSpring/p/13475479.html