Optimize OR join with connect by sub query
I have a table that stores a representation of a folder hierarchy and contains about 16 million rows. An application performs queries on this table using connect by clauses. In the main these run OK, but certain end user actions can lead to the application performing a query such as below:
select * from folders where id_object in (
select id_object from folders
connect by prior id_object = id_parent
start with id_object = 'f10') or name = 'Test Folder';
The query above takes a few hours to complete, and the explain plan output indicates a full table scan of the folders table.