关于连表查询的执行计划

select * from a left join b on a.id=b.id where a.createtime>xxxx;

执行计划:

如果a.createtime后的结果集比b要大,那么b作为驱动表去整合a的结果

如否,则a.createtime后的结果作为驱动表去整合b

select * from a left join b on a.id=b.id where b.createtime>xxxx;

执行计划:

如果b.createtime后的结果集比a要大,那么a作为驱动表去整合b的结果

如否,则b.createtime后的结果作为驱动表去整合a

-- EXPLAIN
SELECT
  count(1) 
FROM
  systrade_trade_cancel cc
   LEFT JOIN systrade_order o ON o.tid = cc.tid 
WHERE
  cc.shop_id =1
  and cc.created_time>1561449422

 对于上述2个表都是百万级的,这样的查询是很慢的,即使有索引,但是执行就需要百万级的驱动表去轮询匹配被驱动表。另外索引的匹配速度和表的索引总大小有关,详细可以ddl里面看索引长度。

暗夜之中,才见繁星;危机之下,暗藏转机;事在人为,为者常成。
原文地址:https://www.cnblogs.com/zenghansen/p/14930710.html