AlfieriChou / alfierichou.github.io

AlfieriChou的博客
https://alfierichou.com
4 stars 0 forks source link

MySQL千万大表优化方案 #50

Open AlfieriChou opened 1 year ago

AlfieriChou commented 1 year ago

参考文章:https://cloud.tencent.com/developer/beta/article/1705504

AlfieriChou commented 1 year ago

subquery查询可以优化成临时表关联

  1. 案例样本
    select 
    * 
    from 
    a_table 
    where 
    b in (
    select 
      b 
    from 
      d_table 
    where 
      k = '11111' 
    group by 
      b
    )

2.优化后方案

select 
  * 
from 
  a_table 
  left join (
    select 
      b 
    from 
      d_table 
    where 
      k = '11111' 
    group by 
      b
  ) as t_table on t_table.b = a_table.b