• mysql sql性能测试


    1.mysql 逗号会优化为inner join,没有区别
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test,test_ordervy where test.id=test_ordervy.Id;
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test inner join test_ordervy on test.id=test_ordervy.Id;
    
    
    2.inner join 时条件写到on 和where都行
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test inner join test_ordervy on test.id=test_ordervy.Id
    and test.Id=2;
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test inner join test_ordervy on test.id=test_ordervy.Id
    where test.Id=2;
    
    3. left join right join ,条件需要写到where 后,写到on有性能问题和结果集不合符逾期问题
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test left join test_ordervy on test.id=test_ordervy.Id
    and test.id=2;
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test left join test_ordervy on test.id=test_ordervy.Id
    where test.id=2;
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test right join test_ordervy on test.id=test_ordervy.Id
    and test.id=2;
    
    EXPLAIN select test.id id,test.Name name,test_ordervy.Id id2,test_ordervy.Name name2 from test right join test_ordervy on test.id=test_ordervy.Id
    where test.id=2;
    
    4.尽量以小结果集为驱动表,left join 坐表为驱动表,right join 右表为驱动表
    
     
  • 相关阅读:
    一篇文章让你了解GC垃圾回收器
    使用SpringBoot整合ssm项目
    SpringBoot项目集成Hystrix
    50个简单易懂的经济学定律
    使用POI导出EXCEL工具类并解决导出数据量大的问题
    数据库事务的四大特性以及四种隔离级别
    简单了解Redis
    如何更规范化的编写JAVA 代码
    如何在Linux服务器上部署Mysql
    常见的数据库函数,关键字整理
  • 原文地址:https://www.cnblogs.com/liuqiyun/p/15921909.html
Copyright © 2020-2023  润新知