How to implement Materialized View with MySQL?

前端 未结 4 1870
时光取名叫无心
时光取名叫无心 2021-02-02 12:38

How to implement Materialized Views?

If not, how can I implement Materialized View with MySQL?

Update:

Would the following work? This do

4条回答
  •  臣服心动
    2021-02-02 13:16

    Your example approximates a "full refresh" materialized view. You may need a "fast refresh" view, often used in a data warehouse setting, if the source tables include millions or billions of rows.

    You would approximate a fast refresh by instead using insert / update (upsert) joining the existing "view table" against the primary keys of the source views (assuming they can be key preserved) or keeping a date_time of the last update, and using that in the criteria of the refresh SQL to reduce the refresh time.

    Also, consider using table renaming, rather than drop/create, so the new view can be built and put in place with nearly no gap of unavailability. Build a new table 'mview_new' first, then rename the 'mview' to 'mview_old' (or drop it), and rename 'mview_new' to 'mview'. In your above sample, your view will be unavailable while your SQL populate is running.

提交回复
热议问题