SQL优化案例一则,insert到临时表的sql优化余地

来源:互联网 发布:软件广告语 编辑:程序博客网 时间:2024/05/06 06:18

问题SQL,报上来看有没优化的余地。

9it0epcis库,

这个sql是上生产了,但是没有开quartz开关;所以这次上线将会打开,需要优化该sql;请协助支持!

 

INSERT /* +APPEND */ INTO ECIF_GROP_DEPART_ADD_TMP

    select distinct /*+ parallel(o,8)*/    o.created_by,o.created_date,o.updated_by,o.updated_date,

             o.client_no,

             o.client_name,

             o.org_code_no,

             o.tax_no,

             o.business_register_no,

             o.other_certificate_no,

       o.address,

             n.department_code,

             o.client_no||n.department_code as rel_no,

             o.updated_date as add_date,

             '0'

      from ecif_client_organization_info o ,cicsdata.ecif_policy_client_relation n

      where o.client_no=n.client_no(+) and  o.updated_date >= to_date('2014-03-10','yyyy-mm-dd')  

      and   o.updated_date<(to_date('2014-03-10','yyyy-mm-dd')+1)  AND n.department_code is not null

执行计划:


 

驱动表:

Cicsdata.ecif_client_organization_info

2g,hash分区表,分区键是CLIENT_NO

 

驱动表行数不多,才28行,走nest loop没问题。

select count(*) from ecif_client_organization_info o where o.updated_date >= to_date('2014-03-10','yyyy-mm-dd')  and   o.updated_date<(to_date('2014-03-10','yyyy-mm-dd')+1)

--28

 

被驱动表

CICSDATA.ECIF_POLICY_CLIENT_RELATION

统计信息:343567876行,2011311日采集。

实际:该表145G

 

IX_ECIF_P_C_RELATION_C_NO_ROLE索引

统计信息:342787981行,聚簇因子:302798887

38G,复合b*tree索引,(CLIENT_NOCLIENT_ROLE

 

 

总结:

关于Hint改进的意见:

Parallel hint没用得上,这里走索引不能用这个hint,这个hint是并行表的。

Append hint 改成/*+APPEND */*+之间别有空格。

如果还想有所改进,可以在CICSDATA.ECIF_POLICY_CLIENT_RELATION表建单列索引(CLIENT_NO),但是必要性不是很大,建多了索引也有维护成本。

另外该索引可以尝试重建,重建完clustering_factor会变小,对随机读取有帮助。


改进完后,执行计划。

INSERT /*+APPEND */ INTO ECIF_GROP_DEPART_ADD_TMP

    select distinct   o.created_by,o.created_date,o.updated_by,o.updated_date,

             o.client_no,

             o.client_name,

             o.org_code_no,

             o.tax_no,

             o.business_register_no,

             o.other_certificate_no,

       o.address,

             n.department_code,

             o.client_no||n.department_code as rel_no,

             o.updated_date as add_date,

             '0'

      from ecif_client_organization_info o ,cicsdata.ecif_policy_client_relation n

      where o.client_no=n.client_no(+) and  o.updated_date >= to_date('2014-03-10','yyyy-mm-dd')  

      and   o.updated_date<(to_date('2014-03-10','yyyy-mm-dd')+1)  AND n.department_code is not null

0 0
原创粉丝点击