Skip to Main Content
  • Questions
  • How to refresh Materialized View when the changes are made in the B tables !

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, OP.

Asked: December 18, 2000 - 8:25 am UTC

Last updated: July 31, 2013 - 3:57 pm UTC

Version: 8.1.6

Viewed 50K+ times! This question is

You Asked

Dear Tom,

Hi !
How are you doing !


Thanks very much for your Kind help again and again.
Sometimes I wonder if you were not there what would
have happened to my role.

My sincere thanks and Regards to you.

Ques) This Quest is based on Materialized View .When
we create a Materialized view and after that if the
Changes are made in the Base tables,the changes are not
reflected in the Materialized view.There is a need to
drop it and recreate it.

For exmaple I am creating Materialized View like this :


create materialized view MV_AREA_WRK_PLC
tablespace test storage ( initial 128K )
build immediate
using index tablespace test
as
(
select
(area.WRK_PLC_AREA_CD || '00000000') as PLC_MERGED_CD,
area.WRK_PLC_AREA_NM as PLC_MERGED_NM,
area.WRK_PLC_AREA_CD as WRK_PLC_AREA_CD,
area.WRK_PLC_AREA_NM as WRK_PLC_AREA_NM,
area.DISP_ORDER as WRK_PLC_AREA_DISP_ORDER,
null as WRK_PLC_CD,
null as WRK_PLC_NM,
'0000' as WRK_PLC_DISP_ORDER
from
MT_WRK_PLC_AREA area
where
area.del_f = '0'
)
union all
(
select
(area.WRK_PLC_AREA_CD || plc.WRK_PLC_CD) as PLC_MERGED_CD,
plc.WRK_PLC_NM as PLC_MERGED_NM,
area.WRK_PLC_AREA_CD as WRK_PLC_AREA_CD,
area.WRK_PLC_AREA_NM as WRK_PLC_AREA_NM,
area.DISP_ORDER as WRK_PLC_AREA_DISP_ORDER,
plc.WRK_PLC_CD as WRK_PLC_CD,
plc.WRK_PLC_NM as WRK_PLC_NM,
plc.DISP_ORDER as WRK_PLC_DISP_ORDER
from
MT_WRK_PLC_AREA area,
MT_WRK_PLC plc
where
plc.WRK_PLC_AREA_CD = area.WRK_PLC_AREA_CD and
area.del_f = '0' and
plc.del_f = '0'
)
order by 4, 7
;

Whenever any change is made in the value for Tables

MT_WRK_PLC_AREA
MT_WRK_PLC

there is a need to drop it and recreate it.


1) Is there any Keyword which can be used while creation
of materialized view so that the Materialized view gets
refresed automatically after some appropriate duration
of time.

2) How Materialized view is different from View ?


Kindly answer !

Thanks & Regards
OP


and Tom said...

You need to use the REFRESH clause of the create materialized view command. It lets you specify a NEXT clause. For example:


CREATE MATERIALIZED VIEW T
REFRESH FAST START WITH SYSDATE NEXT trunc(SYSDATE) + 1

AS SELECT .....


Would create a changed only MV that will refresh nightly at midnight. In some cases you can even specify "refresh on commit" meaning apply the changes to the MV as soon as you commit.

See
</code> http://docs.oracle.com/cd/A81042_01/DOC/server.816/a76994/mv.htm#721 <code>

for more details.

A view is simply a stored query, it consumes no space in the database other then its data dictionary entries. A materialized view on the other hand is a real table -- we've already computed the view and queries will go against the results of the MV. If you were using a regular view -- we just substitute in the view text in your query. With an MV, we query the materialized view data.



