- 最后登录
- 2016-4-27
- 在线时间
- 84 小时
- 威望
- 87
- 金钱
- 846
- 注册时间
- 2012-2-22
- 阅读权限
- 50
- 帖子
- 101
- 精华
- 1
- 积分
- 87
- UID
- 253
|
1#
发表于 2012-5-10 13:36:29
|
查看: 4776 |
回复: 2
现在有可问题,观察执行计划时发现在NL join 中驱动表选择有点问题,默认运行是1分40秒,加了ordered hint更换驱动表后大概是40秒,做了10053 level 1 trace ,我的问题是如果找出cbo 是如何判断在NL JOIN中用哪个表做out table的。
默认cbo的执行计划
select /*+ gather_plan_statistics*/ count(*) total,count(distinct stu.ic_code)
hav_sc_stucn,sum(ns.class_score),stu.ic_code from icme_student stu join icme_noproject_score ns on
stu.ic_code=ns.ic_code group by stu.ic_code
Plan hash value: 1102099122
----------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------------------------------------------------
| 1 | SORT GROUP BY | | 1 | 608K| 172K|00:00:30.77 | 41M| 98M| 15M| 87M (0)|
| 2 | NESTED LOOPS | | 1 | 20M| 20M|00:02:03.45 | 41M| | | |
| 3 | INDEX FAST FULL SCAN| UK_NOPROJECT_SCORE | 1 | 20M| 20M|00:00:00.01 | 219K| | | |
|* 4 | INDEX RANGE SCAN | PK_ICME_STUDENT | 20M| 1 | 20M|00:01:25.71 | 41M| | | |
----------------------------------------------------------------------------------------------------------------------------------
select /*+ ordered */ count(*) total,count(distinct stu.ic_code) hav_sc_stucnt,sum(ns.class_score),stu.ic_code from icme_student stu
join icme_noproject_score ns on stu.ic_code=ns.ic_code
group by stu.ic_code
854409 rows selected.
Elapsed: 00:00:34.78
Execution Plan
----------------------------------------------------------
Plan hash value: 2339117530
-----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 608K| 13M| | 129K (2)| 00:26:00 |
| 1 | SORT GROUP BY | | 608K| 13M| 648M| 129K (2)| 00:26:00 |
|* 2 | HASH JOIN | | 20M| 470M| 24M| 75642 (1)| 00:15:08 |
| 3 | INDEX FAST FULL SCAN| PK_ICME_STUDENT | 1179K| 11M| | 956 (1)| 00:00:12 |
| 4 | INDEX FAST FULL SCAN| UK_NOPROJECT_SCORE | 20M| 274M| | 47986 (1)| 00:09:36 |
-----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("NS"."IC_CODE"="STU"."IC_CODE")
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
222813 consistent gets |
|