public inbox for [email protected]  
help / color / mirror / Atom feed
From: =?utf-8?B?Y2NhNTUwNw==?= <[email protected]>
To: =?utf-8?B?cGdzcWwtaGFja2Vycw==?= <[email protected]>
Subject: Avoid calling SetMatViewPopulatedState if possible
Date: Fri, 10 Apr 2026 11:36:43 +0800
Message-ID: <[email protected]> (raw)

Hi,

During refresh matview, we call SetMatViewPopulatedState unconditionally even
if the value doesn't change. Attach a small patch to optimize it.

--
Regards,
ChangAo Chen


Attachments:

  [application/octet-stream] v1-0001-Avoid-calling-SetMatViewPopulatedState-if-possibl.patch (955B, ../[email protected]/2-v1-0001-Avoid-calling-SetMatViewPopulatedState-if-possibl.patch)
  download | inline diff:
From b4af8a5917d03602b01c16695f57ebda63dc7483 Mon Sep 17 00:00:00 2001
From: ChangAo Chen <[email protected]>
Date: Fri, 10 Apr 2026 11:26:11 +0800
Subject: [PATCH v1] Avoid calling SetMatViewPopulatedState if possible

---
 src/backend/commands/matview.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index f7d8007f796..6e242a2848f 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -296,7 +296,8 @@ RefreshMatViewByOid(Oid matviewOid, bool is_create, bool skipData,
 	 * Tentatively mark the matview as populated or not (this will roll back
 	 * if we fail later).
 	 */
-	SetMatViewPopulatedState(matviewRel, !skipData);
+	if (RelationIsPopulated(matviewRel) == skipData)
+		SetMatViewPopulatedState(matviewRel, !skipData);
 
 	/* Concurrent refresh builds new data in temp tablespace, and does diff. */
 	if (concurrent)
-- 
2.34.1



view thread (8+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Avoid calling SetMatViewPopulatedState if possible
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox