Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5987
  • Last Modified:

Materialized view with refresh fast on commit does not refresh

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
SaschaHerrmann
Asked:
SaschaHerrmann
  • 4
  • 4
  • 2
1 Solution
 
seazodiacCommented:
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
 
SaschaHerrmannAuthor Commented:
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
 
seazodiacCommented:
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!

 
SaschaHerrmannAuthor Commented:
But then I cannot use the "group by", can I?!
0
 
seazodiacCommented:
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
 
SaschaHerrmannAuthor Commented:
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
 
vc01778Commented:
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
 
SaschaHerrmannAuthor Commented:
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
 
seazodiacCommented:
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
 
vc01778Commented:
@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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now