2

In Oracle, I've tried to run the same hierarchial queries in different ways : with CONNECT BY and recursive CTE. According to an execution plan CONNECT BY is preferable.

Are there any cases, when recursive CTE work faster in Oracle (or are there any situations at all where they are better be used)?

Thanks.

4

1 回答 1

3

"According to an execution plan CONNECT BY is preferable."

That isn't surprising. The CONNECT BY syntax has been part of the Oracle toolbox for decades, so Oracle has had lots of time to tweak the optimizer to handle it in a performant fashion. Recursive CTEs are newer.

Also I suspect it will be harder for the CBO to understand the cost of a recursive CTE, because they are programmatic rather than data driven.

On the other hand, lots of people (not just beginners) have problems grasping the Oracle hierarchical syntax, whereas recursion is a standard programming concept. So perhaps that's where they are useful.

Incidentally, I don't think hierarchical queries should be used in situations where performance is crucial. If you have a large amount of data you need to retrieve quickly and often in a hierarchical format you should probably consider a different approach, such as materializing the transitive closures. Find out more.

于 2013-03-31T12:44:57.590 回答