Rating

  (54 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Materialzed View

Bharath, June 27, 2002 - 11:27 am UTC

Hi Tom,
In your reply you had mentioned that an option can be specified during the creation of MV to reflect the changes made in the base table. Will this work for only What

If a MV is based on say more than one table for e.g. 5 tables and has a number of columns from each base table.
What would happen if one of the column is updated in the base table. Will the change be reflected in the MV or the
"refresh on commit" would work for MV based on a single table.

Thanks,
Bharath

Tom Kyte
June 27, 2002 - 12:04 pm UTC

see
</code> http://docs.oracle.com/docs/cd/A87860_01/doc/server.817/a76994/mv.htm#32933 <code>

ON COMMIT

Refresh occurs automatically when a transaction that modified one of the materialized view's fact tables commits. Can be used with materialized views on single table aggregates and materialized views containing joins only.






Sun from HK

chen sun, July 16, 2002 - 4:56 am UTC

Hi Tom,
Can Materialized View be used in Oracle Discover? and If I want to create a MV, what should I set in the machine?
thanks ........

Tom Kyte
July 16, 2002 - 7:35 am UTC

A MV works like an index -- the application doesn't have to be aware of it, only the optimizer.

the goal of an MV is to be totally transparent to the client - making them available to ANY and ALL clients from sqlplus to discoverer to brio to crystal and so on.

You'll want to read the chapter on MV's in the data warehousing guide and if you have my book -- I have a chapter in there explaining what they are, what privs you need, how to set up and so on.

Lots of examples on this site as well if you use the SEARCH

How about set operators in a mview..

Worker Bee, October 10, 2002 - 4:14 pm UTC

Can set operators like "union all", "minus" etc.. be used in a materialized view definition?

I was under the impression that it was not allowed (in either 8i or 9i) but looks like the person with the initial question was able to do it.

Thank you.


Tom Kyte
October 11, 2002 - 7:43 pm UTC

you can use them, sure -- they are just not FAST refreshable.

In 9iR2, union ALL views are fast refreshable.


The union, minus -- that would be truly hard cause they remove DUPS, there isn't any sort of one to one mapping from MV row back to a source row.

Aladdin

Aladdin, September 26, 2003 - 12:53 pm UTC

thanks ,
i wanna know is these materialized view could be refreshed on commit if the view is a join between two tables
on on my bdatabase and the other on another database(borland interbase) using a database link

Tom Kyte
September 26, 2003 - 2:53 pm UTC

no.

just no

Aladdin, September 27, 2003 - 2:38 pm UTC

how it could be

Tom Kyte
September 27, 2003 - 2:40 pm UTC

because that is the answer??

did you want me to make something up?

you cannot refresh on commit over a dblink, period.

you cannot even capture a "commit" action from borland interbase in Oracle - think about it.


Sometimes the answer is "no" and nothing else.

What additional privs?

Kamal Kishore, September 28, 2003 - 8:24 am UTC

Hi Tom,
I have SELECT, INSERT, UPDATE, DELETE privs. on the SCOTT.EMP table and SELECT on MVIEW LOG table granted. When trying to create a Materialized View (REFRESH ON DEMAND) it works but fails when specified REFRESH ON COMMIT. What additional privs. are required for REFRESH ON COMMIT?

SQL> create materialized view mview_emp
  2  refresh fast on demand
  3  as
  4  select * from scott.emp
  5  /

Materialized view created.

SQL>
SQL> drop materialized view mview_emp
  2  /

Materialized view dropped.

SQL>
SQL> create materialized view mview_emp
  2  refresh fast on commit
  3  as
  4  select * from scott.emp
  5  /
select * from scott.emp
                    *
ERROR at line 4:
ORA-01031: insufficient privileges


SQL>
SQL> disconnect
Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.3.0 - Production
SQL>
 

Tom Kyte
September 28, 2003 - 9:35 am UTC

Most all of the SQL commands include their "pre-reqs" in the SQL Reference:

</code> http://docs.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_63a.htm#2080852 <code>



joins on MV

aish, October 09, 2003 - 9:03 am UTC

can we use multiple joins on MV's
REFRESH complete WITH ROWID
START WITH SYSDATE NEXT trunc(SYSDATE) + 1
AS
SELECT so.urefitem, fc.CREFITEM1 , Count(oi.prefitem) ItemCount
FROM tab1 so INNER JOIN tab2 oi ON
so.sorefitem = oi.sorefitem INNER JOIN tab3 pc ON
oi.prefitem = pc.prefitem INNER JOIN tab4 fc ON
pc.flatiD = fc.FLATID
WHERE so.ostatus = -1 AND so.osubstatus = -1 AND fc.CREFITEM1 <> 1
GROUP BY so.urefitem, fc.CREFITEM1 ;
like the above
iam getting ORA-00904 error



Tom Kyte
October 09, 2003 - 5:43 pm UTC

[tkyte@tkyte-pc-isdn tkyte]$ oerr ora 904
00904, 00000, "%s: invalid identifier"
// *Cause:
// *Action:


your query is "bad"

if you 

SQL> set autotrace traceonly explain
SQL> select .....

does the query even parse? 

Refresh fast with dblink is causing prob

Gayatri, June 10, 2004 - 7:53 am UTC

create materialized view mv1
refresh fast
start with sysdate
next sysdate+1/500
with primary key
as select * from mv_tab@mydblink;

gives the error :ora-12015 cannot create a fast refresh materialized view from a complex query

Tom Kyte
June 10, 2004 - 9:37 am UTC

give us the entire example -- the steps you took to create mv_tab -- the entire thing.

ANSI Join syntax issue with ON COMMIT

Glen Morris, February 07, 2005 - 11:45 pm UTC

I've been struggling to get ON COMMIT working on a simple join MV. I have finally been able to work out the problem and it appears to be down to my use of the newish ANSI join syntax.

When I try to create the MV using the 'inner join', I get "ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view".

When I switch the joins into the normal where clause syntax, all works fine.

I had a good look around in doco and can't find any reference to this restriction. Should I log this as a TAR or have I missed an obvious reference somewhere?

Test case follows :

drop table test_x;
drop table test_y;

create table test_x (a number, b varchar2(10));
create table test_y (a number, b varchar2(10));

drop materialized view test_mv;

create materialized view test_mv
BUILD IMMEDIATE
REFRESH on commit
ENABLE QUERY REWRITE
AS
select x.a xa
,x.b xb
,y.b yb
FROM test_x x
inner join test_y y
on (y.a = x.a)
/

create materialized view test_mv
BUILD IMMEDIATE
REFRESH on commit
ENABLE QUERY REWRITE
AS
select x.a xa
,x.b xb
,y.b yb
FROM test_x x
,test_y y
where y.a = x.a
/

insert into test_x values (1,'a');

commit;

select * from test_mv;

insert into test_y values (1,'b');

commit;

select * from test_mv;


Thanks for your great help.
Glen

Tom Kyte
February 08, 2005 - 1:28 am UTC

please log a tar, yes.

Follow up on ANSI Join syntax

Glen Morris, March 02, 2005 - 10:57 pm UTC

Just to let you know, logged a TAR on the above issue (bug 4143202). The Oracle documentation will be amended to state ansi joins are not permitted in 'refresh on commit' MVs.

The reason is :
"Transformation for the ANSI INNER JOIN in oracle is as follows.
select x.a xa
,x.b xb
,y.b yb
FROM test_x x inner join test_y y
on (y.a = x.a)
/
.
will be tranformed to
.
select xa
, xb
, yb
from (select x.a xa, x.b xb, y.b yb
from test_x x, test_y y
where y.a = x.a) V ;
.
As there is an inline view in the query , creation of mview fails with error ORA-12054.
"

At least the doco will soon highlight the problem.

Thanks
Glen


Tom Kyte
March 03, 2005 - 7:19 am UTC

thanks for the followup!

ON COMMIT question

Mike, March 09, 2005 - 2:50 pm UTC

Tom,

We use 9.2.0.4 version. Most of our tables are loaded using sql*loader. Sql*loader commits after every 10,000 rows (ROWS=10000). Most table loads are conventional.

I wanted to know if I create an MV on one of such tables using ON COMMIT clause, does the refresh occur multiple times (equal to the number of commits during sql*load) or only once?

Thank you.

Tom Kyte
March 09, 2005 - 3:18 pm UTC

every time you (sqlldr) commits -- it'll refresh as part of the commit process.

alter base table of Mview

Vishal Tandon, April 22, 2005 - 11:28 am UTC

we user oracle 9.2.0.4. I have a snapshot log and a materialized view created on a huge base table. One of
the column width in the base table has been increased.
Can we alter the snapshot log and mview to accomodate the
revised column definiton or we have to drop and re-create
snapshot log and mview which will take very long time.
Please advise thanks for your help.

The mview has been created using refresh force with primary key option

Tom Kyte
April 22, 2005 - 12:28 pm UTC

DDL against the snapshot log is not going to be anything I can suggest...

Please contact support for this.

Monitoring of Materialized view

monika, May 08, 2005 - 1:04 pm UTC

I would like to know, if a refresh of Materialized view fails, how can a user be notified, say by email

Tom Kyte
May 08, 2005 - 1:37 pm UTC

you'd have to either

a) have a monitoring tool, of which there are literally dozens to choose from

