The colleague sent two statements, saying that statement 1 is slow, and Statement 2 is very fast. 1. Execution is really slow. It is found that the two statements are not equivalent.
Statement 1:
select l.*,o.object_name from v$locked_object l left join all_objects o on l.object_id=o.object_id;
Statement 2:
select l.*,o.object_name from v$locked_object l,all_objects o where l.object_id=o.object_id;
If the outer left join is missing a plus sign, modify Statement 2 to make it equivalent to Statement 1.
Statement 3:
select l.*,o.object_name from v$locked_object l,all_objects o where l.object_id=o.object_id(+);
It is also very slow to change to an equivalent value.
Although Statement 2 is not equivalent, why is Statement 2 faster than Statement 1 and Statement 3? After reading the execution plan for a while, I understood it. In statement 1, OBJ $ uses the entire table, and in statement 2, OBJ $ uses the index.
The performance bottleneck is mainly because all_objects is very slow. It took more than 15 minutes to count and there was more than million data.
Only 80 data records are returned.
What are the methods to optimize scalar queries?
One is index optimization and the other is external connections.
Isn't the performance of scalar quantum queries worse than external connections at any time.
The following statement is used to convert a scalar quantum query.
Statement 4:
select l.*,(select o.object_name from all_objects o where l.object_id=o.object_id) from v$locked_object l;
Now that this situation is indexed, you can rewrite it into a scalar quantum query, which is also very fast.
Avoiding the full table of OBJ $, all_objects has more than records
After rewriting, it is equivalent to the meaning of the original left Outer Join. Results are output within 2 seconds at a high speed.
Standard Quantum query to optimize external connections