Oracle Materialized View-general understanding of query rewrite 3

Source: Internet
Author: User
Tags oracle materialized view

In query rewrite, we can see that this technology is inseparable from one thing, the materialized view, mview for short. this is the first Technology launched by Oracle in 8i. In addition to using query rewrite, mview also plays an important role in master-slave replication, here we are mainly concerned about query rewrite. Oracle is getting stronger and stronger in query rewrite. in Oracle 8i, it is basically the query rewrite of text match, there is a large update in 9i/10g. It also supports general query rewrite (except for text match). If you can try the last SQL statement, you cannot rewrite in 8i, in 9i, you can:

SQL> DESC mvtest8
Name null? Type
-------------------------------------------------------
Owner varchar2 (30)
Object_name varchar2 (128)

SQL> Create materialized view mv8_test
2 enable query rewrite
3
4 select owner, count (*) rowcnt from mvtest8
5 group by owner;

SQL> select count (*) from mvtest8 where owner = 'sys ';

When using mview to implement query rewrite, you need to have a basic understanding of mview. The main points are as follows:

1. The design of mview can meet the requirements of SQL rewrite.
2. For mview refresh, mivew is an intermediate table and the data may not be updated. It is also important for a large amount of data refresh methods.

In fact, there are some conflicts between these two points. To implement the first point, complicated mview definitions may help improve the execution efficiency after query rewrite, however, for a complex mview, all records may be copied for each refresh. For mview refresh, mview can be incrementally refreshed when there is a mview log, in general, the following conditions must be met for incremental Refresh:

1. In mview SQL, functions with uncertain return values, such as sysdate and rownum, cannot be included.
2. When the mview SQL statement only includes a summary, it is best to add grouping functions such as Count (*) and count (field.
3. mview SQL only includes join.

The syntax for creating mview and mview log is not mentioned here. mview Refresh has three options: full refresh; fast: Incremental refresh using mview log; force: if you cannot use fast, use full. there are two main types of refresh time: On Demand: manual refresh (crontab, job, schedule, etc.), on commit: refresh immediately after commit (must be fast, otherwise you are miserable ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.