b) schedule a custom job using dbms-job or the new 10g scheduler. It would invoke the refresh and upon getting an error, use utl-smtp or whatever you want to send email -- to send it, and then re-raise the exception (MV's are already using the job queues to run themselves, you would just stop using the interval on the MV and create your own job)

monika, May 08, 2005 - 9:49 pm UTC

Thanks so much tom!
Can you please provide a sample code for custom job and email notification, or direct to the URL where it is already available.

Tom Kyte
May 09, 2005 - 6:57 am UTC

begin
dbms_mvew.refresh( 'thename' );
exceptions
when others
then
send_mail(.....);
raise;
end;

send_mail
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:255615160805 <code>
(utl_mail supplied with 10g)

schedule it using dbms_job (tons of examples, search)


Refreshing MView only for specific rows

Claude, May 11, 2005 - 11:02 am UTC

Tom,
I am trying to refresh specific materialized view records based on a key-value (say employee_id), and leave the rest of the mview records unrefreshed.

dbms_mview.refresh('emp_mv', ???)
only for emp_mv.emp_id=123.

Can this be done?
Thanks

Tom Kyte
May 11, 2005 - 12:21 pm UTC

no, it cannot be done for individual rows like that.

Materialize view

António Gonçalves, September 20, 2006 - 12:30 pm UTC

I wanted to create one I materialize view in an user (app_cpal_bi) with the following command:

create materialized view cpl_custo_consum_doentes_v2
build immediate
refresh fast on commit
enable query rewrite
as
select *
from app_cpal.cpl_custo_consum_doentes_v2;

app_cpal = another user

he gave the following error: "ORA-12054: it is not possible to define the attribute of renewal ON COMMIT for the materialized sight".
what I must make ?

Tom Kyte
September 20, 2006 - 3:42 pm UTC

you must make complete test case before I look at it - the original create table, the materialized view logs and so on.

but I would really question the "sanity" of this materialized view - WHY WHY WHY are you doing that??? what is the point?

How can I achive this ?

Parag J Patankar, September 22, 2006 - 3:35 am UTC

Hi,

I am having two servers one at london another is in new york. On London server I can not do any changes in database while in new york server I can do any changes.  I want to replicate a data of a single table of london server to new york server. 

Suppose in London server I have table call 't' having 15 columns, which should be replaced on newyork server. Table 't' is currently having less number of insert/update records ( no delete ) and expected to large no of rows in a future. 

How can I achive this ? I thought using mv on newyork server using refresh fast but I can not create mv log in london server I had tried this

drop database link s0055;

create database link s0055
connect to scott
identified by tiger
using 'test'
/

create materialized view log on t@s0055 with rowid;

11:33:17 SQL> @b

Database link dropped.

Database link created.

create materialized view log on t@s0055 with rowid
*
ERROR at line 1:
ORA-00949: illegal reference to remote database

Kindly suggest me urgently, how can I achive this ( want some kind of  fast refresh to avoid huge network traffic )in Oracle 9.2 database ?

thanks & regards
PJP 
 

Tom Kyte
September 22, 2006 - 3:13 pm UTC

if you want a materialized view log, well, you will HAVE TO MODIFY the remote server.

sorry - but if you want any sort of reasonable response times here, you will sort of have to have london "participate with you in a logical fashion"

tell london, if they do not, you will full refresh - that might convince them to work WITH you.

MV REFRESH !!!!

PARAG J PATANKAR, September 25, 2006 - 6:20 am UTC

Hi Tom,

Thanks for your reply. I have following few questions regardsing mv refresh in 9.2 database !!!

1/ Is there any way to find out what way mv has been refreshed ? for e.g. I have a view call 'parag' and it has been refreshed last 2 hours. Now I want to know by what method it has been refreshed ( fast or full ). How can I find out ?

2/ Last timestamp of mv refreshed ?

3/ Amount of network traffic used due to mv refreshed on different servers. For e.g. my london server having mv log and newyork server is having mv. I want to find out if I do refresh of mv in fast mode how much network bandwidth is using it ?

thanks & regards
pjp

Tom Kyte
September 25, 2006 - 8:06 am UTC

desc user_mviews - that'll be #1 and #2

to measure the "network" traffic, you would:

query v$mystat to see how much you've used so far.
run your refresh interactively
query v$mystat to see how much MORE you've used so far.
subtract

dbms_mview refresh

Parag Jayant Patankar, September 26, 2006 - 12:55 am UTC

Hi,

Thanks for your help. Will you pl explain in more detail
<
query v$mystat to see how much you've used so far.
run your refresh interactively
query v$mystat to see how much MORE you've used so far.
subtract
>
of using v$mystat. Will you kindly show me "select" statment for v$mystat ?

Secondly, If I am having average row length then can I calculate avg row len * no of rows in mv log to find network traffic ?

thanks & regards
PJP




Tom Kyte
September 26, 2006 - 2:37 am UTC

did you check out the reference manual for what is in these views???


v$mystat - has your sessions statistics, join it to v$statname and use a where clause to get "redo" information.


no, you cannot compute just avg row len * #rows - you are monitoring the network usage of an APPLICATION - that happens to do an mv refresh, it is not just simply sending #rows back and forth.

MV FAST REFRESH creation workaround

Parag Jayant Patankar, September 28, 2006 - 1:16 am UTC

Hi Tom,

I am using oracle 9.2.0.6. I am facing a problem on creating fast refresh MV. Kindly suggest me workaround.

on Server A sombody created table

create table f ( timestamp timestamp primary key );

( column name same as datatype, which is causing a problem )

insert into f select localtimestamp from dual;
insert into f select localtimestamp from dual;
insert into f select localtimestamp from dual;

create materialized view log on f;

On Server B I am tring following

drop database link s0055
/
create database link s0055
connect to scott
identified by tiger
using 'orcl'
/
drop materialized view mvf
/
create materialized view mvf
parallel
build immediate
refresh fast on demand with rowid
as
select *
from scott.f@S0055
/

ERROR at line 7:
ORA-04052: error occurred when looking up remote object ATLAS.F@S0055
ORA-00604: error occurred at recursive SQL level 1
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-320: the declaration of the type of this expression is
incomplete or malformed
ORA-02063: preceding 2 lines from S0055

Will you pl suggest me workaround for creating MV without disturbing original table structure ? ( Can I create MV as FAST REFRESH on view, I have tried it but not succeeded )

thanks & regards
PJP


Tom Kyte
September 28, 2006 - 3:10 am UTC

someone really did this:

( timestamp timestamp primary key );

and thought it was a "good idea"???  date/time fields are not good for primary keys first of all and naming the column after the datatype is "not smart"


but I cannot reproduce:

ops$tkyte%ORA9IR2> create table f ( timestamp timestamp primary key );

Table created.

ops$tkyte%ORA9IR2>
ops$tkyte%ORA9IR2> insert into f select localtimestamp from dual;

1 row created.

ops$tkyte%ORA9IR2> insert into f select localtimestamp from dual;

1 row created.

ops$tkyte%ORA9IR2> insert into f select localtimestamp from dual;

1 row created.

ops$tkyte%ORA9IR2>
ops$tkyte%ORA9IR2> create materialized view log on f with rowid;

Materialized view log created.

ops$tkyte%ORA9IR2> create database link loopback@ora9ir2
  2  connect to ops$tkyte identified by xxxxx using 'ora9ir2';

Database link created.

ops$tkyte%ORA9IR2>
ops$tkyte%ORA9IR2> create materialized view mvf
  2  parallel
  3  build immediate
  4  refresh fast on demand with rowid
  5  as
  6  select *
  7  from f@loopback@ora9ir2
  8  /

Materialized view created.


so, I'll have to ask you to work this one via support. 

MV workaround

Parag Jayant Patankar, September 28, 2006 - 3:52 am UTC

Hi Tom,

Thanks for your brilliant answer. But In my case still it is not working.

Server A1 under user ('a')

  1* create table f ( timestamp timestamp )
SQL> /

Table created.

SQL> create materialized view log on f with rowid;
Materialized view log created.

Server 'b1' under user 't'

drop database link a@atinp2
/
create database link a@atinp2
connect to atlas
identified by atlas
using 'atinp2'
/
drop materialized view mvz23
/
create materialized view mvz23
parallel
build immediate
refresh fast on demand with rowid
as
select *
from f@a@atinp2
/

Database link dropped.
Database link created.
drop materialized view mvz23
*
ERROR at line 1:
ORA-12003: materialized view "T"."MVZ23" does not exist

from f@a@atinp2
     *
ERROR at line 7:
ORA-04052: error occurred when looking up remote object F@A@ATINP2
ORA-00604: error occurred at recursive SQL level 1
ORA-06552: PL/SQL: Compilation unit analysis terminated
ORA-06553: PLS-320: the declaration of the type of this expression is
incomplete or malformed
ORA-02063: preceding 2 lines from A@ATINP2

Kindly suggest where I have gone wrong. 

In your example I assumed "loopback" is not having much meaning. ( I have tried above example with loopback@atinp2 but sam error ). I also raised a service request 5813754.992.

thanks & regards
PJP
 

Tom Kyte
September 28, 2006 - 4:24 am UTC

umm, I just showed you I cannot reproduce and said "you'll need to work this via support"

I didn't want you to change your dblink name, I just used that dblink name is all.

ORA-32320: REFRESH FAST of Owner.Mview unsupported after cointainer table PMOPs

A reader, September 28, 2006 - 4:07 am UTC

Hi Tom,
Oracle version 9.2.0.7.0 - 64bit Production
OS: HP-UX

We have a job which refreshes a Mview group everyday at 8 AM
The group has a mview which is failing with this error and a result the job as well.
The particular mview has the following attributes:

Non-partitioned
References a Single Table from a remote site.
Refersh on Demand
Fast refresh
Read Only

The master table at the remote site is also non partitioned and has a mlog.

The mview was truncated a few days ago.
Then after getting the error I refreshed it manually using COMPLETE refresh. Then, changed the refresh mode to force and executed the job manually. The job executed successfully and got reset to the correct value of next_date. Also failures was 0 after running the job successfully.
But even after that I keep getting this error.
Please advice what am I doing wrong.
Thanks as always.


Tom Kyte
September 28, 2006 - 4:27 am UTC

[tkyte@dellpe ~]$ oerr ora 32320
32320, 00000, "REFRESH FAST of \"%s\".\"%s\" unsupported after container table PMOPs"
// *Cause: A Partition Maintenance Operation (PMOP) has been performed on the
// materialized view, and no materialized view supports
// fast refersh after container table PMOPs.
// *Action: Use REFRESH COMPLETE. Note: you can determine why your
// materialized view does not support fast refresh after PMOPs using
// the DBMS_MVIEW.EXPLAIN_MVIEW() API.



truncating would prevent a fast refresh.

ORA-32320

A reader, September 28, 2006 - 6:03 am UTC

Hi Tom,
I havd read about the error and based on that did a complete refresh.
But, even after that it is generates this error.
Do you mean that after truncating the mview all subsequent refreshes have to be complete and fast refresh option has to be left out.

I did an explain plan using MV_CAPABILTIES_TABLE as suggested but did not know which attribute or data will specify the reason for failed fast refreshes.

CAPABILITY_NAME P REL_TEXT MSGTXT
------------------------------ - -------- ----------------------------------------------------------
PCT N
REFRESH_COMPLETE Y
REFRESH_FAST Y
REWRITE N
PCT_TABLE N WFRSAPPS relation is not a partitioned table
REFRESH_FAST_AFTER_INSERT Y
REFRESH_FAST_AFTER_ONETAB_DML Y
REFRESH_FAST_AFTER_ANY_DML Y
REFRESH_FAST_PCT N PCT is not possible on any of the detail tables in the
materialized view

REWRITE_FULL_TEXT_MATCH N WFRSAPPS mv references a remote table or view in the FROM list
REWRITE_FULL_TEXT_MATCH N query rewrite is disabled on the materialized view
REWRITE_PARTIAL_TEXT_MATCH N materialized view cannot support any type of query rewrite
REWRITE_PARTIAL_TEXT_MATCH N query rewrite is disabled on the materialized view
REWRITE_GENERAL N materialized view cannot support any type of query rewrite
REWRITE_GENERAL N query rewrite is disabled on the materialized view
REWRITE_PCT N general rewrite is not possible and PCT is not possible on
any of the detail tables
Thanks as always.


Tom Kyte
September 28, 2006 - 7:16 am UTC

no, the refresh after the truncate would be complete, but then fast is OK - you need to sync them up.

Excellent...

A reader, September 28, 2006 - 7:57 am UTC

Thanks for the response Tom.
That is exactly what I have done.
I refreshed the mview using COMPLETE Refresh.
But even after that the job is failing for the same mview with ORA-32320

Am I missing something?
Please advice.
Thanks as always.


Tom Kyte
September 28, 2006 - 8:02 am UTC

should work, you can work this one via support please.

David Aldridge, September 29, 2006 - 1:55 pm UTC

Just a guess, but you'd probably need to purge or drop and recreate the mlog, then complete refresh the mview. Or something like that.

what happens if mv can not able to refresh

Parag J Patankar, October 04, 2006 - 8:50 am UTC

Hi Tom,

Suppose I created mv like this to refresh data in every 5 mins

CREATE MATERIALIZED VIEW T
REFRESH FAST START WITH SYSDATE NEXT 5/(24*60)
AS SELECT .....
from toto@remotedb <======== db link for remote database server

Will you pl explain what happens if my remote database is down for few hours for daily backup ? Does it will create any problem in local database ?

thanks & regards
PJP

Tom Kyte
October 04, 2006 - 5:07 pm UTC

the job that was scheduled to refresh will try 16 times (increasing the time between tries as it does so) and then mark itself broken if after 16 times it cannot refresh.

you will then have to "unbreak the job" after correcting the problem.

MV refresh and data transfer

Parag J Patankar, October 05, 2006 - 8:57 am UTC

Hi Tom,

Thanks for your answers to my questions. I have written following procedure to refresh mvs over dblink in every 5 mins

create or replace procedure refresh
as
kount number(9) := 0;
begin
begin
select count(*)
into kount
from t@test01; <= remote db is up or not checking
exception when others then
kount := 0;
end;

if kount > 0 then
dbms_mview.refresh('mv_test', 'F', '', TRUE, FALSE, 0, 0, 0, FALSE);
end if;
end;
/

variable n number;

begin
dbms_job.submit(:n, 'refresh;', sysdate, 'sysdate+5/(24*60)');
commit;
end;
/

Q1/ Do you think is it a good idea to refresh mv in this manner ?

I have written following SQL to observe network traffic due to mv refresh

select a.sid, a.statistic#, b.name, a.value
from v$mystat a, v$statname b
where a.STATISTIC# = b.STATISTIC#
and b.STATISTIC# = 114
/

Q2. Is it correct ?
Q3 If I do refresh of mv it shows increase by 8 in value

SID STATISTIC# NAME VALUE
--- ---------- -------------------- ----------
12 114 redo entries 27

<--- refresh mv --->

SID STATISTIC# NAME VALUE
--- ---------- -------------------- ----------
12 114 redo entries 35

<--- refresh mv --->

SID STATISTIC# NAME VALUE
--- ---------- -------------------- ----------
12 114 redo entries 43

So can I conclude that due mv refresh network traffic is 8 os blocks ?

thanks & regards
PJP

Tom Kyte
October 05, 2006 - 9:36 am UTC

why would you not just use the builtin capability?

MV refresh and network traffic monitoring due to mv refresh

Parag J Patankar, October 05, 2006 - 10:14 am UTC

Hi Tom,

I am not using buitin feature of mv for refresh because my remote database ( on remote server ) gets completly shutdown before EOD process. ( Timing is not fixed and it is for 1 hour approx ). So mv refresh will get failed after 16 attempts.

So according to me this kind of refresh can be done without any problem as on local database I am having full control and data in mv should be available to users early morning.

Secondly, my dbms_refresh will break down during backup. So I have no option to write a job to run broken job, so why not take care at time of refresh !!!

q1/ Do you think buitin feature will be more useful than
refresh thru procedure in a such situation ?

q2/ Will you pl answer my query regarding mv refresh data traffic monitoring ?

thanks & regards
PJP

Tom Kyte
October 05, 2006 - 1:13 pm UTC

I have no idea why you would monitor redo in order to ascertain network traffic.

mviews refresh network traffic monitoring

Parag J Patankar, October 06, 2006 - 5:35 am UTC

Hi Tom,

I have asked you how to monitor how much data has been transferred over network due to mvs refresh ? You have given me following answer in same question above

<quote>

v$mystat - has your sessions statistics, join it to v$statname and use a where
clause to get "redo" information.
<quote end>

so I have written following query to monitor

select a.sid, a.statistic#, b.name, a.value
from v$mystat a, v$statname b
where a.STATISTIC# = b.STATISTIC#
and b.STATISTIC# = 114
/

Have I missed out your point ? Pl tell me.

thanks & regards
PJP


Tom Kyte
October 06, 2006 - 9:01 am UTC

you just queried out:

SID STATISTIC# NAME                      VALUE
--- ---------- -------------------- ----------
 12        114 redo entries                 43

redo entries.  One would normally query, well, network related statistics to see, well, network traffic no?


please don't use numbers by the way, 114 - that'll change from port to port and version to version.  Use the statistic names, and use one that at least has "Net" in it if you want "network" stuff


ops$tkyte%ORA10GR2> select name from v$statname where name like '%Net%';

NAME
--------------------------------------------------
bytes sent via SQL*Net to client
bytes received via SQL*Net from client
SQL*Net roundtrips to/from client
bytes sent via SQL*Net to dblink
bytes received via SQL*Net from dblink
SQL*Net roundtrips to/from dblink

6 rows selected.

 

preserve aggregate values in MV

Ram, July 09, 2007 - 6:24 am UTC

We want to create MV over big fact table, we are going to have aggregate values of fact table in MV.
Fact table will have high number of insert, and we have to clean the old data which are 3 weeks older.

Is it possible to preserve aggregate values in MV, even though some data deleted from fact table ?
New insert data to be aggregate in MV along with previously aggregate values.

Tom Kyte
July 09, 2007 - 7:13 am UTC

no, the sole goal of the materialized view is to exactly match the base tables, materialized views must reflect all of the modifications to the base table, not just some, by design.


MV must be in Synchronize with base table

Ramki, July 09, 2007 - 12:34 pm UTC

This means MV must be in Synchronize with base table.
We want aggregated data in MV alone to be stored for longer period (2 years) and deleting fact data every 3 weeks. Is there any other way we can do this?
Kindly give your suggestion

Tom Kyte
July 09, 2007 - 2:20 pm UTC

you would have to code it yourself (some process) - especially the "age it out after three years" bit (that'll likely be impossible as you aggregate probably over the time dimension....)

David Aldridge, July 10, 2007 - 11:39 am UTC

Ram, you ought to be aware that query rewrite will be a tricky proposition with materialized views when you drop old data from the fact table and preserve it in the MV, as Oracle may recognise that it's cheaper to query a detailed fact table than it is to query the MV even if the MV is small, as the fact table will actually return no data for old periods. Using DBMS_Advanced_Rewrite is a better proposition as it is documented that a rewritten plan is always preferred over a non-rewritten plan. http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_advrwr.htm#i999507

Fortunately if you are going to be hand-coding your aggregate maintenance (not a bad option at all, in my opinion) then you'd be better off using DBMS_Advanced_Rewrite than you would with MV's. Unfortunately, 10g+ only.

A reader, July 18, 2007 - 4:52 am UTC

I read this:
If a summary contains data that is based on data which is no longer in the fact table, maintain the materialized view using fast refresh ( http://lbdwww.epfl.ch/f/teaching/courses/oracle8i/server.815/a67775/ch5.htm#31381 )

Does that mean, fast refresh will retain data in the MV even if its deleted from the base fact table?
Also, will query rewrite work in such a case?

Will query rewrite work when the MV query contains Union?




Tom Kyte
July 18, 2007 - 10:41 am UTC

no it doesn't - the entire goal of a refresh is to completely synchronize the materialized view with the base tables.


query rewrite will work - yes.

MV must be in Synchronize with base table

Ramki, October 25, 2008 - 5:21 pm UTC

Please see my question above "MV must be in Synchronize with base table" asked on July 9, 2007.

Instead of deleting old data, can we move old data in to separate storage and keep MV & fact table in Synchronize.
My projects is in telecom domain, we will have approximately 400+ fact table, all columns of this table are numbers and these table will have *only insert*. Inserts thousands of rows for every 15 minutes in each table. These data we call it as "raw" data. All read operation are read by hour/day/week/month aggregate.

I am think to do following steps :
Create partition by week and compress older partition table.
Create materialized view for hour/day/week/month/year.
Since we may not read raw data table for any future use, can we move these older partition table to some other storage device.
We are mainly looking for solution for disk space, where disk is getting filled up with "raw" data.
Let me know your suggestion for disk storage problem.

Regards
Ramki
Tom Kyte
October 25, 2008 - 6:43 pm UTC

I am not following your logic.

How about instead of suggesting what you think you would like to physically do, you rather describe the problem at hand - the goal.

If your goal is "archive old data", then partitioning is probably the correct approach.

Materialized view

Rajik Mohamed, August 24, 2010 - 12:35 am UTC

ORA-12012: error on auto execute of job 7
ORA-12008: error in materialized view refresh path
ORA-04052: error occurred when looking up remote object LDS.LOTF@KFLOWF.LOCALHOST
ORA-00604: error occurred at recursive SQL level 3
ORA-03106: fatal two-task communication protocol error
ORA-02063: preceding line from KFLOWF
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 820
ORA-06512: at "SYS.DBMS_SNAPSHOT", line 877
ORA-06512: at "SYS.DBMS_IREFRESH", line 683
ORA-06512: at "SYS.DBMS_REFRESH", line
I get following error in materialized view

Refresh option

Brijesh, February 02, 2011 - 2:55 am UTC

Hi Tom,
Can we use "on commit" option for refresh when we are using dblinks? I tired it gave me error. Please suggest
Tom Kyte
February 02, 2011 - 7:45 am UTC

no, you cannot. It is supported in a single database only.

On commit in a distributed database would make it such that the one database is completely dependent on the availability of the other - meaning - you really really meant to have a single database in the first place, there is no point in having two - they need to share data very intimately.

Replication Vs Materialize view

Brijesh, February 18, 2011 - 12:37 am UTC

We are having requirment to sink the backup(read only) database. Would it be better to use oracle replication (using streams) as compared to Materialize view.

Please suggest
Tom Kyte
February 18, 2011 - 8:57 am UTC

materialized views are replication.

If you can use materialized views, I'd probably go with that due to the utter simplicity of it all. Very little setup, very few moving pieces to watch.

However, if this is a 'backup' (eg failover) site - you should consider using data guard instead - it has all you need to build a complete failover that can also be used for reporting.

Broken Jobs for Materialize view

Brijesh, May 16, 2011 - 7:09 am UTC

Materialize view is created on separate Database and are getting refreshed using DBLink. For testing we put the Base Table user offline, we got build broken job message in the log.
Then we made the user online and manually refreshed the materialize view. But it didn't started getting refreshed automatically as earlier.
Table log was having the data, DB Link was also fine but still it was not getting refreshed. We have to manually refresh it.
To overcome this we had to drop and recreate the Materialize view. Could you please explain the possible steps/mechanism to avoid recreation of Materialize view in case of any failure at the base tables.
Tom Kyte
May 18, 2011 - 3:15 am UTC

you could have just used the dbms_job package to "unbreak" the job, that would have been a bit easier.

http://docs.oracle.com/docs/cd/E11882_01/appdev.112/e16760/d_job.htm#i1000521

thanks for info

raju, May 26, 2011 - 3:36 am UTC

Hi Tom hope u r doing well,
I am unable to create fast refresh mview even after i have created mview log tables for the below query:(i need it urjent plz help me)
CREATE MATERIALIZED VIEW APPS.XX_SHOW_TEST1
TABLESPACE APPS_TS_TX_DATA
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 128K
NEXT 128K
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH FAST
START WITH TO_DATE('26-maj-2011 08:55:15','dd-mon-yyyy hh24:mi:ss')
NEXT DECODE( SIGN ( 5 - TO_CHAR(SYSDATE, 'HH24') ) , 0 , SYSDATE + 2/24 , 1 ,SYSDATE + 6/24 , SYSDATE + 1/(24*6) )
WITH PRIMARY KEY
AS
/* Formatted on 2011/05/26 14:03 (Formatter Plus v4.8.8) */
SELECT hp.party_name customer_name,
DECODE (hp.party_type, 'PERSON', 'Y', 'N') person_flag,
oeh.attribute1 tax_payer_id,
DECODE (oeh.org_id, 2, 'COM03', 47, 'COM04') country_code,
oeh.order_number oracle_order_id, oeh.attribute15 order_type,
oel.orig_sys_document_ref master_order_id,
oel.orig_sys_line_ref psft_order_id, oel.ordered_item, mtl.description,
oel.flow_status_code line_item_status, oeh.attribute18 auth_return,
oeh.creation_date order_creation, confirm_date ship_confirm_date,
xp.pickup_date pickup_date, oel.attribute1 msisdn,
oel.attribute8 eu_first_name, oel.attribute9 eu_last_name,
wdd.tracking_number tracking_number, xa.delivery_phone delivery_phone,
xa.delivery_contact delivery_contact, oel.attribute5 sales_person,
oeh.sales_channel_code sales_channel_code,
oeh.attribute17 agreement_url, qpi.segment1 proposition_code,
qpi.description desc_proposition,
DECODE (s.orig_sys_document_ref, NULL, 'N', 'Y') return_created,

/*DECODE
(oeh.attribute15,
'RE', NULL,
'RP', NULL,
'EX', NULL,
DECODE ((SELECT COUNT (ROWID)
FROM oe_order_lines_all ay
WHERE ay.reference_header_id = oel.header_id
AND ay.reference_line_id = oel.line_id),
0, 'N',
'Y'
)
) return_created, */
xa.confirmation_email confirmation_email,
xa.confirmation_sms confirmation_sms,
NVL (xa.order_acceptance_status, 'NULL') order_acceptance_status,
--Added for B5921
NVL (xa.order_confirmation_sent, 'NULL') order_confirmation_sent,
--Added for B5921
xa.customer_ip customer_ip_address, --Added for B5921
xa.customer_timestamp customer_timestamp, --Added for B5921
get_hold_status_order (oeh.header_id) hold_status,
s.orig_sys_document_ref case_id, --NEW

/*DECODE ('**XXYYZZ**',
'**XXYYZZ**', (SELECT s.orig_sys_document_ref
FROM oe_order_lines_all s
WHERE s.reference_header_id =
oel.header_id
AND s.reference_line_id =
oel.line_id
AND ROWNUM <= 1)
) case_id, */
DECODE
('**XXYYZZ**',
'**XXYYZZ**', (SELECT description
FROM fnd_lookup_values
WHERE lookup_type = 'CREDIT_MEMO_REASON'
AND lookup_type LIKE 'CREDIT_MEMO_REASON'
AND lookup_code = s.return_reason_code) --NEW
) return_reason
FROM oe_order_headers_all oeh,
oe_order_lines_all oel,
xx_additional_order_info xa,
xx_pickup_dates xp,
mtl_system_items_b mtl,
hz_cust_site_uses_all hcs,
hz_cust_acct_sites_all has,
hz_party_sites hps,
hz_parties hp,
hz_locations hl,
oe_order_price_attribs oep,
xx_qp_items qpi,
wsh_new_deliveries wnd,
wsh_delivery_assignments wda,
wsh_delivery_details wdd,
oe_order_lines_all s
WHERE oeh.header_id = oel.header_id
AND oeh.orig_sys_document_ref = xa.orig_sys_document_ref(+)
AND oeh.order_source_id = fnd_profile.VALUE ('XX_CRM_IMPORT_SOURCE') --NEW
AND oeh.org_id = xa.org_id(+)
AND s.reference_header_id(+) = oel.header_id
AND s.reference_line_id(+) = oel.line_id
--AND oeh.sold_to_org_id = has.cust_account_id
AND wdd.tracking_number = xp.tracking_number(+)
AND mtl.organization_id =
DECODE (oel.org_id,
2, 4,
47, 85
) -- NEW changed order of org and segment
AND mtl.segment1 = oel.ordered_item -- NEW changed order of org and segment
AND oeh.ship_to_org_id = hcs.site_use_id
AND has.cust_acct_site_id = hcs.cust_acct_site_id
AND hps.party_site_id = has.party_site_id
AND hp.party_id = hps.party_id
AND hl.location_id = hps.location_id
AND wnd.delivery_id(+) = wda.delivery_id
AND wda.delivery_detail_id(+) = wdd.delivery_detail_id
AND wdd.source_line_id(+) = oel.line_id
AND NVL (oeh.quote_number, 1) = NVL (oeh.quote_number, 1) -- NEW
AND oeh.order_type_id IN
(1193, 1274, 1199, 1214, 1253, 1197, 1276, 1255, 1201)
AND oeh.attribute15 != 'EX'
AND oeh.creation_date >
TRUNC
(SYSDATE - 365)
--between TRUNC (SYSDATE - 565) AND TRUNC (SYSDATE - 201)
AND oeh.order_category_code = 'ORDER' -- NEW
AND oep.header_id(+) = oel.header_id
AND oep.line_id(+) = oel.line_id
AND qpi.inventory_item_id(+) = oep.pricing_attribute1
AND NVL (qpi.organization_id, DECODE (oel.org_id, 2, 4, 47, 85)) =
DECODE (oel.org_id,
2, 4,
47, 85
);

Tom Kyte
May 26, 2011 - 7:53 am UTC

your keyboard is broken, it is spewing out unintelligible nonsense like:

u
r
plz

I cannot parse your sentences when they look like that.



AND oeh.creation_date >
TRUNC
(SYSDATE - 365)


sysdate is constantly moving - think about this - this cannot be fast refreshed, every row must be reconsidered every second.

for my earlier post

raju, May 27, 2011 - 2:21 am UTC

Hi TOm,Iam very thankful to your reply.
and u asked me to think about sysdate for fast refresh materialized view.then i came to know that mine is complex query which is not eligible for fast refresh. Now my question is my force refresh materialized view is taking more time to get refreshed.Please help me so that i can reduce the time for process of my force refresh materialized view.

thanks
Raju
Tom Kyte
May 27, 2011 - 10:38 am UTC

If you are in 10g and up, you might consider atomic_refresh=> false.

That will use a

a) truncate
b) insert /*+ append */ (direct path load)

instead of the current:

a) delete
b) insert (conventional path)


