Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Materialized view with refresh fast on commit does not refresh

Posted on 2004-03-26
10
Medium Priority
?
5,917 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious sideā€¦
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

661 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