Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does DBMS_MVIEW.REFRESH have an implicit commit?

I noticed recently that calling dbms_mview.refresh(...), which refreshes materialized views in Oracle, has an implicit commit.

Any ideas - other than "because it does" - why this action has an implicit commit?

like image 909
Nick Pierpoint Avatar asked May 06 '09 09:05

Nick Pierpoint


2 Answers

According to Tom Kyte it is because a decision was made at design time to consider refreshing to be a DDL operation. Since all DDL operations implicitly commit, so does this one. Unfortunatly he doesn't answer the resulting question of why they choose to make it DDL.

like image 116
Leigh Riffel Avatar answered Sep 21 '22 16:09

Leigh Riffel


Depending on your Oracle version and/or the parameters you supply dbms_mview.refresh may be doing a TRUNCATE followed by a direct load. TRUNCATE is a DDL command and as such issues an implicit commit. Direct load does not require a commit.

If you are using a more recent version of Oracle, I think 10.2+, you can set the atomic_refresh parameter to TRUE and it will refresh within a single transaction, using standard DELETE / INSERTs. This method could be quite a bit slower though.

like image 45
David Avatar answered Sep 21 '22 16:09

David