Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSpyd-006UUA-0Y for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 05:09:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSpyb-002tTG-2a for pgsql-hackers@arkaria.postgresql.org; Tue, 09 Dec 2025 05:09:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vSpyb-002tT7-1G for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 05:09:29 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSpyZ-003sCZ-0X for pgsql-hackers@lists.postgresql.org; Tue, 09 Dec 2025 05:09:28 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-477619f8ae5so40187725e9.3 for ; Mon, 08 Dec 2025 21:09:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765256965; x=1765861765; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IU8vo+Wj9W5A1s4xvrdZM8BX3UA8GuA7Oiin0/ZQNLI=; b=CwqjPkIXcGXv0g0UwScuC0FBtDNtK5qLPxWoY4PAMnGR/oj79Ww4PJuD6T5m3radux +k8oxIJk6vFJBFoeLLJ7CKkvnWjSssZB2jpzAMCzd4VIEsrhdfgKKGNXH89SNcEnzO4u otMngUMueWShipgn4BlJi5EP9j1novSLtiTplW31T3QuBcyYC2RmFXjhipuh+87pl/RR +j+HRFabwSEvuC+rKp4IXsO8zFPIOXzlRajIY+pOIkW6W8I9US+uSnpdJnQpi92J0+iL K+gXQdb9+sgPyhNzDo8uQta+i9JrUPM2ritQhCcV4GQ9snYVvm42KA+Q46gjE9PaSv5c 69wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765256965; x=1765861765; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=IU8vo+Wj9W5A1s4xvrdZM8BX3UA8GuA7Oiin0/ZQNLI=; b=noQNy2ILoFh0Fo9GsIrR2cF2YaBm7SMS7LusNXr0M0DPRboSozZXmMn5eqAtlncvD0 2xJqzbd+ZcQrmeRSHwMpux78BnhLZtYJXNTE34J1E/NjVzjxQhOwSdDIec3JCdFZKz02 iHPQfT8ObaL5S2qfVpCZYz3EbJL7Emck0ldXdxoOrUkRu0JcCTh1kMTlynjM2p6UVRxB +e+Llfox8s3Orbs57Mk+N7T5nVtXApeQwYwWu2kG57yLn04zl2uJtNyeZugbw+0A4kFN nNkO2Dib8tLkqVPX+lDesWfv4v2a9zd9t3rfbDn56CSvWrpSnRdd5JSVE0IMx9rkLxTZ H59Q== X-Gm-Message-State: AOJu0YzktZOA/TZLGZ03DNFUY9oxKyatulXpl34J2BeLXv3vHZ8LuA1+ jo5D7AF4y4bnRpvIvhknnTIW1d+ZGIp+ZmPBlwJgAeVjog8BVdf/SN/gFEEf72IHicNHb+1JmWN TFp+AiA3+WSBLGqpzgp3P1ukK66iipfC+3w== X-Gm-Gg: ASbGncucAogXvpNgCUXaY9Ha8AzeMv27GxF4VKI12lIXYT3y/c3wsYKTcp9I2DRqqWh qvuGjdadYg0xrrhjawi83pl+WBwLhJt1swzt56muYfOl/UKoo3V764+X12CER51dm1rf0f+CL2J FGgO5Xa24ACP2kAt+NZzXaTLyKswZZOlz/z/MvqT1gKlklSHPgwi+UyWq3Hdncg23hUvAne7MpQ +5D4QqYmxnVd/VusdLr8prUA+Izi7DNRh41ykRfXm/nugPH5Viju5fB1mLnDPshEm1NOu4E5ihA 5EyYncLj0gsrXM9mq3Q+xJZ0oxbpdm+PCb1YcIE/qwFJsiFiMxQibeljYg== X-Google-Smtp-Source: AGHT+IG+eB4Fmgb3sLvgPoy8Qgj+vvaw2E3d78dgNPOQwocIVa8XF5UJAdC2rEpdhXtoQnciWZCMccLN49/gnAjMTJk= X-Received: by 2002:a05:600c:d8:b0:479:3a89:121d with SMTP id 5b1f17b1804b1-4793a891252mr69677035e9.36.1765256964599; Mon, 08 Dec 2025 21:09:24 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Kirk Wolak Date: Tue, 9 Dec 2025 00:08:58 -0500 X-Gm-Features: AQt7F2rTx73zV6mqNfKAxwiebU2Ta_QTAq_SNZGeuo2SnVQjM0wpMC92UbDflaY Message-ID: Subject: Re: [Patch] Add WHERE clause support to REFRESH MATERIALIZED VIEW To: PostgreSQL Hackers Cc: Adam Brusselback , Nikolay Samokhvalov , Andrey Borodin Content-Type: multipart/alternative; boundary="0000000000004ff2de06457dead9" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004ff2de06457dead9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 8, 2025 at 3:58=E2=80=AFPM Adam Brusselback wrote: > Attached is a patch implementing support for a WHERE clause in REFRESH > MATERIALIZED VIEW. > > The syntax allows for targeted refreshes: > REFRESH MATERIALIZED VIEW mv WHERE invoice_id =3D ANY('{1,2,3}'); > REFRESH MATERIALIZED VIEW CONCURRENTLY mv WHERE customer_id =3D 42; > REFRESH MATERIALIZED VIEW mv WHERE order_date >=3D '2023-01-01'; > > I was inspired to implement this feature after watching the Hacking > Postgres discussion on the topic: > https://www.youtube.com/watch?v=3D6cZvHjDrmlQ > > +1 (But I was in that hacking session). Our situation was a wonderful MV with all the columns we needed (some hard to calculate) to augment search data done millions of times/day. It was a thing of beauty. Until we realized we needed to update 1 record (vendor inventory UPDATE date/time) every time we processed a file (something we do 24x7, a hundred times each hour! For that ONE field, we ended up doing REFRESH MV concurrently; OVER 2,000 times per day. Our understanding is that many people run into this exact issue. The cache needs small frequent updates. (After reading the code that handles MVs, we just created our own TABLE, and maintain it with a scheduler to rebuild HOURLY, and when we process the file, a Simple UPDATE is issued for the one column)= . While this "Works", the CONCEPT of this patch (untested by me, as of yet), would have fixed this with far less effort, and would be easier to maintain. After I review the code, I will add additional comments. I am curious what others think? (And FWIW, I believe that the larger the MV, the MORE this feature is needed, vs refreshing the ENTIRE view). Regards... > --0000000000004ff2de06457dead9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Dec 8, 2025 at 3:58=E2=80=AFPM Ad= am Brusselback <adambrussel= back@gmail.com> wrote:
Attached is a patch implementing support for a WHERE clause in REFRESH MAT= ERIALIZED VIEW.