but bear in mind, during the refresh period - if you use truncate/insert /*+ append */ - the materialized view will appear empty during the refresh.

can do you do that?

for my earlier post

A reader, May 30, 2011 - 4:15 am UTC

Hi tom, you are helping me alot.you suggested me to use atomic_refresh=false.But in my scenario i cant do this because they need to use this mview very frequently.So could you suggest me any other alternative way.
Tom Kyte
May 31, 2011 - 10:21 am UTC

short of analyzing your query and trying to figure out a way to accomplish the goal using a more efficient query. No, not really. It is all related to the performance of that query.

Materialized view with Database Links

A reader, June 01, 2011 - 2:30 am UTC

Hi,
Greetings.
We have a requirement to replicate 2 tables in a remote environment. So a obvious approach will be a materialized view. We are thinking of Materialized view with prebuilt table option and creating a materialized view logs for a fast refresh.

Environment details

1) Source environment- 2 physical tables are present say Table_A,Table_B
2) Remote Site - Above tables are required here, not on line but a refresh once a day after activity is over in Source database.

What are the best ways to have this replicated in the Remote 2 site.

We are thinking of creating a materialized view on pre built table and create materialized view logs on the source Database for a Fast Refresh. We are running with 10g Release 2 i.e 10.2.0.1.0 and will use a Atomic Refresh - TRUE.

