1 1.1 SELECT * FROM tbl WHERE title ='Senior' and emp_no < '10001' //这里使用到了最左前缀的emp_no索引 1.2 SELECT * FROM tbl WHERE title ='Senior' and emp_no like '10001' //这里没有使用到索引
同样都是范围查询 为什么第二个没有使用emp_no索引?
2 2.1
SQL code
SELECT * FROM tbl
WHERE emp_no BETWEEN '10001' AND '10010'
AND title='Senior Engineer'
AND from_date BETWEEN '1986-01-01' AND '1986-12-31';
用到了所有索引 2.2
SQL code
SELECT * FROM tbl
WHERE emp_no BETWEEN '10001' AND '10010'
AND title='Senior Engineer'
AND from_date > '1986-01-01' AND from_date<'1986-12-31';