|
SQL> CONN YSP/YSP
Connected.
SQL> SELECT TNAME FROM TAB;
TNAME
------------------------------------------------------------
T
MLOG$_T
MV_T
T_EXP
TEST
TEMP_STATS
MV_CAPABILITIES_TABLE
TEST3
YSP
SYS_TEMP_FBT
10 rows selected.
SQL> DROP MATERIALIZED VIEW MV_T;
Materialized view dropped.
SQL> DROP TABLE T PURGE;
Table dropped.
SQL> create table t (id number, time date)
2 partition by range (time)
3 (partition p1 values less than (to_date('2008-1-1', 'yyyy-mm-dd')),
4 partition p2 values less than (to_date('2009-1-1', 'yyyy-mm-dd')),
5 partition p3 values less than (to_date('2010-1-1', 'yyyy-mm-dd')),
6 partition p4 values less than (to_date('2011-1-1', 'yyyy-mm-dd')))
7 ;
Table created.
SQL> insert into t select rownum, sysdate - rownum from dba_objects;
51099 rows created.
SQL> COMMIT;
Commit complete.
SQL> create materialized view log on t with rowid, sequence (id, time) including new values;
Materialized view log created.
SQL> create materialized view mv_t refresh fast enable query rewrite as
2 select time, count(*) from t group by time;
Materialized view created.
SQL> set autot traceonly explain
SQL> select time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 3024588181
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9 | 81 | 4 (25)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE| | 9 | 81 | 4 (25)| 00:00:01 | 3 | 3 |
| 2 | HASH GROUP BY | | 9 | 81 | 4 (25)| 00:00:01 | | |
|* 3 | TABLE ACCESS FULL | T | 9 | 81 | 3 (0)| 00:00:01 | 3 | 3 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement
SQL> select /*+ rewrite */ time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 2061866561
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 396 | 30 (4)| 00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV_T | 18 | 396 | 30 (4)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("MV_T"."TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "MV_T"."TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement
SQL> set autot off
SQL> delete t where time < to_date('2008-1-1', 'yyyy-mm-dd');
50215 rows deleted.
SQL> commit;
Commit complete.
SQL> set autot traceonly explain
SQL> select /*+ rewrite */ time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 2061866561
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 396 | 30 (4)| 00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV_T | 18 | 396 | 30 (4)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("MV_T"."TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "MV_T"."TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement
SQL> exec dbms_stats.gather_table_stats(user,'T');
PL/SQL procedure successfully completed.
SQL> select /*+ rewrite */ time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 2061866561
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 18 | 396 | 30 (4)| 00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV_T | 18 | 396 | 30 (4)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("MV_T"."TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "MV_T"."TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
Note
-----
- dynamic sampling used for this statement
SQL> exec dbms_stats.gather_table_stats(user,'MV_T');
PL/SQL procedure successfully completed.
SQL> select /*+ rewrite */ time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 2061866561
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9 | 99 | 30 (4)| 00:00:01 |
|* 1 | MAT_VIEW REWRITE ACCESS FULL| MV_T | 9 | 99 | 30 (4)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("MV_T"."TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "MV_T"."TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
SQL> select time, count(*) from t where time > to_date('2009-1-1', 'yyyy-mm-dd') and time < to_date('2009-1-10', 'yyyy-mm-dd') group by time;
Execution Plan
----------------------------------------------------------
Plan hash value: 3024588181
-----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 8 | 64 | 4 (25)| 00:00:01 | | |
| 1 | PARTITION RANGE SINGLE| | 8 | 64 | 4 (25)| 00:00:01 | 3 | 3 |
| 2 | HASH GROUP BY | | 8 | 64 | 4 (25)| 00:00:01 | | |
|* 3 | TABLE ACCESS FULL | T | 8 | 64 | 3 (0)| 00:00:01 | 3 | 3 |
-----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("TIME"<TO_DATE(' 2009-01-10 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
"TIME">TO_DATE(' 2009-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) |
|