We plan for a materialized view on a prebuilt table because further to creation of materialized view, its our understanding that any query written on those table(s) will be queried from the materialized view. So if this is TRUE i shall resort to this option instead of creating a materialized view for different queries on same 2 tables.

We dont want a View because the data needs to travel from 2 remote locations where we dont enjoy a good network bandwidth but where as a Refresh of Materialized view is one time activity.


Please suggest a best alternative to have this done or if prebuilt table option is not right.

Tom Kyte
June 01, 2011 - 8:55 am UTC

You would use a prebuilt table for offline instantiation typically . If you are just going to use the dblink to move the data the first time, you wouldn't really need or want to use a prebuilt table.


We plan for a materialized view on a prebuilt table because further to creation of materialized view, its our understanding that any query written on those table(s) will be queried from the materialized view. So if this is TRUE i shall resort to this option instead of creating a materialized view for different queries on same 2 tables.

I could not understand the gist of that paragraph. It didn't compute to me.

A reader, June 01, 2011 - 9:37 am UTC

Hi
Thanks for your post. Can you please explain in detail on what do you mean by "prebuilt table for offline instantiation typically", am not able to comprehend this.
also explain us on What is the main use of this clause "prebuilt table" while creating Materialized views.

Thanks in advance


Tom Kyte
June 01, 2011 - 2:42 pm UTC

