简体   繁体   中英

“WITH” clause optimization in oracle query

When I use many WITH clauses in query, it executes longer, rather than without it. Query structure like this:

with t1 as (select some_fields from table1 inner join table2),
     t2 as (select some_fields from t1 inner join table3),
     t3 as (select some_fields from t2 inner join table4)
select * from t3

What approach should be used for optimization of similar queries? In my case each subquery returns about 10 million rows.

With all the secrecy involved I suggest you to take a look at EXPLAIN PLAN for both queries. In my opinion WITH is nothing more than syntax sugar allowing you to reuse certain sql in subqueries. But in all it's usefulness it doesn't always lead to the most efficient plan.

and yes, 10 000 000 is always gonna be slow.

I confirm that the WITH CLAUSE does not improve performance in Oracle databases. It only allows to use query names instead of the repetition of the whole query texts.

In addition, it allows to define PL/SQL functions to be used subsequently in the query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM