MySQL複合索引(聯合索引) a b c

SQL腳本

CREATE TABLE `test1` (
  `id` int(11) NOT NULL,
  `a` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
  `b` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
  `c` varchar(255) COLLATE utf8mb4_bin DEFAULT NULL,
  KEY `i1` (`a`,`b`,`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

測試sql:

desc select * from  test1 where a='1' and b='1' and c='1';	//走索引
desc select * from  test1 where a='1' and b='1';		//走索引
desc select * from  test1 where a='1' and c='1';		//走索引
desc select * from  test1 where b='1' and c='1';		//沒走索引

實際測試結果:bc沒有走索引

參考資料:

https://zhidao.baidu.com/question/1574629868516219500.html

https://www.cnblogs.com/liuqun/p/12655147.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章