user_info 表有 1000 条数据 主表 字段 id name
user_level 表有 100 条数据 匹配表 字段 user_id level

没有索引的连接查询

select * from user_info ui
left join user_level ul on ui.id=ul.user_id

user_info 表会查询 1000次 user_level 表会查询 1000*100=100000 次

MySQL连接查询原理
有索引的连接查询(被匹配表加索引)
select * from user_info uileft join user_level ul on ui.id=ul.user_id

当 被匹配表 user_level 的 user_id 有索引时,会先根据 user_info 的 id 值去
user_id 索引数据结构查询相应的数据,然后得到列,这样 user_level 只会查询 100次

MySQL连接查询原理

图片是从别的地方复制来的

相关文章:

  • 2021-11-03
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
猜你喜欢
  • 2021-12-23
  • 2021-11-19
  • 2021-10-01
  • 2021-09-13
  • 2021-07-15
相关资源
相似解决方案