What is better? Subqueries or inner joining ten tables?

If I understand your question correctly, you are starting an operation to rewrite some of your SQL statements because you THINK there might be an issue with them.

My advice is to stop and first start to determine where your time is currently being spent. Only after you have found that it's in the queries with those scalar subselects AND it's because of those scalar subselects, you should be rewriting them. Until then: start tracing and examining.

Here are two threads from OTN that are used to guide people with performance problems:

http://forums.oracle.com/forums/thread.jspa?messageID=1812597 http://forums.oracle.com/forums/thread.jspa?threadID=863295

Regards,
Rob.

And: because of scalar subquery caching, your original query might be a lot faster than a rewritten query using joins.


subquery actually runs once for every row whereas the join happens on indexes.

Use joins for better readability and maintainability as you have already mentioned in your questions.

Tags:

Sql

Oracle

Select