Avoid unnecessary matview populated-state updates 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 <[email protected]> Reviewed-by: Zizhuan Liu <[email protected]> Reviewed-by: Adam Brusselback <[email protected]> Reviewed-by: Fujii Masao <[email protected]> Discussion: https://postgr.es/m/[email protected] Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/33c77cfad3e4d5749a5827f7c8c6394e7cab0b30 Modified Files -------------- src/backend/commands/matview.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