the main use of prebuilt table is for offline instantiations of various types, or for times when you want the table to remain in the database even after dropping the materialized view (search this site for the term prebuilt and you'll see examples)

offline instantiation is a technique of creating a materialized view without having to initially pull all of the data over the dblink. For example, you might have a 500gb table you want a materialized view of. Rather than using a dblink - you decide to use a backup of the data and sneakernet to move it. You would import it and create the materialized view on the prebuilt table - instead of having the materialized view itself create and pull the data. It doesn't always use prebuilt tables, but it can.

http://docs.oracle.com/docs/cd/E11882_01/server.112/e10707/rarmanmv.htm#REPMA416

HOW CAN WE FIND THE REFRESH TIME

raju, June 04, 2011 - 2:51 am UTC

Hi Tom,hope doing well.I have created a FAST REFRESH materialized view but i wanted to know how long it is getting refreshed.please expalin me with the syntax.
and if at all it goes for long time how can i reduce the refresh time.
Tom Kyte
June 06, 2011 - 9:11 am UTC

depending on the mview type, you might be able to get it from here:

http://docs.oracle.com/docs/cd/E11882_01/server.112/e17110/statviews_1141.htm#i1581763

if it is a summary materialized view (aggregate). Else, it is something you have to record yourself - instead of using the automatic job that is created with a scheduled refresh period - create your own job to refresh it that looks something like:

begin
start := sysdate;
dbms_mview.refresh('xxxx' );
insert into log_table ( mview_name, start_time, end_time ) values
( 'xxxx', start, sysdate );
end;


To reduce refresh times you can consider parallel operations or having less time between refreshes (less work = less time)

Materialized view is in idle status

raju, July 04, 2011 - 12:06 am UTC

Hi Tom,

Hope you are doing well.
I have created a fast refresh materialized view but it is not performing any refresh.I checked in DBA_JOBS table for my specific materialized view then i came to know that no refresh happened and it is not going to do any refresh in the future (by seeing last_date,next_date in dba_jobs table).Then i have checked my materialized view capabilities in mv_capabilities_table i got a message that" materialized view log is newer than last full refresh". kindly help me . Thanks in advance.
Tom Kyte
July 05, 2011 - 7:57 am UTC

the materialized view log is newer than the last full refresh meaning - the log was created AFTER the materialized view was created/fully refreshed - meaning - the log might not have a record of every change needed to make the materialized view consistent.

meaning: you need to do a full refresh before that log can be used, that will be the only way to know that the log has a record of every relevant change.

mv in idle status

raju, July 06, 2011 - 8:53 am UTC

hi Tom,

As you suggested i have done complete refresh but still no use.Could you give me any other solution.Thanks in advance.


Tom Kyte
July 08, 2011 - 11:27 am UTC

show us the output of a direct call to the refresh routine using the 'F' option for a fast refresh and show us any errors you receive in sqlplus or your alert log.

STALE=NEEDS_COMPILE

rajesh, July 15, 2011 - 6:28 am UTC

Hi Tom,
i have created FAST refresh materialized view.it is eligible for FAST refresh because when i executed SELECT * FROM USER_MVIEWS i could see FAST_REFRESHABLE=DIRLOAD_DML and STALENESS=STALE and it is not getting refreshed(through DBA_JOBS).Could you tell me the reason why it is in STALE status and how to resolve it. and one of my materialized views is in NEEDS_COMPILE status, Could you tell me the reason why it is and how to resolve it
Tom Kyte
July 18, 2011 - 9:09 am UTC

in dba_jobs, is it broken? there is a broken column, has it failed? when is it scheduled to run and when did it last run? any messages in your alert.log? have you tried refreshing from the command line yourself?

Materialised View

Nikhil Trivedi, February 13, 2012 - 8:58 am UTC

How to use a materialised view refresh,where the refresh is done for a table daily but the updated date doesnt change.It changes only when there is change in the project for an employee.Kindly reply ASAP.
Tom Kyte
February 13, 2012 - 9:06 am UTC

huh? I don't know what you mean.

Preserving incremental refresh capability when performing partition operations

P, March 27, 2012 - 11:05 pm UTC

Hello Tom.

Is it possible to preserve the incremental refresh capabilities of a materialized view, in the face
of partition operations, when the base table(s), mlog and mvlog are all equipartitioned?

I can see why the behaviour below is sensible in general but, unless I misunderstand something, I
think it is safe in our case.

The reason we wish to do this is that we'd like to enforce business-rule integrity constraints via
ON COMMIT mviews (they're ON DEMAND in the example just to make it easier to test).
We'd probably be happy to suffer an individual customers constraints needing to be fully rechecked
when their partitions are moved but needing to recheck every customer's constraints is likely to be
unworkable (as I believe we'd need to cease all DML by all customers until we can alter the mv back
to REFRESH FAST ON COMMIT).

Any thoughts?

Thanks.


drop table test1;
drop table test2;
drop table tmp;
drop materialized view mv_test1;
drop materialized view mv_test2;
drop materialized view mv_tmp;
drop table mv_test1;
drop table mv_test2;
drop table mv_tmp;


create table test1
(
CUSTOMERID VARCHAR2(35),
test NUMBER(*,0)
)
partition BY list(CUSTOMERID)(Partition defaultpartition VALUES(NULL));

create table test2
(
CUSTOMERID VARCHAR2(35),
test NUMBER(*,0)
)
partition BY list(CUSTOMERID)(Partition defaultpartition VALUES(NULL));

create table tmp
(
CUSTOMERID VARCHAR2(35),
test NUMBER(*,0)
);

CREATE UNIQUE INDEX test1_PKidx ON test1 (CUSTOMERID, test) LOCAL;
CREATE UNIQUE INDEX test2_PKidx ON test2 (CUSTOMERID, test) LOCAL;
CREATE UNIQUE INDEX tmp_PKidx ON tmp (CUSTOMERID, test) ;

ALTER TABLE test1 ADD CONSTRAINT test1_PK PRIMARY KEY (CUSTOMERID,test) ENABLE NOVALIDATE;
ALTER TABLE test2 ADD CONSTRAINT test2_PK PRIMARY KEY (CUSTOMERID,test) ENABLE NOVALIDATE;
ALTER TABLE tmp ADD CONSTRAINT tmp_PK PRIMARY KEY (CUSTOMERID,test) ENABLE NOVALIDATE;


CREATE MATERIALIZED VIEW LOG ON test1
partition BY list(CUSTOMERID)(Partition defaultpartition VALUES(NULL))
WITH
PRIMARY KEY,
ROWID
;
CREATE MATERIALIZED VIEW LOG ON test2
partition BY list(CUSTOMERID)(Partition defaultpartition VALUES(NULL))
WITH
PRIMARY KEY,
ROWID
;
CREATE MATERIALIZED VIEW LOG ON tmp
WITH
PRIMARY KEY,
ROWID
;

create table mv_test1
partition BY list(CUSTOMERID) (Partition defaultpartition VALUES(NULL))
as select customerid, test from test1
where 1 = 2;

create table mv_test2
partition BY list(CUSTOMERID) (Partition defaultpartition VALUES(NULL))
as select customerid, test from test2
where 1 = 2;

create table mv_tmp
as select customerid, test from tmp
where 1 = 2;


CREATE MATERIALIZED VIEW mv_test1
on prebuilt table
refresh fast on demand
as select customerid, test from test1;

CREATE MATERIALIZED VIEW mv_test2
on prebuilt table
refresh fast on demand
as select customerid, test from test2;


CREATE MATERIALIZED VIEW mv_tmp
on prebuilt table
refresh fast on demand
as select customerid, test from tmp;





alter table test1 add partition CUST01 values ('CUST01');
alter table MLOG$_test1 add partition CUST01 values ('CUST01');
alter table MV_test1 add partition CUST01 values ('CUST01');

alter table test1 add partition CUST02 values ('CUST02');
alter table MLOG$_test1 add partition CUST02 values ('CUST02');
alter table MV_test1 add partition CUST02 values ('CUST02');

alter table test2 add partition CUST01 values ('CUST01');
alter table MLOG$_test2 add partition CUST01 values ('CUST01');
alter table MV_test2 add partition CUST01 values ('CUST01');

insert into test1 ( customerid, test) values ('CUST01', 10);
insert into test1 ( customerid, test) values ('CUST01', 11);
insert into test1 ( customerid, test) values ('CUST02', 20);
insert into test1 ( customerid, test) values ('CUST02', 21);
commit;

exec dbms_mview.refresh('MV_TEST1', 'f');

insert into test1 ( customerid, test) values ('CUST01', 13);
insert into test1 ( customerid, test) values ('CUST01', 14);
insert into test1 ( customerid, test) values ('CUST02', 23);
insert into test1 ( customerid, test) values ('CUST02', 24);
commit;

--Ensure that no DML is occurring to any CUST01 related partition
alter table mv_test1 exchange partition CUST01 with table mv_tmp INCLUDING INDEXES WITHOUT VALIDATION;
alter table MLOG$_test1 exchange partition CUST01 with table MLOG$_tmp INCLUDING INDEXES WITHOUT VALIDATION;
alter table test1 exchange partition CUST01 with table tmp INCLUDING INDEXES WITHOUT VALIDATION;

--All partitions in MLOG are truncated and following refresh fails due to MLOG being newer than last complete refresh
exec dbms_mview.refresh('MV_TEST1', 'f');

Tom Kyte
March 28, 2012 - 8:47 am UTC

you cannot play with the materialized view and materialized view log tables like that, no. that definitely would not be supportable/supported.

best you can do is utilize some partition change tracking

http://docs.oracle.com/cd/E11882_01/server.112/e25554/advmv.htm#DWHSG00324

you'd have to see if that fits into your schema at all.



P, March 29, 2012 - 5:24 pm UTC

Ok, thanks.

So, the conclusion I have reached is that partition exchange operations are incompatible with mlogs
and, by consequence, incremental refresh of mviews. Hence partition exchange rules out enforcing
any complex integrity constraints where you can't get a complete refresh done quick enough for 'on
commit' usage.

PCT won't help this situation as we need incremental update on all DML.

And this is a problem even when everything is equipartitioned and you are able to manually ensure
that the base tables, mlogs and mviews are all in synch as you can't assert that you've put the
right data into the mlog (sort of like what you can do for mviews using prebuilt tables).

Archive Log Generation for MV's

Brijesh, July 30, 2012 - 1:37 am UTC

Hi Tom,

We have created materialized view having multiple base tables and used cast function for few columns in MV. The database is running in Archive mode.

After these changes the MV's are generating lot of Archive 6GB/Hr resulting in space issues which was normally 1GB/Day

Is this behaviour normal or we needed to add some hint in MV's or tune some DB parameter.
Tom Kyte
July 30, 2012 - 12:04 pm UTC

you can either

a) refresh incrementally (also known as "fast") which means the changes will be applied to the materialized view row by row - that'll generate redo like you have right now.

b) refresh complete - the refresh will be done with a truncate (no undo, no redo to speak of) and insert /*+ APPEND */ - which if you set the materialized view table to nologging and do not have force logging set at the database level - can bypass undo and redo on the table (but not on any indexes)



