Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Slow hierarchical query

783568Feb 9 2011 — edited Feb 9 2011
Hello
I wrote a query that enables the user to filter the displayed data according to several parameters, one of the parameters (b) is hierarchical e.g. every item (except from the root item) has a father and several sons, the hierarchy is managed by a specific table (LINKS), I need that when the user select b the result will also include all its descendants.

This is the query:

SELECT *
FROM R
INNER JOIN RT ON R.A = RT.A
WHERE (R.B IN (select sub_id
from LINKS start with father_id = :id
connect by prior sub_id= father_id)
or R.B = :id or :id = 0)
AND (R.A= :a OR :a=0)
ORDER BY R.B, R.A

The problem is that the query is so slow it makes the application to stuck, when I omitted the line: "or R.B = :id or :id = 0" it did'nt stuck but this line is necessary since the user can also leave the filter field empty or try to filter to b itself and not to its descendants.

Is there a way to improve this query performance or to write it better?
This post has been answered by Sven W. on Feb 9 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 9 2011
Added on Feb 9 2011
2 comments
326 views