I am trying to fetch data from remote table. The data is expanded from seed set of data in local table using recursive CTE. The query is very slow (300 seed rows to 800 final rows takes 7 minutes).
For other "tiny local, huge remote"-cases with no recursive query the DRIVING_SITE
hint works excellently. I also tried to export seed set from local table into auxiliary table on remotedb
with same structure and - being logged in remotedb
- ran query as pure local query (my_table
as p
, my_table_seed_copy
as i
). It took 4s, which encouraged me to believe forcing query to remote site would make query fast.
What's the correct way to force Oracle to execute recursive query on the remote site?
with s (id, data) as (
select p.id, p.data
from my_table@remotedb p
where p.id in (select i.id from my_table i)
union all
select p.id, p.data
from s
join my_table@remotedb p on ...
)
select /*+DRIVING_SITE(p)*/ s.*
from s;
In the query above, I tried
select /*+DRIVING_SITE(p)*/ s.*
in main selectselect /*+DRIVING_SITE(s)*/ s.*
in main select- omitting
DRIVING_SITE
in whole query select /*+DRIVING_SITE(x)*/ s.* from s, dual@remotedb x
as main selectselect /*+DRIVING_SITE(p)*/ p.id, p.data
in first inner selectselect /*+DRIVING_SITE(p)*/ p.id, p.data
in both inner selectsselect /*+DRIVING_SITE(p) MATERIALIZE*/ p.id, p.data
in both inner selects- (just for completeness - rewriting to
connect by
is not applicable for this case - actually the query is more complex and uses constructs which cannot be expressed byconnect by
)
All without success (i.e. data returned after 7 minutes).