CAST function in MV

Brijesh, July 31, 2012 - 7:03 am UTC

Thanks for your recommendation.
My pain point is using the CAST function. When my MV is not using the cast function and is based on single base table, logs generated are within limits.
If my MV uses the cast function and access multiple base tables, log generation increase too many folds.
Each of my base tables has 1-2 million records and gets 60-70K update per day. We have refresh frequency of 5 min for MV.
Can you please help me understand where my approach is off track?
Can we go by the complete refresh route?

Tom Kyte
July 31, 2012 - 12:45 pm UTC

Can we go by the complete refresh route?


you are the only one that can answer that. can you live with having the data in the materialized view disappear as soon as the truncate happens and reappear only after the commit of the insert /*+ APPEND */ is complete?


are you sure the CAST function is the culprit - or is it due to the fact that your materialized view is much more complex with multiple tables and such???

Please help me to solve ORA-32320

bhaskar reddy, July 01, 2013 - 6:02 am UTC

ORA-32320: REFRESH FAST of "E****"."RM*********" unsupported after container table PMOPs
Tom Kyte
July 01, 2013 - 9:23 pm UTC


ops$tkyte%ORA11GR2> !oerr ora 32320
32320, 00000, "REFRESH FAST of \"%s\".\"%s\" unsupported after container table PMOPs"
// *Cause:  A Partition Maintenance Operation (PMOP) has been performed on the
//          materialized view, and no materialized view supports
//          fast refersh after container table PMOPs.
// *Action: Use REFRESH COMPLETE.  Note: you can determine why your
//          materialized view does not support fast refresh after PMOPs using
//          the DBMS_MVIEW.EXPLAIN_MVIEW() API.


