I was executing some tests with the concept of Materialized Views in Oracle and I wasn't able to answer this question, would a Materialized View fetch rows when the master table it was originally created from becomes empty? I have listed a sequence of events below to visualize what I have in mind,
- Create a valid Materialized View based on a huge Master table
Here's an example
The Master table
CREATE TABLE master_tab
(
col1 varchar2(10),
col2 varchar2(10),
col3 varchar2(10),
tr_val1 number,
tr_val2 number,
tr_val3 number
)
The Materialized View definition
CREATE MATERIALIZED VIEW mview_test
BUILD IMMEDIATE
REFRESH COMPLETE
ON DEMAND
ENABLE QUERY REWRITE
AS SELECT col1, col2
SUM(tr_val1), SUM(tr_val2)
FROM master_tab
GROUP BY col1, col2
- At a later point in time, for some reason, the master table master_tab gets truncated
- So, now, only the Materialized View has any data relevant to any query on the Master table master_tab
I wasn't very conversant with what Oracle does behind the scenes to fetch the correct data. Now, what happens when a query gets executed from an application looking for data from the Master table? For example, what happens when an application queries,
SELECT col1, col2
SUM(tr_val1), SUM(tr_val2)
FROM master_tab
GROUP BY col1, col2
- What kind of decisions does Oracle take internally to fetch data from Materialized Views?
- Would Oracle still retrieve the correct data from the Materialized View even if the Master table is empty?
- If the answer to #2 is yes, does it mean that as long as the Materialized View isn't refreshed again, Oracle will still be able to fetch data for all queries looking for data from the Master?
Thanks for your help