暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Mysql精华问答(五)| explain 进行Sql分析

海兴视点 2021-05-25
477


    {EXPLAIN | DESCRIBE | DESC}
    tbl_name [col_name | wild]


    {EXPLAIN | DESCRIBE | DESC}
    [explain_type]
    {explainable_stmt | FOR CONNECTION connection_id}


    explain_type: {
    EXTENDED
    | PARTITIONS
    | FORMAT = format_name
    }


    format_name: {
    TRADITIONAL
    | JSON
    }


    explainable_stmt: {
    SELECT statement
    | DELETE statement
    | INSERT statement
    | REPLACE statement
    | UPDATE statement
    }

      explain  select * from test1 t1 inner  join test1 t2 on t1.id=t2.id

      结果:

        explain  select * from test1 t1 where t1.id = (select  id  from  test1 t2 where  t2.id=2);

        结果:

          explain 
          select t1.* from test1 t1
          inner join (select max(id) mid from test1 group by id) t2
          on t1.id=t2.mid

          结果:

            explain select * from test1;

            结果:

              explain select * from test1 t1 where t1.id = (select id from  test1 t2 where  t2.id=2);

              结果:

                explain
                select t1.* from test1 t1
                inner join (select max(id) mid from test1 group by id) t2
                on t1.id=t2.mid

                结果:

                  explain
                  select * from test1
                  union
                  select* from test2

                  结果:

                    explain select * from test2 where id=1;

                    结果:

                      explain select * from test2 t1 inner join test2 t2 on t1.id=t2.id;

                      结果:

                        explain select * from test2 where code = '001';

                        结果:

                          explain select *  from test1 t1 inner join test1 t2 on t1.id=t2.id where t1.code='001';







                          END



                          来源 | 捡田螺的小男孩



                          扫描二维码

                          获取更多精彩

                          海兴破颈记


                          文章转载自海兴视点,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

                          评论