zoukankan      html  css  js  c++  java
  • 探寻BTree 索引对sql 优化影响

    从一道题開始分析:

    如果某个表有一个联合索引(c1,c2,c3,c4)一下——仅仅能使用该联合索引的c1,c2,c3部分
    A where c1=x and c2=x and c4>x and c3=x
    B where c1=x and c2=x and c4=x order by c3
    C where c1=x and c4= x group by c3,c2
    D where c1=? and c5=? order by c2,c3
    E where c1=? and c2=? and c5=?

    order by c2,c3

    有谁知道以下A-E是否能能够使用索引!

    !为什么?

    OK;開始

    创建表:

    insert into t 
    values
    ('a1','a2','a3','a4','a5'),
    ('b1','b2','b3','b4','b5');

    插入数据:

    insert into t 
    values
    ('a1','a2','a3','a4','a5'),
    ('b1','b2','b3','b4','b5');

    加入索引:

    alter table t add index c1234(c1,c2,c3,c4);

    对第一种情况:说明c1,c2,c3。c4被使用


    稍作改变:



    使用group by 一般先生成暂时文件。在进行排序


    order by 哪?同上面类似啦


    略微改变一下,分析:知道原理都非常easy啦!


    上面问题答案是多少?反正我是不知道!

    总结规律可得:



  • 相关阅读:
    JS常用自定义方法
    mybatis like用法
    设计模式之前之UML
    DSU模板(树的启发式合并)
    【hihocoder编程练习赛9】闰秒
    静态链接与动态链接的区别【转】
    pragma指令详解(转载)
    Crawl(2)
    Crawl(1)
    Treap
  • 原文地址:https://www.cnblogs.com/claireyuancy/p/6736100.html
Copyright © 2011-2022 走看看