Which type of materialized view refresh to use and how to refresh a materialized view every Tuesday - oracle

I have a requirement in which I need to build a materialized view on a transaction table, though it has about 671348 records, it takes more than 15 mins for executing the underlying materialized query.
The base table is refreshed every Tuesday
Please let me know what type of refresh I can use for materialized view(full or fast)
Also please let me know the syntax for refreshing the materialized view every tuesday.

Related

Can a materialized view be rolled back

Once an Oracle materialized view refreshes successfully can it be rolled back or put back to what it was prior to the refresh? Can the materialized view log on the master table be used if there is one?
I have an etl processes which has several procedures and materialized view refreshes. The way it is supposed to work if something fails than every thing that was done prior to it is rolled back. If something fails after a materialized view has been refreshed can the refresh be rolled back?
You can not manually rollback a materialized view refresh, once the refresh procedure is complete it has committed.
What you can do is lump all your materialized view refreshes into the same dbms_mview.refresh call. The default arguments for refresh_after_errors, atomic_refresh mean that if one of the MView refreshes in your list fail, the whole thing will be rolled back.

Partial refresh on Materialized View

We have a table TB_1 which has monthly and weekly data partitioned by monthly and weekly columns. We also have materialized view MV_1 inherited from the table TB_1.
We would like to refresh the materialized view by certain weekly or monthly basis.
Not sure how we can filter out weekly or monthly changes from all the changes captured in the materialized log for partial refresh.
Right now we are thinking to have a flag column in TB_1. By clearing the materialized log and updating the flag, We think we can achieve this.
Is there anyway efficient way than the process for partial refresh on specific criteria?
We have a similar case here: the solution we found was to partition the materialized view month by month (using PCT ). If you have this as an option in your licensing, this could be a solution. Then you must partition the "details tables", TB_1, and probably the "details tables" of MV_1.
execute dbms_mview.refresh(
list => 'your_partitioned_mview'
, method => 'P' -- this is where PCT is specified
, atomic_refresh => false
);
There are also other solution on Is it possible to partially refresh a materialized view in Oracle? .
edit:
I'd say the solution of a fast refresh using a "to be refreshed" flag is worth being tried. Not sure you need to clear the Mview log beforehand. Just changing the value of the flag for the record to be updated should work. Here is a nice howto I found.
If you have Oracle 12.2, they introduced real-time Mviews, which might be what you are looking for...
Oracle 12.2 introduced the concept of real-time materialized views, which allow a statement-level wind-forward of a stale materialised view, making the data appear fresh to the statement. This wind-forward is based on changes computed using materialized view logs, similar to a conventional fast refresh, but the operation only affect the current statement. The changes are not persisted in the materialized view, so a conventional refresh is still required at some point.
#use416, please keep us posted for what actually worked for your case.

Refreshing an existing materialized View

I created a materialized view with the following information.
CREATE MATERIALIZED VIEW EMPLOYEE_INFO
AS
SELECT * FROM EMPLOYEE_TABLE WHERE LOCATION = 'Brazil'
I did not add any refresh interval to this MV initially. Now, I need to refresh this MV everyday at 0000HRS.
Will the following command help me to alter it for everyday at 0000HRS?
ALTER MATERIALIZED VIEW EMPLOYEE_INFO
REFRESH COMPLETE
START WITH SYSDATE
In case, I need to refresh it for every 6 hours, how do I perform it? Is it possible?
For periodic refresh you must use NEXT clause. To refresh everyday at 00:00:
ALTER MATERIALIZED VIEW EMPLOYEE_INFO
REFRESH COMPLETE
NEXT TRUNC(SYSDATE) + 1
To refresh every 6 hours:
ALTER MATERIALIZED VIEW EMPLOYEE_INFO
REFRESH COMPLETE
NEXT SYSDATE + 6/24
From documentation (ALTER MATERIALIZED VIEW):
START WITH Clause
Specify START WITH date to indicate a date for the first automatic refresh time.
NEXT Clause
Specify NEXT to indicate a date expression for calculating the interval between automatic refreshes.
Both the START WITH and NEXT values must evaluate to a time in the future. If you omit the START WITH value, then Oracle Database determines the first automatic refresh time by evaluating the NEXT expression with respect to the creation time of the materialized view. If you specify a START WITH value but omit the NEXT value, then Oracle Database refreshes the materialized view only once. If you omit both the START WITH and NEXT values, or if you omit the alter_mv_refresh entirely, then Oracle Database does not automatically refresh the materialized view.
At the time of the next automatic refresh, Oracle Database refreshes the materialized view, evaluates the NEXT expression to determine the next automatic refresh time, and continues to refresh automatically.

Oracle - What happens when refreshing a 'REFRESH FORCE ON DEMAND' view with DBMS_MVIEW.REFRESH

I have the following materialized view -
CREATE MATERIALIZED VIEW TESTRESULT
ON PREBUILT TABLE WITH REDUCED PRECISION
REFRESH FORCE ON DEMAND
WITH PRIMARY KEY
AS
SELECT...
FROM...
WHERE...
This materialized view has no backing MATERIALIZED VIEW LOG. As seen in the clause above this MV has "ON DEMAND" specifies, and according to Oracle documentation,
"[ON DEMAND] indicate[s] that the materialized
view will be refreshed on demand by
calling one of the three DBMS_MVIEW
refresh procedures."
When I call DBMS_MVIEW.REFRESH('TESTRESULT') , what is occuring? Is it manually checking each record to see if it has been updated?
Oracle Version: 10g
By default (and this default changes in different versions of Oracle), that will do a full, atomic refresh on the materialized view. That means that the data in the materialized view will be deleted, the underlying query will be re-executed, and the results will be loaded into the materialized view. You can make the refresh more efficient by passing in a value of FALSE for the ATOMIC_REFRESH parameter, i.e.
dbms_mview.refresh( 'TESTRESULT', atomic_refresh => false );
That will cause the materialized view to be truncated, the query re-executed, and the results inserted into the materialized view via a direct path insert. That will be more efficient than an atomic refresh but the materialized view will be empty during the refresh.

Oracle - Updating Materialized Views

How can I update a materialized view? Is there any downside to updating materialized views? I'm in a situation where I can either
Update the materialized view (OR)
Copy the records to another table, update them, truncate or drop the materialized view table, insert the updated records back into the materialized view.
These two options revolve around the long amount of time required to rebuild the materialized view (literally 5+ days).
Version : Oracle 10g
The intention of a materialized view is to store the results of some complex long running query that the query rewrite mechanism can use to save lots of time. It looks like the sql that is used to build the MV needs some tweeking.
You cannot update an MV, unless you meant doing a full/fast refresh/rebuild.
What is eating the time in during the MV refresh? Did you check the addm reports?
Did you configure full or fast refreshes?

Resources