求解,这俩SQL有什么区别
RT,这俩SQL在性能上有什么区别,为什么
select b.* from a left join b on a.id=b.id where [a].id=1
select b.* from a left join b on a.id=b.id where [b].id=1
[解决办法]
执行计划 存在巨大差异
select b.* from a left join b on a.id=b.id where [a].id=1 这句逻辑读取破万
select b.* from a left join b on a.id=b.id where [b].id=1 这句逻辑读取在10以内
差异打是正常的。。。
你的第二条,执行计划给你把a.id=b.id这个条件给优化掉了,因为你的两边id都一样。
而第一条,因为where中是a.id,所以要查b.id,a.id=b.id这个条件不能省。。
顺便请教,哪位大神能教我一下,引用功能怎么用。。。点了没效果阿。。。
[解决办法]
逻辑上的顺序是你那种,但是实际上就很难说了,优化器来决定,但是逻辑上先优化是必须的,也是你能做的。语义不同,其实没什么可比性
[解决办法]
SQL 语句执行顺序
(8)SELECT (9)DISTINCT (11)<TOP_specification> <select_list>
(1)FROM <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4)WHERE <where_condition>
(5)GROUP BY <group_by_list>
(6)WITH {CUBE
[解决办法]
ROLLUP}
(7)HAVING <having_condition>
(10)ORDER BY <order_by_list>