REFRESH MATERIALIZED VIEW currently calls SetMatViewPopulatedState() even when the materialized view's relispopulated value already matches the state requested by the command. That performs a catalog update of pg_class without changing the visible state of the materialized view. The extra update creates a dead pg_class tuple and causes the usual catalog-update side effects, including relcache invalidation and WAL, for no semantic benefit. The effect is especially visible for REFRESH MATERIALIZED VIEW CONCURRENTLY, where the refresh updates the materialized view contents with DML and otherwise need not change pg_class just to keep relispopulated set to true. Check the current populated state before calling SetMatViewPopulatedState(), and update pg_class only when the value would actually change. This preserves the required state transitions for WITH DATA and WITH NO DATA while avoiding catalog churn for repeated refreshes that leave the populated state unchanged. Author: ChangAo Chen <cca5507@qq.com> Reviewed-by: Zizhuan Liu <44973863@qq.com> Reviewed-by: Adam Brusselback <adambrusselback@gmail.com> Reviewed-by: Fujii Masao <masao.fujii@gmail.com> Discussion: https://postgr.es/m/tencent_DF2D8533B5412908326F7806075B7637A108@qq.com
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.