| From: | Fujii Masao <fujii(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Avoid unnecessary matview populated-state updates |
| Date: | 2026-08-12 05:44:35 |
| Message-ID: | E1wu1lS-00000000DSh-1vmh@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <cca5507(at)qq(dot)com>
Reviewed-by: Zizhuan Liu <44973863(at)qq(dot)com>
Reviewed-by: Adam Brusselback <adambrusselback(at)gmail(dot)com>
Reviewed-by: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Discussion: https://postgr.es/m/tencent_DF2D8533B5412908326F7806075B7637A108@qq.com
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Amit Kapila | 2026-08-12 06:02:26 | pgsql: Remove unnecessary list_free() calls in OpenTableList(). |
| Previous Message | Michael Paquier | 2026-08-12 03:09:34 | pgsql: Move index statistics into their own stats kind |