当前位置: 首页 > news >正文

MySQL系列---sql优化

目录标题

  • join时以大表为基表

join时以大表为基表

  • 查不动

    explain  select u.id as useId, u.open_id as userOpenId, u.name as userName, u.phone as userPhone, s.id as shopId, s.shop_id as shopNum, s.shop_name as shopName from jml_mp_wechatuser u right join jml_shop s on u.id = shopkeeper_id where u.phone = '6D26B768750A90426AAA4CE04FA4CCBB'
    

    在这里插入图片描述

  • 查不动

    EXPLAIN select u.id as useId, u.open_id as userOpenId, u.name as userName, u.phone as userPhone, s.id as shopId, s.shop_id as shopNum, s.shop_name as shopName from jml_shop s LEFT JOIN jml_mp_wechatuser u on u.id = s.shopkeeper_id where u.phone = '6D26B768750A90426AAA4CE04FA4CCBB'
    

    在这里插入图片描述

  • 5s

    EXPLAIN select u.id as useId, u.open_id as userOpenId, u.name as userName, u.phone as userPhone, s.id as shopId, s.shop_id as shopNum, s.shop_name as shopName from jml_shop s LEFT JOIN jml_mp_wechatuser u on u.open_id = s.shopkeeper_openid where u.phone = '6D26B768750A90426AAA4CE04FA4CCBB'
    

    在这里插入图片描述

  • 3s

    explain  select u.id as useId, u.open_id as userOpenId, u.name as userName, u.phone as userPhone, s.id as shopId, s.shop_id as shopNum, s.shop_name as shopName from jml_mp_wechatuser u left join jml_shop s on u.id = shopkeeper_id where u.phone = '6D26B768750A90426AAA4CE04FA4CCBB'
    

    在这里插入图片描述

  • 4s

    explain  select u.id as useId, u.open_id as userOpenId, u.name as userName, u.phone as userPhone, s.id as shopId, s.shop_id as shopNum, s.shop_name as shopName from jml_mp_wechatuser u left join jml_shop s on u.open_id = s.shopkeeper_openid where u.phone = '6D26B768750A90426AAA4CE04FA4CCBB'
    

    在这里插入图片描述

A left join B = B right join A; join的原理是以基准表为底,根据on的条件for循环去另一张表找到等值进而关联。所以显而易见,影响join效率的是等值的长度及for循环次数。以大表为基准可以有效减少for循环次数,选取主键关联可以更快的判断等值。

如何join? on主键+大表为基准!


http://www.mrgr.cn/news/61196.html

相关文章:

  • Unity Protobuf实践
  • power shell 2
  • 嘉立创画原理图和PCB
  • ffmpeg7.0 aac转pcm
  • React前端框架:构建现代Web应用的强大工具
  • 2024AAAI SCTNet论文阅读笔记
  • qq流量分析(渗透课作业)
  • PBKDF2算法:一种基于密码的密钥派生算法
  • VQ-VAE(2018-05:Neural Discrete Representation Learning)
  • png怎么转换成jpg格式?将png格式转换成jpg格式的几个方法推荐
  • 21世纪20年代了, 居然遭遇扩容U盘!
  • Jenkins+RobotFramework 失败用例重执行方案
  • 串口调试工具
  • 人工智能图谱
  • java基础练习:三天打鱼,两天晒网
  • AI(10)-瓶子logo
  • JS中的正则表达式
  • 高压线路覆冰厚度测量,输电线路微波覆冰监测装置守护电网安全
  • 后端检测_文件头检测漏洞
  • 线上问题排查@Transactional事务失效
  • 探索 Python 异步库的神秘力量:sniffio 库全解析
  • 鸿蒙开发 五十一 Command Line Tools 之ohpm
  • Java Lock LockSupport 总结
  • 玩转软件定义存储HBlock | 全方位体验天翼云存储资源盘活系统
  • MobileNetv2网络详解
  • 基于uniapp微信小程序的宠物救助宠物领养系统