美文网首页
关于mysql的索引

关于mysql的索引

作者: 无尘粉笔 | 来源:发表于2021-03-15 10:18 被阅读0次

我们首先创建一个表
并且创建索引

create table user
(
    id int auto_increment
        primary key,
    name int not null,
    age int not null,
    sex int not null,
    remark int null
);

create index user_name_age_sex_index
    on user (name, age, sex);

create index user_remark_index
    on user (remark);

我们通过这些测试

explain select * from user where name = 1;
explain select * from user where age = 1;
explain select * from user where sex = 1;
explain select * from user where name = 1 and sex = 1;
explain select * from user where name = 1 and sex = 1;
explain select * from user where age > 1 and name < 1;
explain select * from user where age = 1 and name > 1;
explain select * from user where sex = 1 and name = 1;
explain select * from user where sex = 1 and age = 1;
explain select * from user where name = 1 and age = 1 and sex = 1 ;
explain select * from user where name = 1 and sex = 1 and age = 1 ;
explain select * from user where remark = 1 and name = 1 and sex = 1 ;
explain select * from user where age = 1 and sex = 1 and name = 1 ;
explain select * from user where sex = 1 and name = 1 and age = 1 ;
explain select * from user where sex = 1 and age = 1 and name = 1 ;
explain select * from user where sex = 1 and name = 1 and remark = 1;

可以看出包含name的走name_age_sex的索引


image.png

如果不包含name,包含remark的走remark索引


image.png

相关文章

  • MySQL索引知多少

    mysql索引 总结关于mysql的索引,查询优化,SQL技巧等 1 索引类型 B-Tree索引 Hash索引 ...

  • Mysql 索引 & 锁

    Mysql索引在开发工作中经常用到,在此总结一些关于mysql索引的一些学习笔记 1mysql索引的本质是什么? ...

  • MySQL联合索引运用-最左匹配原则

    前言 之前看了很多关于MySQL索引的文章也看了《高性能MySQL》这本书,自以为熟悉了MySQL索引使用原理,入...

  • MySQL索引及查询优化书目录

    MySQL索引的原理之索引目的 MySQL索引的原理之索引原理 MySQL索引的原理之索引的类型 MySQL索引的...

  • 《高性能mysql》------ 索引(一)

    mysql索引 最近一直在看《高性能mysql》,关于索引部分,以前接触过,但是不是特别深入,仅仅了解过主键索引,...

  • 关于mysql索引

    数据库主要字段三个,aCityId,bCityId,distance,主要储存两个城市之间距离 关于索引: 图中索...

  • MySQL索引的使用

    MySQL索引 MySQL索引可以快速提高MySQL的检索速度。索引分单列索引和组合索引单列索引:即一个索引只包含...

  • 关于mysql的索引

    我们首先创建一个表并且创建索引 我们通过这些测试 可以看出包含name的走name_age_sex的索引 如果不包...

  • 高性能的索引策略

    MySQL查询基础-查询执行过程 MySQL聚簇索引 MySQL覆盖索引 MySQL索引扫描排序 MySQL冗余和...

  • MySql性能(7)—MySql索引扫描与order by排序优

    在mysql中,order by子句也可以使用索引优化。 在《高性能mysql第三版》中关于索引建议是这样描述的:...

网友评论

      本文标题:关于mysql的索引

      本文链接:https://www.haomeiwen.com/subject/jcapqltx.html