What are materialized views?

前端 未结 6 2239
余生分开走
余生分开走 2021-02-19 06:30

Can someone explain to me what views or materialized views are in plain everyday English please? I\'ve been reading about materialized views but I don\'t understand.

6条回答
  •  爱一瞬间的悲伤
    2021-02-19 06:38

    A view is a query on one or more tables. A view can be used just like a table to select from or to join with other tables or views. A metrialized view is a view that has been fully evaluated and its rows have been stored in memory or on disk. Therefore each time you select from a materialized view, there is no need to perform the query that produces the view and the results are returned instantly.

    For example, a view may be a query such as SELECT account, SUM(payment) FROM payments GROUP BY account with a large number of payments in the table but not many accounts. Each time this view is used the whole table must be read. With a materialized view, the result is returned instantly.

    The non-trivial issue with materialized views is to update them when the underlying data is changed. In this example, each time a new row is added to the payments table, the row in the materialized view that represents the account needs to be updated. These updates may happen synchronously or periodically.

提交回复
热议问题