Oracle のビューとマテリアライズド ビューの違いは何ですか?
8 に答える
マテリアライズド ビューはディスク ベースであり、クエリ定義に基づいて定期的に更新されます。
ビューは仮想のみであり、アクセスされるたびにクエリ定義を実行します。
Views
They evaluate the data in the tables underlying the view definition at the time the view is queried. It is a logical view of your tables, with no data stored anywhere else.
The upside of a view is that it will always return the latest data to you. The downside of a view is that its performance depends on how good a select statement the view is based on. If the select statement used by the view joins many tables, or uses joins based on non-indexed columns, the view could perform poorly.
Materialized views
They are similar to regular views, in that they are a logical view of your data (based on a select statement), however, the underlying query result set has been saved to a table. The upside of this is that when you query a materialized view, you are querying a table, which may also be indexed.
In addition, because all the joins have been resolved at materialized view refresh time, you pay the price of the join once (or as often as you refresh your materialized view), rather than each time you select from the materialized view. In addition, with query rewrite enabled, Oracle can optimize a query that selects from the source of your materialized view in such a way that it instead reads from your materialized view. In situations where you create materialized views as forms of aggregate tables, or as copies of frequently executed queries, this can greatly speed up the response time of your end user application. The downside though is that the data you get back from the materialized view is only as up to date as the last time the materialized view has been refreshed.
Materialized views can be set to refresh manually, on a set schedule, or based on the database detecting a change in data from one of the underlying tables. Materialized views can be incrementally updated by combining them with materialized view logs, which act as change data capture sources on the underlying tables.
Materialized views are most often used in data warehousing / business intelligence applications where querying large fact tables with thousands of millions of rows would result in query response times that resulted in an unusable application.
Materialized views also help to guarantee a consistent moment in time, similar to snapshot isolation.
ビューはクエリを使用して、基になるテーブルからデータを取得します。
マテリアライズド ビューは、クエリの結果セットを含むディスク上のテーブルです。
マテリアライズド ビューは、主に、インデックスが適用された標準ビューを使用することが不可能または望ましくない場合に、アプリケーションのパフォーマンスを向上させるために使用されます。マテリアライズド ビューは、トリガーまたはON COMMIT REFRESH
オプションを使用して定期的に更新できます。これにはいくつかの追加のアクセス許可が必要ですが、複雑なことは何もありません。ON COMMIT REFRESH
少なくとも Oracle 10 から導入されています。
マテリアライズド ビュー- クエリの結果セットを含むディスク上のテーブル
マテリアライズされていないビュー- 基になるテーブルからデータを取得するクエリ
ビューは本質的に、特定のクエリによってその場で入力される論理的なテーブルのような構造です。ビュー クエリの結果はディスク上のどこにも格納されず、クエリが実行されるたびにビューが再作成されます。マテリアライズド ビューは、データベース内に格納され、ディスクに書き込まれる実際の構造です。これらは、作成時に定義されたパラメーターに基づいて更新されます。
ビュー:ビューは単なる名前付きクエリです。何も保存しません。ビューにクエリがある場合、ビュー定義のクエリを実行します。実際のデータはテーブルから取得されます。
マテリアライズド ビュー:データを物理的に格納し、定期的に更新します。MV を照会している間、MV からデータを取得します。
マイク・マカリスターのかなり徹底した回答に追加...
マテリアライズド ビューは、ビュー クエリがコンパイラによって単純であると見なされた場合にのみ、データベースが変更を検出して自動的に更新するように設定できます。複雑すぎると考えられる場合は、ソース テーブルの変更を追跡して mview テーブルの変更された行のみを更新するための本質的に内部トリガーをセットアップすることができません。
マテリアライズド ビューを作成すると、Oracle は mviewと同じ名前のテーブルの両方を作成するため、混乱を招く可能性があります。