Mview refresh on commit

Vinodh G R, July 22, 2013 - 8:06 am UTC

Hi Tom,
I have some doubt on "ON COMMIT" refresh.

1. Does on commit refresh will refresh the mview only for the updated master table's data or it will do the updated values of the select query inside the mview.

2. what are the advantages and disadvantages of on commit refreshes.

3.I read in the some ML note that on commit refresh will genterate the mview logs. what is the use of that logs.



In our database we have 3 mviews which are doing the complete refresh every 3 min(due to this we have more redo generation.). I'm Planing to change this refresh to on commit.

4. Does On commit refresh will generate the less redos as compared to complete refresh.

Please suggest me how to avoid/ minimize the redo generations.

Thanks

Tom Kyte
July 31, 2013 - 3:57 pm UTC

1) i don't understand that question at all - i don't know what you are asking?

when you refresh on commit, the changes you've made in your session are applied to the materialized view. we've kept a log of your changes and we are doing an incremental refresh of the materialized view using your log entries.


2)
advantage:
materialized view is never stale

disadvantage:
makes your transaction bigger, potentially slower
introduces some level of serialization - only one refresh at a time


3) to maintain a list of the changes you've made so we can apply them to the materialized viwe.


do not change to refresh on commit. If you can have a 3 minute lag - keep it.

why not just change your materialized view to be "refresh fast", that will apply incremental changes instead of deleting+inserting the entire set? The amount of redo will be a function of the amount of data modified.


just go to refresh fast, create the apppropriate materialized view logs on the base tables and refresh fast - but not on commit. You apparently do not have an on commit requirement


4) it can produce

a) the same
b) more
c) less


an incremental (fast) refresh TYPICALLY produces less redo since you are only applying the changes that have occurred since the last refresh - not rewriting the entire structure.