【发布时间】:2016-06-23 12:10:34
【问题描述】:
我目前有一个需要很长时间(一个小时+-)的过程。
这个过程基本上是这样的:
首先,它从一个表连接到一个视图 -
SELECT * FROM
STG_CRM, V_CRM
WHERE
STG_CRM.CRM_CASE_ID=V_CRM.CASE_ID(+)
视图 DDL:
create or replace view stg_admin.v_crm as
select t.case_id
from crm_case t, dim_crm x
where t.case_id=x.crm_case_id;
STG_CRM - 20 万条记录 - 无索引。
DIM_CRM - 90MIL 条记录 - 已编入索引(crm_case_id - 唯一)。
CRM_CASE - 20 万条记录 - 无索引。
到目前为止,一切都还不是很重(大约 2-3 分钟),然后有一个左连接到另一个 VIEW ,这是当前最重的选择(只需从视图中选择 * 是 10 分钟)。
查看 DDL - 我目前正在考虑两个不同的查询:
select t.crm_case_id,s.customer_key
from stg_crm t, stg_scd s
where t.account_number=s.account_number
and t.case_create_date between s.start_date and s.end_date;
或者:
select t.crm_case_id,
(select min(s.customer_key) keep (dense_rank first order by s.end_date asc)
from stg_scd s
where t.account_number = s.account_number and
t.case_create_date <= s.end_date
) as customer_key
from stg_crm t
表 stg_scd - 500MIL 条记录索引(customer_key,start_date,end_date) - 每天按 end_date 唯一分区。
现在这两个查询都需要很长时间,第二个更长一点。我的猜测是因为它没有使用索引,因为 start_date 没有用于过滤,但我不知道如何添加它。
我的问题是:我怎样才能让它更快?如果我在 create_date 的 STG_CRM 上添加索引,会有帮助吗?(我什至不知道 DBA 是否允许)因为这是小表。
限制:
- 我无法更改大表 (STG_SCD) 上的索引
- 我也许可以在其他表上添加索引,但只有在给出充分理由的情况下,因为它会损害使用此表的其他进程的性能。
隐式连接语法是通过我的程序生成的,所以这里不需要cmets。
提前非常感谢!
附:第一个选择左连接到第二个选择大约需要 30-60 分钟。
【问题讨论】:
-
请,请,请迁移到使用 ANSI 标准联接并停止使用旧的 Oracle 逗号联接。
-
@MT0 在说这样的话之前,请阅读倒数第三行...
-
我建议创建一个索引为
CREATE INDEX IND1 ON stg_crm (account_number, case_create_date)和(可能更重要)CREATE INDEX IND2 ON stg_crm (account_number)
标签: sql oracle performance indexing oracle11g