WEB开发网
开发学院数据库Oracle Oracle数据仓库查询优化技术 阅读

Oracle数据仓库查询优化技术

 2007-05-06 12:07:32 来源:WEB开发网   
核心提示: SQL> select t.t_quarter, sum(f.amount1),sum(f.amount2)2from time_dim t,fact_sales f3where t.time_id=f.time_id4group by t.t_quarter;执行计划--Plan
SQL> select t.t_quarter, sum(f.amount1),sum(f.amount2)
2 from time_dim t,fact_sales f
3 where t.time_id=f.time_id
4 group by t.t_quarter;
执行计划
----------------------------------------------------------
Plan hash value: 53462861
----------------------------------------------------------------------------------
| Id | Operation      | Name    | Rows | Bytes | Cost (%CPU)| Time   |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT  |      | 1000 | 60000 |  9 (23)| 00:00:01 |
| 1 | HASH GROUP BY   |      | 1000 | 60000 |  9 (23)| 00:00:01 |
|* 2 |  HASH JOIN     |      | 1000 | 60000 |   8 (13)| 00:00:01 |
| 3 |  TABLE ACCESS FULL| TIME_DIM | 1000 | 21000 |  4  (0)| 00:00:01 |
| 4 |  TABLE ACCESS FULL| FACT_SALES | 1000 | 39000 |  3  (0)| 00:00:01 |
----------------------------------------------------------------------------------

创建一个Dimension,指定维度表中各level之间的层次关系:

SQL> create dimension time_dim
2 level year is (time_dim.t_year)
3 level quarter is (time_dim.t_quarter)
4 level month is (time_dim.t_month)
5 level day is (time_dim.t_day)
6 hierarchy year_quarter_month_day
7 (
8 day child of
9 month child of
10 quarter child of
11 year
12 );
维已创建。

重新执行查询,注意query_rewrite_integrity参数设置为Trust。同时分析fact_sales,time_dim表以及mv_month物化视图。有了dimension中定义的层次关系以后,优化器就能正确的利用月度物化视图进行季度统计的查询重写了:

上一页  1 2 3 4 5 6  下一页

Tags:Oracle 数据 仓库

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