Sql 提高SELECT性能

Sql 提高SELECT性能,sql,oracle,performance,plsql,etl,Sql,Oracle,Performance,Plsql,Etl,现在我有一个select查询,它基本上是表1减去表2(包括不同的记录)、左连接和过滤空值 我的问题是: SELECT table1.serial_number, table1.equip_account_number, table1.equip_service_address_id, table1.equip_ani_phone_number, table1.equip_part_number, table1.equ

现在我有一个select查询,它基本上是表1减去表2(包括不同的记录)、左连接和过滤空值

我的问题是:

SELECT table1.serial_number, 
       table1.equip_account_number, 
       table1.equip_service_address_id, 
       table1.equip_ani_phone_number, 
       table1.equip_part_number, 
       table1.equip_polled_date, 
       table1.equip_zone_map, 
       table1.equip_return_value, 
       table1.equip_renewal_frequency, 
       table1.equip_last_renewal_date, 
       table1.equip_in_stock_date, 
       table1.equip_assigned_addresses, 
       table1.equip_link_to_serial_number, 
       table1.equip_converter_type, 
       table1.equip_converter_id, 
       table1.equip_converter_model, 
       table1.equip_converter_options, 
       table1.equip_converter_value, 
       table1.equip_emp_code, 
       table1.equip_vendor_code, 
       table1.equip_headend_code, 
       table1.equip_distributor_code, 
       table1.equip_manufacturer_code, 
       table1.equip_location_code, 
       table1.equip_group_code, 
       table1.equip_ownership_code, 
       table1.equip_secondary_conv_info, 
       table1.equip_secondary_conv_type, 
       table1.equip_second_conv_manufacturer, 
       table1.equip_second_conv_install_date, 
       table1.call_back_cycle_day, 
       table1.call_back_last_date, 
       table1.call_back_request_date, 
       table1.trx_equip_status_code, 
       table1.trx_equip_reason_code, 
       table1.tv_ind, 
       table1.int_ind, 
       table1.tel_ind, 
       table1.dwh_create_date, 
       table1.dwh_update_date, 
       table1.equip_outlet_location_code, 
       table1.equip_return_date_due, 
       table1.equip_unrecovered_ind, 
       table1.equip_delete_date, 
       table1.install_date, 
       table1.work_order_number, 
       table1.ds_work_order_number, 
       table1.disconnect_emp_code, 
       table1.disconnect_date, 
       table1.ds_equip_location, 
       table1.equip_active_in_tv_ind, 
       table1.equip_active_in_tel_ind, 
       table1.equip_active_in_int_ind, 
       table1.equip_active_intv_change_date, 
       table1.equip_active_intel_change_date, 
       table1.equip_active_inint_change_date, 
       table1.pirat_ind, 
       table1.pirat_ind_change_date, 
       table1.equip_owner 
FROM   dim_equip, 
       scd_equip 
