- 最后登录
- 2023-8-16
- 在线时间
- 1686 小时
- 威望
- 2135
- 金钱
- 50532
- 注册时间
- 2011-10-12
- 阅读权限
- 200
- 帖子
- 5207
- 精华
- 39
- 积分
- 2135
- UID
- 2
|
3#
发表于 2013-4-13 14:55:17
FYI
SQL> conn sh/oracle
已连接。
CREATE MATERIALIZED VIEW sum_sales_pscat_week_mv
ENABLE QUERY REWRITE AS
SELECT p.prod_subcategory, t.week_ending_day,
SUM(s.amount_sold) AS sum_amount_sold
FROM sales s, products p, times t
WHERE s.time_id=t.time_id AND s.prod_id=p.prod_id
GROUP BY p.prod_subcategory, t.week_ending_day;
SQL> explain plan for SELECT p.prod_subcategory, t.week_ending_day,
2 SUM(s.amount_sold) AS sum_amount_sold
3 FROM sales s, products p, times t
4 WHERE s.time_id=t.time_id AND s.prod_id=p.prod_id
5 GROUP BY p.prod_subcategory, t.week_ending_day;
已解释。
SQL> /
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------
----------------------------------------
Plan hash value: 2350791048
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1879 | 92071 | 8 (0)| 00:00:01 |
| 1 | MAT_VIEW REWRITE ACCESS FULL| SUM_SALES_PSCAT_WEEK_MV | 1879 | 92071 | 8 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
已选择8行。
SQL> l
1* select * from table(dbms_xplan.display())
SQL> delete sales where rownum<1000;
已删除999行。
SQL> commit;
提交完成。
SQL> select STALENESS from dba_mviews where MVIEW_NAME='SUM_SALES_PSCAT_WEEK_MV';
STALENESS
--------------------------------------
STALE
SQL> conn sh/oracle
已连接。
SQL> exec dbms_mview.refresh('SUM_SALES_PSCAT_WEEK_MV','C');
PL/SQL 过程已成功完成。
SQL> select STALENESS from dba_mviews where MVIEW_NAME='SUM_SALES_PSCAT_WEEK_MV'
STALENESS
--------------------------------------
FRESH
delete sales where rownum<1000;
SQL> alter session set events '10046 trace name context forever,level 8';
会话已更改。
SQL> delete sales where rownum<1000;
已删除999行。
SQL> rollback;
回退已完成。
SQL> select STALENESS from dba_mviews where MVIEW_NAME='SUM_SALES_PSCAT_WEEK_MV';
STALENESS
--------------------------------------
FRESH
SQL> delete sales where rownum<1000;
已删除999行。
SQL> commit;
提交完成。
SQL> select STALENESS from dba_mviews where MVIEW_NAME='SUM_SALES_PSCAT_WEEK_MV';
STALENESS
--------------------------------------
NEEDS_COMPILE
SQL> select count(*) from SUM_SALES_PSCAT_WEEK_MV;
COUNT(*)
----------
4083
SQL> select STALENESS from dba_mviews where MVIEW_NAME='SUM_SALES_PSCAT_WEEK_MV';
STALENESS
--------------------------------------
NEEDS_COMPILE
sys.sum$ w.mflags
alter session set events 'trace[SQL_MVRW] disk highest';
|
|