Why do materialized views show a red X (invalid) in Mat. View mode (only) on the left and as INVALID when referenced in the Used By tab on the right? Both the Object and Accessing views appear perfectly fine and return the data correctly. This seems fairly consistent and is not resolved with nightly refreshes. I’m getting to the point where I think this is safe to ignore, but I thought I’d ask before I officially Don’t Care. Thanks for any wisdom … (and Happy Holidays.)
with Objs as
(Select object_id
from (select object_id, referenced_object_id
from public_dependency
where referenced_object_id <> object_id) pd
connect by nocycle prior object_id = referenced_object_id
start with referenced_object_id = :ObjID)
Select o.owner, o.object_type, o.object_name, o.object_id, o.status
from sys.DBA_OBJECTS o, Objs
where o.Object_id = Objs.Object_id;
So, Oracle must be showing your Materialized views as invalid in DBA_OBJECTS. This can happen is if you’ve done any DDL on any of the objects referenced in the MView’s query.
Thank you John. I’m not sure that’s the issue here as the invalid state seems to persist even through a MView refresh. These views are designed to transform, stabilize and version production data for reporting in a mobile app. The initial and somewhat complex transformations are handled in series of standard views that can then be replicated in the MView with little more than a SELECT * query. I do have a live sysdate-based timestamp in the view data that gets posted to the MView. Could that be the source of Invalid-ness? Otherwise, the data is a pretty stable and doesn’t change much from day to day, and the MView, itself, performs as expected. However, If I understand you correctly, maybe I don’t care because the content of the MView is the snapshot from 3:30a, e.g. yesterday’s final state, and that’s what I want. Make sense?
Hey Dave, I don’t think it would be caused by SYSDATE in one of the underlying views. But it could be one of the tables that are underneath the views that is causing the INVALIDness. Maybe there is some partition management happening on one of the tables? Just a guess, of course, but something like that could do it too, I think.
(Re: sysdate) … even when it is loaded to the MView and thus, automatically become out of sync with its source? I cannot think of anything else because the rest of the content is either a direct import of source view columns or a few case statements setting flags based on other (static) data on that row …? I could pull the RFRSHD (date) field off the view and just load SYSDATE to the MView and see what happens. Otherwise, I’m inclined to move on since the data checks out just fine … but I will keep an eye on it. Thanks,
Dependencies related to MVs are automatically maintained to ensure correct operation. When an MV is created, the materialized view depends on the master tables referenced in its definition. Any DML operation, such as an INSERT, or DELETE, UPDATE, or DDL operation on any dependency in the materialized view will cause it to become invalid.
What I think you are describing is exactly the issue (data consistency, not a faulty view construct) and therefore, is one that I don’t think I care about. I refresh (On Demand) nightly …
REFRESH ON DEMAND
START WITH sysdate
NEXT trunc(sysdate+1)+3.5/24
… to stabilize and snapshot-ize the data so I can put it in memory. I don’t care that it changes over the next 24 hours, because I’ll do it again. Thus, the invalid-ness (I’m learning) seems more in relation to data currency than its construct so I think I’m ok, aren’t I?
Thanks to both you guys for the contributions to my education.
You are welcome. I had similar problems a few years back with exactly this problem. Took me ages to work out the solution - which I then forgot about as time went by. Old age!
As you are refreshing on demand, you will see the problem any time the underlying tables change, but unless you need up to the second accuracy, this is not a problem.
You are good to go - and have nothing to worry about.
Cheers,
Norm. [TeamT]
–
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Good morning! With this “X” I understand. But there is " ! " in front of some of Materialized views. It goes away if I recompile this MV. Does it means it needs recompilation? Why that happened?
To follow up on whatbJohn said, an MV will "need compile" each and every time that the underlying tables change - alter table etc, or, insert, update, delete etc. This is true if the MVs are refresh on demand. If they are refresh on commit, then you won't see the '!' for insert, update, delete actions on the underlying table as the commit will refresh those parts of the MV deemed necessary to update.
Reply by Norm [TeamT]
To follow up on whatbJohn said, an MV will "need compile" each and every time that the underlying tables change - alter table etc, or, insert, update, delete etc. This is true if the MVs are refresh on demand. If they are refresh on commit, then you won't see the '!' for insert, update, delete actions on the underlying table as the commit will refresh those parts of the MV deemed necessary to update.