zoukankan      html  css  js  c++  java
  • 什么是mysql索引下推(有些装B面试官会问)

    参考资料:

    https://www.bilibili.com/video/BV1kJ411H7w7?from=search&seid=16755936018144089586

    看完视频之后,感觉就是面试官装逼问这个,这次遇到了来补习下。(面试官不问联合索引,直接问知不知道索引下推)

    真不知道有啥好问的?联合索引的最左前缀原则才是开发人员应该关注的,索引下推只是满足最左前缀原则后出来一个优化现象而已。

    下面介绍下索引下推,首先创建一个myperson表

    drop table if exists myperson;
    create table myperson(
        id bigint not null primary key auto_increment,
        name varchar(50),
        age int,
        key(name,age)
    )default charset=utf8 ;
    
    insert into myperson(name,age) values
    ('andy',29),
    ('张三',17),
    ('张三',18),
    ('张三',19),
    ('张麻子',19),
    ('李四',20),
    ('王五',21),
    ('赵六',22),
    ('田七',23);
    
    select * from myperson where name='张三' and age>18; 
    select * from myperson where name like '张%' and age>18; 
    
    --上面两个sql就是索引下推,就是在(name,age)这个索引中,先查询name,再查询,最后回表查询聚簇索引,实际上就是最左前缀原则。
  • 相关阅读:
    leetcode Lowest Common Ancestor of a Binary Tree
    leetcode 141、Linked list cycle
    leetcode 136、Single Number
    tensorflow使用
    c++ priority_queue
    python语法
    CSS基础之选择器
    并发编程的一些理解
    封装的绑定与多态
    继承与派生
  • 原文地址:https://www.cnblogs.com/mkl34367803/p/14747664.html
Copyright © 2011-2022 走看看