求帮助--无索引sql语句优化

[复制链接]
查看11 | 回复5 | 2011-11-1 16:26:59 | 显示全部楼层 |阅读模式
select t1.compname,t.*
fromcode_pur_comp t1,ods_mm_matpurorder t
where t.compcode=t1.compcode
and T.YEAR=2011 ANDT.MONTH=10
AND CASE WHEN T.DELETECODE='L' THEN 1 ELSE 0 END=0
and t.bidplancode in (select distinct bidplancode from ods_mm_bidresult t2 where t2.bidplancode'201011')
AND trim(T.ORDERSTATE)='已审批'
and trim(t.vendorcode) is not null
and not exists(select b.supplier_code from ods_mm_dim_vendorinfo b where b.supplier_code=trim(t.vendorcode));
ods_mm_matpurorder表数据超过2000万, ods_mm_bidresult:7万,code_pur_comp:33条
where条件过滤后ods_mm_matpurorder表为60万
下面是执行计划
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
Plan hash value: 152620310
--------------------------------------------------------------------------------
| Id| Operation
| Name
| Rows| Bytes | Cost (%CP
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT |
| 1 | 410 | 281K(
|*1 |HASH JOIN ANTI|
| 1 | 410 | 281K(
|*2 | HASH JOIN SEMI |
| 1 | 399 | 281K(
|*3 |HASH JOIN |
| 1 | 393 | 280K(
|*4 | TABLE ACCESS FULL| ODS_MM_MATPURORDER| 1 | 367 | 280K(
| 5 | TABLE ACCESS FULL| CODE_PUR_COMP |33 | 858 | 8 (
|*6 |TABLE ACCESS FULL | ODS_MM_BIDRESULT| 67468 | 395K| 578 (
| 7 | TABLE ACCESS FULL| ODS_MM_DIM_VENDORINFO | 86210 | 926K| 294 (
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("B"."SUPPLIER_CODE"=TRIM("T"."VENDORCODE"))
2 - access("T"."BIDPLANCODE"="BIDPLANCODE")

PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------
3 - access("T"."COMPCODE"="T1"."COMPCODE")
4 - filter("T"."MONTH"=10 AND "T"."YEAR"=2011 AND TRIM("T"."VENDORCODE") IS N

NULL AND CASE "T"."DELETECODE" WHEN 'L' THEN 1 ELSE 0 END =0 AND

TRIM("T"."ORDERSTATE")='已审批' AND "T"."BIDPLANCODE"'201011')
6 - filter("T2"."BIDPLANCODE"'201011')

25 rows selected

求大侠们给点建议、、

回复

使用道具 举报

千问 | 2011-11-1 16:26:59 | 显示全部楼层
数据仓库,无索引
回复

使用道具 举报

千问 | 2011-11-1 16:26:59 | 显示全部楼层
本帖最后由 bell6248 于 2011-11-8 13:35 编辑
你的表都已经经过分析了吗?
另外表ods_mm_dim_vendorinfo数据量有多大, 还有4表的关系是如何的?
LZ,你先把4个表都分析一下,然后测试一下如下的语句, 如果可能的话,看看是否可以改下!
select /*+ leading(t1) use_hash(t1 t)*/ t1.compname, t.*
from code_pur_comp t1,
ods_mm_matpurorder t
where t.compcode = t1.compcode
and T.YEAR = 2011
AND T.MONTH = 10
and decode(T.DELETECODE, 'L', 1, 0) = 0
and trim(T.ORDERSTATE) = '已审批'
and trim(t.vendorcode) is not null
and not exists(select 1 from ods_mm_dim_vendorinfo b where b.supplier_code = trim(t.vendorcode))
and exists(select 1 from ods_mm_bidresult t2 where t2.bidplancode = t.bidplancode and t2.bidplancode'201011');

回复

使用道具 举报

千问 | 2011-11-1 16:26:59 | 显示全部楼层
谢谢版主、表分析过了,用您的SQL,加hint改变code_pur_comp,ods_mm_matpurorder连接顺序快了20秒,另外加索引的话有什么建议


回复

使用道具 举报

千问 | 2011-11-1 16:26:59 | 显示全部楼层
suisui0926 发表于 2011-11-8 14:01
谢谢版主、表分析过了,用您的SQL,加hint改变code_pur_comp,ods_mm_matpurorder连接顺序快了20秒,另外加索 ...

你目前是基于OLAP的,因此数据的吞吐量是非常huge的, 对表建立合理的INDEX是解决目前语句执行效率的的最有效的方法,置于如何建立, 要更具具体的整体业务的和数据模型了!
回复

使用道具 举报

千问 | 2011-11-1 16:26:59 | 显示全部楼层
suisui0926 发表于 2011-11-8 14:01
谢谢版主、表分析过了,用您的SQL,加hint改变code_pur_comp,ods_mm_matpurorder连接顺序快了20秒,另外加索 ...

列一下调整后的执行计划,
另外你需要看一下你的2000万的表每关联一次会减少多少数据量。
你的大表比方是t1,
然后起到过滤作用的有t2,t3,t4三个表
那么你有3*2共6种顺序,
另外exists和not exists也可以调整为in和not in走hash anti和hash semi的,
你的in可以先distinct然后作为联接使用,not in也可以先distinct然后用外联接,然后is null使用的,
问题的关键是越早过滤掉不需要的数据越好。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行