Skip to Main Content
  • Questions
  • Using Materialized View log to Refresh the Sql Server tables.

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, pranav.

Asked: May 26, 2016 - 5:30 am UTC

Last updated: May 27, 2016 - 10:38 pm UTC

Version: 11.2.0.4

Viewed 1000+ times

You Asked

Hi Team,

We have created a materialized View which is a join of 3 tables. I have created Mview log on table with primary key & rowid option.

I have created tables in Sql Server which is CTAS(create table as select * from)copy of the materialized View.

We do dataloads of around 10 million in the base tables of Materialized View Daily.

We plan to use the Mview log on the table to insert/delete/update rows on the SQL Server.

1)For Deletes:-We plan to delete rows in Sql server table that are deleted in Oracle base tables using Primary key column.
2)For Updates:-We plan to delete & insert rows for Updates that are updated in Oracle base tables using Primary key column.
3)For Insert:-We plan to insert rows in the Mview log that are updated in Oracle base tables using Primary key column.

Do you feel if this is the right Approach for updating table in Sql Server.

Please advise.

and Connor said...

I wouldnt use a materialized view log for anything by refreshing a materialized view.

Because you're taking a huge gamble if you do so...

SQL> create table t ( x int primary key, d date );

Table created.

SQL>
SQL> create materialized view log on t including new values;

Materialized view log created.

SQL>
SQL> insert into t values (1,sysdate);

1 row created.

SQL> update t set d = d + 1;

1 row updated.

SQL> delete from t;

1 row deleted.

SQL> desc MLOG$_T
 Name                                                  Null?    Type
 ----------------------------------------------------- -------- ------------
 X                                                              NUMBER
 SNAPTIME$$                                                     DATE
 DMLTYPE$$                                                      VARCHAR2(1)
 OLD_NEW$$                                                      VARCHAR2(1)
 CHANGE_VECTOR$$                                                RAW(255)
 XID$$                                                          NUMBER

SQL> select * from MLOG$_T;

         X SNAPTIME$ D O CHANGE_VECTOR$$                     XID$$
---------- --------- - - ------------------------------ ----------
         1 01-JAN-00 I N FE                             3.0963E+15
         1 01-JAN-00 U U 04                             3.0963E+15
         1 01-JAN-00 U N 04                             3.0963E+15
         1 01-JAN-00 D O 00                             3.0963E+15

4 rows selected.


So what happens when the next patchset rolls out, and we (Oracle) decide that we wont have a DMLTYPE column anymore, we're going to store the dml action inside the raw content of CHANGE_VECTOR.

We can do *whatever we want* with the MLOG$ table, because its an *internal* table.

If you want to replicate changes (to SQL Server), then I'd recommend options such as triggers to capture the data, then your process as you've already described, or look at a tool like Goldengate.

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Pranav Palande, May 27, 2016 - 2:20 pm UTC

We have Dataloads happening of 20-25 millions range in our base tables.We will like to test & implement Trigger method.

Can you please suggest best method to implement trigger in Production Database without impacting the Performance.

Kindly give us suggetions on best ways to implement triggers.

Thank you.
Regards,
Pranav Palande

Chris Saxon
May 27, 2016 - 10:38 pm UTC

OK, can you be more precise here:

"We do dataloads of around 10 million in the base tables of Materialized View Daily. We plan to use the Mview log on the table to insert/delete/update rows on the SQL Server. "

Are you saying you were planning on having a mview log on the tables that make up the materialized view, or on the materialized view itself ?


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library