【发布时间】:2016-04-19 13:25:50
【问题描述】:
现在我有一个选择查询,它基本上是 Table1 减去 table2(包括不同的记录),左连接和过滤空值。
我的查询是:
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(+)
Table1 只有唯一索引和 PK - SERIAL_NUMBER
Table2 具有唯一索引和 PK - DWH_SERIAL_KEY
和普通索引 - DWH_END_DATE, EQUIP_ACCOUNT_NUMBER, SERIAL_NUMBER。
Table1 有 13MIL 记录,table2 有更多记录,但在第一个条件(END_DATE=2999) 之后,它返回 13MIL 记录。
查询大约需要 10-25 分钟,具体取决于每天到达的数据量。
任何关于如何使其更快的想法都会被应用。
【问题讨论】:
-
您不能简单地检查
dwh_update_date是否比您上一次 ETL 处理日期更新吗? -
不,不能转发@mef
标签: sql oracle performance plsql etl