时间:2021-07-01 10:21:17 帮助过:95人阅读
同事发来2个语句,说语句1跑得慢,语句2很快就出结果。一执行,果然很慢。仔细发现,2个语句不等价。 语句1: select l.*,o.object_name from v$locked_object l left join all_objects o on l.object_id=o.object_id;语句2: select l.*,o.object_name from
同事发来2个语句,说语句1跑得慢,语句2很快就出结果。一执行,果然很慢。仔细发现,2个语句不等价。
语句1:select l.*,o.object_name from v$locked_object l left join all_objects o on l.object_id=o.object_id; 语句2:
select l.*,o.object_name from v$locked_object l,all_objects o where l.object_id=o.object_id;左外连接,少了一个加号,改一改语句2,使它等价为语句1.
select l.*,o.object_name from v$locked_object l,all_objects o where l.object_id=o.object_id(+);改成等价后也非常慢。
select l.*,(select o.object_name from all_objects o where l.object_id=o.object_id) from v$locked_object l;现在这种情况本身有索引了,可以改写成标量子查询,也是非常快。