WHERE  table2.dwh_end_date(+) = To_date('31/12/2999', 'DD/MM/YYYY') 
       AND ( table2.serial_number IS NULL 
              OR ( table1.equip_account_number <> table2.equip_account_number 
                    OR table1.equip_service_address_id <> 
                       table2.equip_service_address_id 
                    OR table1.equip_ani_phone_number <> 
                       table2.equip_ani_phone_number 
                    OR table1.equip_part_number <> table2.equip_part_number 
                    OR table1.equip_polled_date <> table2.equip_polled_date 
                    OR table1.equip_zone_map <> table2.equip_zone_map 
                    OR table1.equip_return_value <> table2.equip_return_value 
                    OR table1.equip_renewal_frequency <> 
                       table2.equip_renewal_frequency 
                    OR table1.equip_last_renewal_date <> 
                       table2.equip_last_renewal_date 
                    OR table1.equip_in_stock_date <> table2.equip_in_stock_date 
                    OR table1.equip_assigned_addresses <> 
                       table2.equip_assigned_addresses 
                    OR table1.equip_link_to_serial_number <> 
                       table2.equip_link_to_serial_number 
                    OR table1.equip_converter_type <> 
                       table2.equip_converter_type 
                    OR table1.equip_converter_id <> table2.equip_converter_id 
                    OR table1.equip_converter_model <> 
                       table2.equip_converter_model 
                    OR table1.equip_converter_options <> 
                       table2.equip_converter_options 
                    OR table1.equip_converter_value <> 
                       table2.equip_converter_value 
                    OR table1.equip_emp_code <> table2.equip_emp_code 
                    OR table1.equip_vendor_code <> table2.equip_vendor_code 
                    OR table1.equip_headend_code <> table2.equip_headend_code 
                    OR table1.equip_distributor_code <> 
                       table2.equip_distributor_code 
                    OR table1.equip_manufacturer_code <> 
                       table2.equip_manufacturer_code 
                    OR table1.equip_location_code <> table2.equip_location_code 
                    OR table1.equip_group_code <> table2.equip_group_code 
                    OR table1.equip_ownership_code <> 
                       table2.equip_ownership_code 
                    OR table1.equip_secondary_conv_info <> 
                       table2.equip_secondary_conv_info 
                    OR table1.equip_secondary_conv_type <> 
                       table2.equip_secondary_conv_type 
                    OR table1.equip_second_conv_manufacturer <> 
                       table2.equip_second_conv_manufacturer 
                    OR table1.equip_second_conv_install_date <> 
                       table2.equip_second_conv_install_date 
                    OR table1.call_back_cycle_day <> table2.call_back_cycle_day 
                    OR table1.call_back_last_date <> table2.call_back_last_date 
                    OR table1.call_back_request_date <> 
                       table2.call_back_request_date 
                    OR table1.trx_equip_status_code <> 
                       table2.trx_equip_status_code 
                    OR table1.trx_equip_reason_code <> 
                       table2.trx_equip_reason_code 
                    OR table1.tv_ind <> table2.tv_ind 
                    OR table1.int_ind <> table2.int_ind 
                    OR table1.tel_ind <> table2.tel_ind 
                    OR table1.equip_outlet_location_code <> 
                       table2.equip_outlet_location_code 
                    OR table1.equip_return_date_due <> 
                       table2.equip_return_date_due 
                    OR table1.equip_unrecovered_ind <> 
                       table2.equip_unrecovered_ind 
                    OR table1.equip_delete_date <> table2.equip_delete_date 
                    OR table1.install_date <> table2.install_date 
                    OR table1.work_order_number <> table2.work_order_number 
                    OR table1.ds_work_order_number <> 
                       table2.ds_work_order_number 
                    OR table1.disconnect_emp_code <> table2.disconnect_emp_code 
                    OR table1.disconnect_date <> table2.disconnect_date 
                    OR table1.ds_equip_location <> table2.ds_equip_location 
                    OR table1.equip_active_in_tv_ind <> 
                       table2.equip_active_in_tv_ind 
                    OR table1.equip_active_in_tel_ind <> 
                       table2.equip_active_in_tel_ind 
                    OR table1.equip_active_in_int_ind <> 
                       table2.equip_active_in_int_ind 
                    OR table1.equip_active_intv_change_date <> 
                       table2.equip_active_intv_change_date 
                    OR table1.equip_active_intel_change_date <> 
                       table2.equip_active_intel_change_date 
                    OR table1.equip_active_inint_change_date <> 
                       table2.equip_active_inint_change_date 
                    OR table1.pirat_ind <> Nvl(table2.pirat_ind, 0) 
                    OR table1.pirat_ind_change_date <> 
                       NVL(table2.pirat_ind_change_date, 
                       TO_DATE('01/01/0001', 'DD/MM/YYYY')) 
                    OR table1.equip_owner <> table2.equip_owner) )  
       AND table1.serial_number = table2.serial_number(+) 
