Andrei Kokoev
Andrei Kokoev

Reputation: 57

How does Postgres refresh materialized views?

...let's say the underlying data of a materialized view is 1 million rows. Then, a single row in that data changes. How does Postgres 9.5 process that? I.e., does it rebuild the materialized view from scratch, or only the parts that are affected by the changed row?

Upvotes: 1

Views: 735

Answers (1)

user330315
user330315

Reputation:

Quote from the manual

REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. The old contents are discarded.

(Emphasis mine)

It is essentially the same as:

delete from mview;
insert into mview
select ... 

Where the select is the stored query.

Upvotes: 4

Related Questions