简体   繁体   English

oracle查询中的“ WITH”子句优化

[英]“WITH” clause optimization in oracle query

When I use many WITH clauses in query, it executes longer, rather than without it. 当我在查询中使用许多WITH子句时,它执行的时间更长,而不是没有它。 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. 在我的情况下,每个子查询返回大约1000万行。

With all the secrecy involved I suggest you to take a look at EXPLAIN PLAN for both queries. 考虑到所有的保密性,我建议您对两个查询都查看EXPLAIN PLAN In my opinion WITH is nothing more than syntax sugar allowing you to reuse certain sql in subqueries. 在我看来,WITH只是语法糖,它使您可以在子查询中重用某些sql。 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. 是的,10000万总是很慢。

I confirm that the WITH CLAUSE does not improve performance in Oracle databases. 我确认WITH CLAUSE不会提高Oracle数据库的性能。 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. 另外,它允许定义PL / SQL函数,以便随后在查询中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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