How often does a database view get updated in MySQL?
Assume I have a view in MySQL:
CREATE开发者_高级运维 VIEW blah AS
SELECT columnA FROM tableA
How often does this view get updated from the underlying table, tableA?
Instantly. Views don't really exist as separate copies of the data, instead they exist as instructions to rewrite queries.
That is, when you select columnA from blah
, MySQL internally rewrites that as select columnA from tableA
.
In systems that support materialized views, the database is responsible for keeping them up to date.
(Note that when the query is complicated enough, MySQL will internally materialize a view, just for the duration of the query. This is an implementation detail and best considered a defect in MySQL's query optimizer. EXPLAIN
can be used to see when this is happening—but you will very likely notice from the terrible performance.)
精彩评论