选择表1.序列号,
表1.1设备账号,
表1.设备、服务、地址、id、,
表1.1设备和电话号码,
表1.设备零件号,
表1.1调查日期,
表1.1设备分区图,
表1.1设备返回值,
表1.1设备更新频率,
表1.1设备最后更新日期,
表1.设备库存日期,
表1.1设备分配的地址,
表1.设备链接到序列号,
表1.1.1配备转换器类型,
表1.1设备转换器id,
表1.1.1配备转换器的型号,
表1.配备转换器选项,
表1.1转换器的配置值,
表1.1设备emp代码,
表1.1设备供应商代码,
表1.1设备头端代码,
表1.1.设备/分销商/代码,
表1.1设备制造商代码,
表1.1设备位置代码,
表1.1设备组代码,
表1.1设备所有权代码,
表1.设备、辅助设备、转换信息,
表1.设备、二次设备、转换类型,
表1.2第二个制造商的设备,
表1.第二次安装日期,
表1.回拨周期日,
表1.回拨上次日期,
表1.回拨请求日期,
表1.trx\U设备状态\U代码,
表1.trx\U设备\U原因\U代码,
表1.电视工业,
表1.1国际工业,
表1.电话工业,
表1.dwh_创建日期,
表1.dwh_更新日期,
表1.设备、插座、位置、代码,
表1.1设备归还日期到期日,
表1.未回收的设备,
表1.1设备删除日期,
表1.1安装日期,
表1.工作单编号,
表1.ds\U工作订单号,
表1.1断开emp代码,
表1.1日期,
表1.ds\U设备位置,
表1.在电视工业中配备有源,
表1.在电话工业中配备活动设备,
表1.在国际工业中配备主动式,
表1.设备启用日期、国际变更日期、,
表1.1装备、激活、情报、更改、日期,
表1.1设备启用变更日期,
表1.海盗工业,
表1.盗版标识变更日期,
表1.1业主
从dim_Equipment,
scd_设备
其中表2.dwh结束日期(+)=截止日期('31/12/2999','DD/MM/YYYY'))
和(表2.序列号为空
或(表1.装备帐号表2.装备帐号
或表1.1设备\服务\地址\ id
表2.设备、服务、地址、id
或表1.1.1电话号码
表2.1设备和电话号码
或表1.设备零件号表2.设备零件号
或表1.装备轮询日期表2.装备轮询日期
或表1.装备区地图表2.装备区地图
或表1.装备返回值表2.装备返回值
或表1.1设备更新频率
表2.1设备更新频率
或表1.1上次更新日期
表2.2设备上次更新日期
或表1.装备库存日期表2.装备库存日期
或表1.1.设备分配的地址
表2.1设备分配的地址
或表1.设备链接到序列号
表2.设备链接到序列号
或表1.1.1.1.1.1.1.1.1.1.1.1.1.1.2.2.2.2.2.1.1.1.1.1.2.2.2.2.2.1.2.2.2.2.2.2.2.1.2.2.2.2.1.2.2.2.1.2.2.2.2.1.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.1
表2.2.1转换器类型
或表1.Equipment\u converter\u id表2.Equipment\u converter\u id
或表1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.2.2.1
表2.2.1配备的转换器型号
或表1.配备转换器选项
表2.1配备转换器选项
或表1.1.1转换器值
表2.2.1转换器的配置值
或表1.装备电磁脉冲代码表2.装备电磁脉冲代码
或表1.设备供应商代码表2.设备供应商代码
或表1.Equipment\u headend\u code表2.Equipment\u headend\u code
或表1.1.2\u经销商代码
表2.2.1配电盘代码
或表1.1设备制造商代码
表2.1设备制造商代码
或表1.设备位置代码表2.设备位置代码
或表1.设备组代码表2.设备组代码
或表1.1设备所有权代码
表2.1设备所有权代码
或表1.设备、辅助设备和控制信息
表2.设备、辅助设备、转换信息
或表1.2.2.2.1.2.2.2.2.1.2.2.2.1.2.2.2.2.2.1.2.2.2.2.2.2.2.2.2.2.2.2.2
表2.设备、二次设备和转换类型
或表1.第二个制造商的设备
表2.2第二个设备制造商
或表1.第二次安装日期
表2.第二次安装日期
或表1.回拨循环日表2.回拨循环日
或表1.回拨上次日期表2.回拨上次日期
或表1.回拨请求日期
表2.回拨请求日期
或表1.trx\U设备状态\U代码
表2.trx\U设备状态\U代码
或表1.trx\u设备\u原因\u代码
表2.trx\U设备\U原因\U代码
或表1.tv\u ind表2.tv\u ind
或表1.int_ind表2.int_ind
或表1.tel\u ind表2.tel\u ind
或表1.equi
  AND ( table2.serial_number IS NULL 
          OR ( table1.equip_account_number <> table2.equip_account_number 
                OR table1.equip_service_address_id <> 
                   table2.equip_service_address_id 
                OR table1.equip_ani_phone_number <> 
                   table2.equip_ani_phone_number ...
                 ......
SELECT table1.serial_number, 
   table1.equip_account_number, 
   table1.equip_service_address_id, 
   table1.equip_ani_phone_number, 
   table1.equip_part_number, 
   ......
   ......
   table1.pirat_ind, 
   table1.pirat_ind_change_date, 
   table1.equip_owner 
FROM   table1, 


minus 

select table2.serial_number, 
   table2.equip_account_number, 
   table2.equip_service_address_id, 
   table2.equip_ani_phone_number, 
   table2.equip_part_number, 

WHERE  table2.dwh_end_date(+) = To_date('31/12/2999', 'DD/MM/YYYY') 
   AND table2.serial_number IS NULL;
  SELECT table1.serial_number, 
     table1.equip_account_number, 
     table1.equip_service_address_id, 
     table1.equip_ani_phone_number, 
     table1.equip_part_number, 
     ......
     ......
     table1.pirat_ind, 
     table1.pirat_ind_change_date, 
     table1.equip_owner 
   FROM   table1

    minus 

  select table2.serial_number, 
         table2.equip_account_number, 
         table2.equip_service_address_id, 
         table2.equip_ani_phone_number, 
         table2.equip_part_number, 
         ......
         table2.equip_owner
  From   table2
  WHERE  table2.dwh_end_date(+) = To_date('31/12/2999', 'DD/MM/YYYY'); 
ora_hash(equip_account_number||equip_service_address_id||equip_ani_phone_number||...||equip_owner)
SELECT *
FROM table1 tb1, 
   ( -- this subquery compares record from both tables and returns the serial_number of all new/modified records inside table1
    SELECT table1.serial_number, 
       table1.record_hash 
     FROM   table1
  
      minus 
  
    select table2.serial_number, 
       table2.record_hash
    From   table2
    WHERE  table2.dwh_end_date = to_date('31/12/2999', 'DD/MM/YYYY')
    ) diff
 where diff.serial_number = tb1.serial_number