Standard Quantum query to optimize external connections

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.