通过DBLINK select 快,CTAS 快,Insert 慢 (Doc ID 732999.1)

Select statement using DBlinks works fine, but issuing insert into a table using the same select statement  hangs.
 

SQL> select distinct parloc.country gto_loc,
par.organization_id gto_org_id,
par.organization gto_org_name,
par.org_manager_number gto_mgr_num,
par.org_manager_name gto_mgr_name,
par.hr_manager_number gto_hrm_num,
par.hr_manager_name gto_hrm_name,
'',
loc.country org_loc,
org.organization_id org_id,
org.organization org_name,
org.org_manager_number org_mgr_num,
org.org_manager_name org_mgr_name,
org.hr_manager_number org_hrm_num,
org.hr_manager_name org_hrm_name,
'',
'',
'',
'999999999',
Sysdate
from crdohr.crdohr_person@ORDWHR10 per,
crdohr.crdohr_organization@ORDWHR10 org,
crdohr.crdohr_organization@ORDWHR10 par,
crdohr.crdohr_location@ORDWHR10 loc,
crdohr.crdohr_location@ORDWHR10 parloc
where per.curr_sub_business_group = 'GE Global Research'
and per.termination_date is null
and per.curr_band <> 'PEN'
and per.curr_org_id = org.organization_id
and org.location_id = loc.location_id
and org.PARENT_ORG_ID = par.organization_id
and par.location_id = parloc.location_id
and org.org_manager_number = '302000930'

Returns 1 row, however :

SQL> insert into testnow
select distinct parloc.country gto_loc,
par.organization_id gto_org_id,
par.organization gto_org_name,
par.org_manager_number gto_mgr_num,
par.org_manager_name gto_mgr_name,
par.hr_manager_number gto_hrm_num,
par.hr_manager_name gto_hrm_name,
'',
loc.country org_loc,
org.organization_id org_id,
org.organization org_name,
org.org_manager_number org_mgr_num,
org.org_manager_name org_mgr_name,
org.hr_manager_number org_hrm_num,
org.hr_manager_name org_hrm_name,
'',
'',
'',
'999999999',
Sysdate
from crdohr.crdohr_person@ORDWHR10 per,
crdohr.crdohr_organization@ORDWHR10 org,
crdohr.crdohr_organization@ORDWHR10 par,
crdohr.crdohr_location@ORDWHR10 loc,
crdohr.crdohr_location@ORDWHR10 parloc
where per.curr_sub_business_group = 'GE Global Research'
and per.termination_date is null
and per.curr_band <> 'PEN'
and per.curr_org_id = org.organization_id
and org.location_id = loc.location_id
and org.PARENT_ORG_ID = par.organization_id
and par.location_id = parloc.location_id
and org.org_manager_number = '302000930' ;

Hangs and has to be cancelled.



 

CAUSE

The analysis indicates it is an Optimizer issue.

While issuing  insert into , a MERGE JOIN CARTESIAN is being executed when stats are present for tables at the remote site.

The following Bug has been filed and is currently under Development analysis:

BUG 6656178 BAD PLAN - INSERT INTO LOCAL TABLE QUERYING REMOTE TABLES OVER DBLINK


.
With NO stats on remote tables, the Explain Plan looks like:
.

Rows Row Source Operation
------- ---------------------------------------------------
1 SORT UNIQUE (cr=0 pr=0 pw=0 time=1495541 us)
11 MERGE JOIN (cr=0 pr=0 pw=0 time=1495601 us)
1 SORT JOIN (cr=0 pr=0 pw=0 time=1401896 us)
1 MERGE JOIN (cr=0 pr=0 pw=0 time=1401801 us)
1 SORT JOIN (cr=0 pr=0 pw=0 time=1202983 us)
1 MERGE JOIN (cr=0 pr=0 pw=0 time=1202880 us)
1115 SORT JOIN (cr=0 pr=0 pw=0 time=1135187 us)
14156 MERGE JOIN (cr=0 pr=0 pw=0 time=1313453 us)
3524 SORT JOIN (cr=0 pr=0 pw=0 time=795567 us)
3524 REMOTE CRDOHR_LOCATION (cr=0 pr=0 pw=0 time=3919461 us)
14156 SORT JOIN (cr=0 pr=0 pw=0 time=395409 us)
15057 REMOTE CRDOHR_ORGANIZATION (cr=0 pr=0 pw=0 time=456765 us)
1 SORT JOIN (cr=0 pr=0 pw=0 time=67132 us)
1 REMOTE CRDOHR_ORGANIZATION (cr=0 pr=0 pw=0 time=49680 us)
1 SORT JOIN (cr=0 pr=0 pw=0 time=198776 us)
3524 REMOTE CRDOHR_LOCATION (cr=0 pr=0 pw=0 time=237013 us)
11 SORT JOIN (cr=0 pr=0 pw=0 time=93575 us)
2922 REMOTE CRDOHR_PERSON (cr=0 pr=0 pw=0 time=1151217 us)


 

SOLUTION

-- To implement the solution, please execute the following steps::

Until the referenced bug is fixed and the patch is available, implement any of the following available workarounds:

1) At remote site create a VIEW based off the local tables and at LOCAL site run INSERT into local
table as select from the remote view over dblink,

.
or
.
2) Clean out stats on remote tables,

or

3) Enforce Rule Based Optimizer (instead of CBO)

你可能感兴趣的:(数据库)