Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Materialized Views
Hopefully I'm doing something wrong, because so far
Materialized Views are useless. Here's my Create:
create materialized view
FACT_DIM04_LVL02
enable query rewrite
as
select
d04.DKEY
, d04.LVL02_DESCR
, f.KEY01
, f.KEY03
, f.YEAR_MONTH
, f.SCENARIO
, sum(f.AMOUNT) "AMOUNT"
from FACT1 f
, DIM04 d04
where (f.KEY04 = d04.KEY04) and (f.ATTR01 = 'O') and (d04.LVL01_DESCR = '9999') and (f.SCENARIO IN ('ACT', 'PLAN'))
This works. I now do
analyze table FACT_DIM04_LVL02 compute statistics ;
So far so good. Now let's do an EXPLAIN using the exact sames DDL used to create the MV:
explain plan
set STATEMENT_ID = 'FACT04'
for
select
d04.DKEY
, d04.LVL02_DESCR
, f.KEY01
, f.KEY03
, f.YEAR_MONTH
, f.SCENARIO
, sum(f.AMOUNT) "AMOUNT"
from FACT1 f
, DIM04 d04
where (f.KEY04 = d04.KEY04) and (f.ATTR01 = 'O') and (d04.LVL01_DESCR = '9999') and (f.SCENARIO IN ('ACT', 'PLAN'))
This gives:
Query Plan
explain plan
set STATEMENT_ID = 'FACT04'
for
select /*+ REWRITE */
d04.DKEY
, d04.LVL02_DESCR
, f.KEY01
, f.KEY03
, f.YEAR_MONTH
, f.SCENARIO
, sum(f.AMOUNT) "AMOUNT"
from FACT1 f
, DIM04 d04
where (f.KEY04 = d04.KEY04) and (f.ATTR01 = 'O') and (d04.LVL01_DESCR = '9999') and (f.SCENARIO IN ('ACT', 'PLAN')) and (1 = 1)
Notice that I added the simplest predicate possible (1 = 1), *AND* I've added a hint telling the optimizer to use the new MV. However, Oracle does not recognize the MV, instead it goes back to the base tables:
Query Plan
TABLE ACCESS BY INDEX ROWID DIM04 INDEX RANGE SCAN DIM04_LVL02 TABLE ACCESS FULL FACT_DIM04_LVL02
In other words, the MV only seems to work if you're using the *EXACT* query that was used to create the MV, which makes it almost useless.
Yes, I'm using CBO and have set QUERY REWRITE to true.
Any ideas out there? TIA. Received on Thu Jan 31 2002 - 13:26:11 CST