利用维对象来优化数据仓库的高级技巧
2007-05-06 12:05:52 来源:WEB开发网核心提示: CREATE DIMENSION TIME_DIMLEVEL YEAR IS (TIME_DIM.F_YEAR)LEVEL QUATER IS (TIME_DIM.F_QUATER)LEVEL MONTH IS (TIME_DIM.F_MONTH)LEVEL DAY IS (TIME_DI
CREATE DIMENSION TIME_DIM
LEVEL YEAR IS (TIME_DIM.F_YEAR)
LEVEL QUATER IS (TIME_DIM.F_QUATER)
LEVEL MONTH IS (TIME_DIM.F_MONTH)
LEVEL DAY IS (TIME_DIM.F_DAY)
HIERARCHY Y_Q_M_D
(
DAY CHILD OF
MONTH CHILD OF
QUATER CHILD OF YEAR
)
HIERARCHY Y_M_D
(
DAY CHILD OF
MONTH CHILD OF YEAR
)
/
7、建好维后, 重新跑按季度汇总或按年汇总的SQL, 看他们的执行计划有什么不同?
ASQL> SELECT D.F_QUATER,
2 SUM(F.M_AMOUNT1) M_AMMOUNT1,
3 SUM(F.M_AMOUNT2) M_AMMOUNT2
4 FROM TIME_DIM D, FACT_SALES F
5 WHERE D.F_DAY = F.F_DAY
6 GROUP BY D.F_QUATER
7 /
Execute Plan
SQLPLAN COST CARD KBYTE PS PE
----------------------------------------------------------- ---- ---- ----- -- --
0 SELECT STATEMENT Optimizer=ALL_ROWS 10 12 1
1 0 HASH (GROUP BY) 10 12 1
2 1 HASH JOIN 9 289 17
3 2 MAT_VIEW REWRITE ACCESS (FULL) OF MV_FACT_... 3 34 2
4 2 VIEW OF 5 289 4
5 4 HASH (UNIQUE) 5 289 4
6 5 TABLE ACCESS (FULL) OF TIME_DIM (TABLE) 4 999 13
ASQL> SELECT /*+ all_rows */ D.F_YEAR,
2 SUM(F.M_AMOUNT1) M_AMMOUNT1,
3 SUM(F.M_AMOUNT2) M_AMMOUNT2
4 FROM TIME_DIM D, FACT_SALES F
5 WHERE D.F_DAY = F.F_DAY
6 GROUP BY D.F_YEAR
7 /
Execute Plan
SQLPLAN COST CARD KBYTE PS PE
------------------------------------------------------------ ---- ---- ----- -- --
0 SELECT STATEMENT Optimizer=HINT: ALL_ROWS 10 4 0
1 0 HASH (GROUP BY) 10 4 0
2 1 HASH JOIN 9 97 6
3 2 MAT_VIEW REWRITE ACCESS (FULL) OF MV_FACT_S... 3 34 2
4 2 VIEW OF 5 97 1
5 4 HASH (UNIQUE) 5 97 1
6 5 TABLE ACCESS (FULL) OF TIME_DIM (TABLE) 4 999 11
我不太会用语言表解说, 因此设计了这个实例来说明, 如果看不懂, 请多看几次吧!
更多精彩
赞助商链接