How to implement Materialized View with MySQL?

前端 未结 4 1862
时光取名叫无心
时光取名叫无心 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:34

    This thread is rather old, so I will try to re-fresh it a bit:

    I've been experimenting and even deployed in production several methods for having materialized views in MySQL. Basically all methods assume that you create a normal view and transfer the data to a normal table - the actual materialized view. Then, it's only a question of how you refresh the materialized view.

    Here's what I've success with so far:

    1. Using triggers - you can set triggers on the source tables on which you build the view. This minimizes the resource usage as the refresh is only done when needed. Also, data in the materialized view is realtime-ish
    2. Using cron jobs with stored procedures or SQL scripts - refresh is done on a regular basis. You have more control as to when resources are used. Obviously you data is only as fresh as the refresh-rate allows.
    3. Using MySQL scheduled events - similar to 2, but runs inside the database
    4. Flexviews - using FlexDC mentioned by Justin. The closest thing to real materialized

    I've been collecting and analyzing these methods, their pros and cons in my article Creating MySQL materialized views

    looking forwards for feedback or proposals for other methods for creating materialized views in MySQL

提交回复
热议问题