Solved

Materialized view with refresh fast on commit does not refresh

Posted on 2004-03-26
10
5,837 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Function to return one result based on data in first query 11 54
Procedure syntax 5 48
oracle forms question 22 48
looking for guidance on Oracle Sql Formatting standards 9 28
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

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