WEB开发网
开发学院数据库Oracle 利用维对象来优化数据仓库的高级技巧 阅读

利用维对象来优化数据仓库的高级技巧

 2007-05-06 12:05:52 来源:WEB开发网   
核心提示: CREATE MATERIALIZED VIEW MV_FACT_SALESENABLE QUERY REWRITEASSELECT D.F_MONTH,SUM(F.M_AMOUNT1) M_AMOUNT1,SUM(F.M_AMOUNT2) M_AMOUNT2FROM TIME_DIM D
CREATE MATERIALIZED VIEW MV_FACT_SALES
ENABLE QUERY REWRITE
AS
SELECT D.F_MONTH,
SUM(F.M_AMOUNT1) M_AMOUNT1,
SUM(F.M_AMOUNT2) M_AMOUNT2
FROM TIME_DIM D, FACT_SALES F
WHERE D.F_DAY = F.F_DAY
GROUP BY D.F_MONTH
/

4、分析表, 并在会话级启用查询重写

ANALYZE TABLE TIME_DIM COMPUTE STATISTICS;
ANALYZE TABLE FACT_SALES COMPUTE STATISTICS;
ANALYZE TABLE MV_FACT_SALES COMPUTE STATISTICS;
ALTER SESSION SET QUERY_REWRITE_ENABLED=TRUE;
ALTER SESSION SET QUERY_REWRITE_INTEGRITY=TRUSTED;

5、先来看一下按季汇总的SQL语句的执行计划, 理论上, 可以从按月的汇总中进一步汇总生成, 但这时去执行的话, Oracle并不能这样执行

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        626   12   1   
1  0  HASH (GROUP BY)                 626   12   1   
2  1   HASH JOIN                   609 287712 16858   
3  2    TABLE ACCESS (FULL) OF TIME_DIM (TABLE)    4  999  13   
4  2    TABLE ACCESS (FULL) OF FACT_SALES (TABLE)  602 287712 13206

6、接下来来创建一个维对象, 用来告诉Oracle在TIME_DIM表的四个字段上存在的树状关系, 如果没有这个声明, Oracle会认为数据是不附合这个树状关系的

Tags:利用 对象 优化

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接