The syntax allows for targeted refreshes:
=C2=A0 = =C2=A0 REFRESH MATERIALIZED VIEW mv WHERE invoice_id =3D ANY('{1,2,3}&#= 39;);
=C2=A0 =C2=A0 REFRESH MATERIALIZED VIEW CONCURRENTLY mv WHERE cust= omer_id =3D 42;
=C2=A0 =C2=A0 REFRESH MATERIALIZED VIEW mv WHERE order_d= ate >=3D '2023-01-01';

I was inspired to implement this f= eature after watching the Hacking Postgres discussion on the topic: https:= //www.youtube.com/watch?v=3D6cZvHjDrmlQ

= +1 (But I was in that hacking session).

=C2=A0= Our situation was a wonderful MV with all the columns we needed (some hard= to calculate) to augment search data done millions of times/day.=C2=A0 It = was a thing of beauty.=C2=A0 Until we realized we needed to update 1 record= (vendor inventory UPDATE date/time) every time we processed a file (someth= ing we do 24x7, a hundred times each hour!

=C2=A0 = For that ONE field, we ended up doing REFRESH MV concurrently;=C2=A0 OVER 2= ,000 times per day.

=C2=A0 Our understanding is th= at many people run into this exact issue.=C2=A0 The cache needs small frequ= ent updates.
(After reading the code that handles MVs, we just cr= eated our own TABLE, and maintain it with a scheduler to rebuild HOURLY,
and when we process the file, a Simple UPDATE is issued for the one= column).

=C2=A0 While this "Works", the= CONCEPT of this patch (untested by me, as of yet), would have fixed this w= ith far less effort,
and would be easier to maintain.
<= br>
=C2=A0 After I review the code, I will add additional comment= s.

=C2=A0 I am curious what others think?=C2=A0 (A= nd FWIW, I believe that the larger the MV, the MORE this feature is needed,=
vs refreshing the ENTIRE view).

Regards...
--0000000000004ff2de06457dead9--