MySQL索引面试题分析
MySQL索引面试题分析 话不多说,先建立一个表testTable,其中id为自增主键 在c1,c2,c3,c4上建立符合索引索引 CREATE INDEX idx_testTable_c1234 ON testTable ( c1 , c2 , c3 , c4 ) ; 现在的题目是:根据以下SQL分析索引使用的情况 1. SELECT * FROM testTable WHERE c1 = 'a1' AND c2 = 'a2' AND c3 = 'a3' AND c4 = 'a4' ; 2. SELECT * FROM testTable WHERE c4 = 'a4' AND c3 = 'a3' AND c2 = 'a2' AND c1 = 'a1' ; 首先我们用explain语句来分析一下1,2条SQL语句 EXPLAIN SELECT * FROM testTable WHERE c1 = 'a1' AND c2 = 'a2' AND c3 = 'a3' AND c4 = 'a4' ; EXPLAIN SELECT * FROM testTable WHERE c4 = 'a4' AND c3 = 'a3' AND c2 = 'a2' AND c1 = 'a1' ; 在这里我们看到它们的结果都是一样的,这是为什么呢? 其实,在MySQL逻辑架构中