Solved

Materialized view with refresh fast on commit does not refresh

Posted on 2004-03-26
10
5,770 Views
Last Modified: 2007-12-19
I have a table BEFUND. PK is column BEFUND_UBEID. A FK column is UBERGEBNIS_UBEID.

Now I want to create a MV on that table that always shows the latest (highest) BEFUND_UBEID for a given UBERGEBNIS_UBEID.

I do:

create materialized view log on BEFUND tablespace users1 with rowid ( befund_ubeid, ubergebnis_ubeid ) including new values;

Then I do:

create materialized view TOTAL_REPORT
tablespace users
build immediate
refresh fast on commit
as
( select
  ubergebnis_ubeid,
  max( befund_ubeid ) LAST_BEFUND_UBEID,
  count( befund_ubeid ) BEFUND_COUNT
  from BEFUND
  group by ubergebnis_ubeid );

Info in user_mview states that FAST_REFRESHABLE is "DIRLOAD_LIMITEDDDML".
Now when my application creates a new row in BEFUND for a given UBERGEBNIS_UBEID with a new sequence-generated BEFUND_UBEID I would like the MV to fast refresh. It doesn't. STALENESS says it's UNUSABLE. I cannot trigger a manual fast refresh (ORA-12057).

What can I do to solve this?
0
Comment
Question by:SaschaHerrmann
  • 4
  • 4
  • 2
10 Comments
 
LVL 23

Expert Comment

by:seazodiac
ID: 10686776
what oracle version are you using?

1. did you have JOB_QUEUE_PROCESSES defined in your init.ora file? its values have to be greater than 0.
2. did you create MATERIALIZED VIEW LOG on the BEFUND table?

for example:

create materialized view log on BEFUND with rowid;



after you finish these two requirements, try to restart your database after you modify job_queue_processes parameter though.

and you do need a commit after you insert a row into the table in order to see the new row in the materialized view, remember that.

0
 
LVL 2

Author Comment

by:SaschaHerrmann
ID: 10686884
Hi!

It's a 9.2.0.4.

1. It is set to '4'
2. And yes, I have created the log (see line 7 of my posting).

DB was restarted yesterday, so that' not it.

My application commits alright. When I execute the query of my MV stand-alone, I see the modified data. But my MV just becomes unusable.
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 10687321
ok,  you have to include your ROWID in your MV definition.
create materialized view TOTAL_REPORT
tablespace users
build immediate
refresh fast on commit
as
( select
 ROWID,                                 ----------add this line to your materialized view.
 ubergebnis_ubeid,
 max( befund_ubeid ) LAST_BEFUND_UBEID,
 count( befund_ubeid ) BEFUND_COUNT
 from BEFUND
 group by ubergebnis_ubeid );
0
 
LVL 2

Author Comment

by:SaschaHerrmann
ID: 10687434
But then I cannot use the "group by", can I?!
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 10687735
that's true. Ignore my post with regards to adding the ROWID in your MV definition.

instead, change your materialized view log like this:

SQL> drop materialized view log on BEFUND;

SQL> create materialized view log on BEFUND tablespace users1 with rowid;
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 2

Author Comment

by:SaschaHerrmann
ID: 10688107
I have to include all columns mentioned in the query. Otherwise I'll get a ORA-12033.
And the "including new values" will have to stay too, otherwise I get a ORA-32401.

It's not that easy. I tried a lot already.
0
 
LVL 11

Expert Comment

by:vc01778
ID: 10689487
What's your Oracle version ?  There are numerous bugs with MVs in different Oracle versions.

Under 9.2.0.4,  your original example works OK:

SQL*Plus: Release 9.2.0.4.0 - Production on Fri Mar 26 12:58:49 2004

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> create table BEFUND(befund_ubeid int primary key,  ubergebnis_ubeid int);

Table created.

SQL>
SQL> create materialized view log on BEFUND
  2   with rowid ( befund_ubeid, ubergebnis_ubeid ) including new values;

Materialized view log created.

SQL>
SQL> create materialized view TOTAL_REPORT
  2  build immediate
  3  refresh fast on commit
  4  as
  5  ( select
  6    ubergebnis_ubeid,
  7    max( befund_ubeid ) LAST_BEFUND_UBEID,
  8    count( befund_ubeid ) BEFUND_COUNT
  9    from BEFUND
 10    group by ubergebnis_ubeid );

Materialized view created.

SQL>
SQL>
SQL> insert into befund values(1,2);

1 row created.

SQL> insert into befund values(2,2);

1 row created.

SQL> insert into befund values(3,2);

1 row created.

SQL> commit;

Commit complete.

SQL>
SQL> select * from TOTAL_REPORT;

UBERGEBNIS_UBEID LAST_BEFUND_UBEID BEFUND_COUNT
---------------- ----------------- ------------
               2                 3            3

SQL>


VC
0
 
LVL 2

Author Comment

by:SaschaHerrmann
ID: 10691651
Well, it's 9.2.0.4. Frankly, I don't see why it shouldn't work. But it doesn't.

Could it be the way data is inserted into the table? On Monday, I am going to do some "manual" inserts like you did and see what happens.
Is there some way to see why the MV just becomes unusable? Is there a way to see what's in the log? What could be the cause for the ORA-12057 (no fast refresh possible, must be complete)? I'm puzzled.
What does LIMITEDDML mean? Limited to what? I scanned the whole documentation, but cannot find an explanation.
0
 
LVL 23

Expert Comment

by:seazodiac
ID: 10691685
I tested it too, these are really simple steps to follow, and I don't see any reason why it does not work..


BTW, how did you insert the data ?
0
 
LVL 11

Accepted Solution

by:
vc01778 earned 500 total points
ID: 10694946
@SaschaHerrmann,


1. "DIRLOAD_LIMITEDDML"

This means that your MV is fast refreshable only upon inserts and direct load inserts.
It cannot be fast refreshed on deletes and updates (limited dml).  The reason for this is that you are using MIN/MAX aggregates -- with these aggregates, the view cannot be fast refreshed on deletes and updates.

2. The view becomes unusable because, apparently,  you've performed a delete or an update.

3. I am not sure it's a good idea to use refresh on commit because your commits on the base table will be delayed until  the refresh is completed, but you probably know about that.

VC
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now