mysql面试题索引Mysql---索引命中
sql数据库创建学生表
1、假设 test_demo表中有个复合索引 idx(sex,company,job)
    1.1、最左前缀原则
explain select * from test_demo where sex='' and job ='' and  company=''
结果:type:ref、key:idx
explain select * from test_demo where job ='' and sex='' and  company=''
结果:type:ref、key:idx
伦勃朗自画像的艺术探究
explain select * from test_demo where company='' and job ='' and sex=''
结果:type:ref、key:idx
explain select * from test_demo where job ='' and  company=''
结果:type:all
explain select * from test_demo where company='' and job=''
结果:type:all
游戏挂机赚钱一小时20
explain select * from test_demo where sex='' and job =''
结果:type:ref、key:idx
explain select * from test_demo where sex='' and company =''
结果:type:ref、key:idx
少儿编程免费视频explain select * from test_demo where sex=''
结果:type:ref、key:idx
explain select * from test_demo where job =''
结果:type:all
explain select * from test_demo where company =''
结果:type:all
    1.2、like不会命中索引spring过滤器
explain select * from test_demo where sex like '%%'
结果:type:all
    1.3、or命中索引
explain select * from test_demo where sex='' or sex =''
结果:type : ref、key:idx
    1.4、负向条件不会命中索引
explain select * from test_demo where sex!=''
结果:type:all
explain select * from test_demo where sex<>''
结果:type:all

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。