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 1vpL5M-0063PP-0D for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Feb 2026 06:49:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vpL5L-009VUF-0O for pgsql-bugs@arkaria.postgresql.org; Mon, 09 Feb 2026 06:49:26 +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 1vpL5K-009VU7-1o for pgsql-bugs@lists.postgresql.org; Mon, 09 Feb 2026 06:49:26 +0000 Received: from box.gogi.eu ([85.214.124.207]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vpL5H-00000001EfZ-3Jzh for pgsql-bugs@lists.postgresql.org; Mon, 09 Feb 2026 06:49:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gogi.tv; s=helium; t=1770619760; bh=wW0DzXb7Eis4BNlgrRgGgysKc4Oithowqk8xWosxI2Q=; h=Date:To:From:Subject:From; b=jiVROHtDEHDwyzni2M871dNbCCDkPHkjsnhkMblBcTVsmDPqHNKeaR15zy3iN+3Wm MVY2ONo9V14SHPzlkXyrToFNaH9jqzbwGKxTJh1QhjtJOmoNOxWJa8TVc9DOrcW0qR Ca4Bt5MZbdfDGltMWF8L+B0L89Be3h/aEuyIi3bOMkklVMLjlE+1ObdUkEMPtNB1qb utzzLXDi4ebrYeTLVwHRul27Kavn8LAozXnVaL9/1hNfn6+ermtN0HbegPb2TvbdpP OkrmFJRiY9Dk9kMt2ZeCMV6CmYI0Vl3qTkwAw9/mT7AlWnuwZk+GjrDLzQgnRGWd7o SxEWgmMDDKidQ== Received: from [IPV6:2001:8e0:3900:c110::1f2] (2001-8e0-3900-c110--1f2.bbcs.ip6.as8758.net [IPv6:2001:8e0:3900:c110::1f2]) by box.gogi.eu (Postfix) with ESMTPSA id 9C6743A026D for ; Mon, 9 Feb 2026 06:49:20 +0000 (UTC) Message-ID: <40d694df-39fd-4a4a-9459-9d6489165f60@gogi.tv> Date: Mon, 9 Feb 2026 07:49:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pgsql-bugs@lists.postgresql.org From: Giuliano Gagliardi Subject: Two issues with REFRESH MATERIALIZED VIEW CONCURRENTLY Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I noticed the following two issues while looking at the code that handles REFRESH MATERIALIZED VIEW CONCURRENTLY (refresh_by_match_merge() in matview.c): 1. At the beginning of the function, there is some code that checks for duplicate rows, but it does not catch the following case: CREATE TABLE t(a text, b text); INSERT INTO t VALUES('test', null); CREATE MATERIALIZED VIEW m AS SELECT * FROM t; CREATE UNIQUE INDEX ON m(a); INSERT INTO t VALUES('test', null); -- t now contains two identical rows REFRESH MATERIALIZED VIEW CONCURRENTLY m; -> no error, but m still contains only one row! REFRESH MATERIALIZED VIEW m; -> error (as expected) 2. Do I understand correctly that the join creating the "diff" table is given equality conditions for all columns referenced in any unique indexes? This led me to think that a unique index on a column with many null entries would enlarge the "diff" table. In the following example, creating the second unique index noticeably worsens the performance of REFRESH MATERIALIZED VIEW CONCURRENTLY: CREATE MATERIALIZED VIEW s AS SELECT generate_series as x, null as y FROM generate_series(1, 1000000); CREATE UNIQUE INDEX ON s(x); REFRESH MATERIALIZED VIEW CONCURRENTLY s; -> runs for ~1700 ms CREATE UNIQUE INDEX ON s(y); REFRESH MATERIALIZED VIEW CONCURRENTLY s; -> runs for ~9000 ms Kind regards, Giuliano