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 1vqGK8-007aZw-14 for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Feb 2026 19:56:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqGK6-005TN4-0h for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Feb 2026 19:56:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vqGK5-005TMu-2y for pgsql-bugs@lists.postgresql.org; Wed, 11 Feb 2026 19:56:30 +0000 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vqGK1-00000000Cgv-0ZSz for pgsql-bugs@lists.postgresql.org; Wed, 11 Feb 2026 19:56:30 +0000 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-45c9fdf2a06so4782356b6e.2 for ; Wed, 11 Feb 2026 11:56:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770839783; cv=none; d=google.com; s=arc-20240605; b=Pu5D9D9jG6hr2L2j+kEA1CSmBFRytXGzQfvslEXH/sO0u4hI8iXxQepIXxC3uzVYgp 4p2sfPa/LXogj/5TLPcbkQr8GOqsM5OIM5K49sHybRxbCryTG6OlKCKRtxmJIMFgCUnA HuPFT0TCfTpcgAEczhHWEGC0qfMf0WDvOMjhe1vwrxhoA0jxd8jd2wQnw+2x3iMI8LDs HBnCnYrDWszTqt1alqKArhk4LbjGZQJZbgt/v3+F6GqQPj9E/q0M+bBp6EpzWygT3dDX dtk/0j2UuspQoY+xL3eQOmuGp8TWdfD87x16CWqkTs621dLnFGmsJfLrM7f2TQL15/mF 0NBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=v7DZ4K3OokQAXMBJFhWvrnexuHfDHIb8T0TqjU97/JA=; fh=UZ2RupGbXr1M5m4uTXiMQoSoiUlO7geb1q/gelp8Hy4=; b=k/OtPxNFMYpubzPzV4EWPY6dewhiclebi6Jyt5rJrP6BCWyG4ZJ8YHoZRu29VsyreL eZ3qG1wzkOXdkUnzRAog4DwuV+fCvQFkwIwR05mtYNo+yp1bKJxIqGxEYKDl30lDqVrY /rSA8+FJi0MlGzroDXQUPiHRrtvETxPy6VsNDZPk5jy2flNoJFfiIV6vz6t/zZPLT3hi /hhWHvp3SZLRHienFoEiTtwTxRrYjgVDmWQUAtLgpa/dU6GjpMpX37oLc7X72il/Md8K L4ctBSU0bfebE9xURtFpUsBHceaKgSSxxmBgn2eT4DQZFNWQ28ectoy3pcDQcAClvKwb lXxw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770839783; x=1771444583; 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=v7DZ4K3OokQAXMBJFhWvrnexuHfDHIb8T0TqjU97/JA=; b=W6x+6eNHCnEggpgIX8WPe3FaFTrXpg5llylArGyluKbzz0l0DDPt1F205oAQFBqdko dzQ8+NN8TaywWlKszI1Vf7oIc0Dh9nz9Y6Ia5v0H9460h6I6DGYUC+8iNyRdyO/L+Q79 Po1F8mG2g4pqe4adETkabnlUuc9Ya+IgKDMXikYunY2PcQLPkdvS8mDCo/A+BcZKaft+ Yvvzy2xsZi4mjaavOMdRdvuyNDhfU1Rp8QhZLD9BZIUbzjTNP7BY6fhRuglr/jvpwKa6 uaP7P78/H/kH12m8tUUcipBT9dCqPBzgCDkuIhBpp5urqbUsVJ6X+5Hhy95UwzGY28Qn FSZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770839783; x=1771444583; 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=v7DZ4K3OokQAXMBJFhWvrnexuHfDHIb8T0TqjU97/JA=; b=RlBotEF0CKmAO7RnX6KyjpWHrH94JpOO1sF5t0N4lgKV6lwTap2JOTgJXgiqB2k2PF L8yhc7s5qK4EuAQelD4MNaJL3tBTWaG3F17lPJz+w4QWm0dxxIAPsT2nMKrd1kHH8AtW gnFag40ZE4A3UEt/AokQdAnvPKfHSV/UBsMEP5j8M1ge1V16hGWMHfoumXXTZfF0JnkP ddlF0RA3Z7HRblqrFwC3OoblS7zbxl5Mp9vi6ma6/rKgBbaadVp3SJHQqeQSaaTznxnH MJbNX6NW45l0PfMf4enT6gM0k46+9XxddEiLUS8zxTE6fA09bfQIzyYBzA4BDK8fdZrY 2CMA== X-Gm-Message-State: AOJu0YzwlvepYmGNaty0FZxow0D/+9hz4dFuCOJHCFYUAa41DvEfoDMR NuVWaIvQLTn4pxFAR0BGHjL7yTbiT4Z/nmIVEP3eWrbwsFsD90e0/iRDrUkRt3+4wWa+/qihLvA eP9bzoXBlLWrIyz3yG0GpxY9vVM6bmqqwR6q5y3c= X-Gm-Gg: AZuq6aImPHjm3Z8ueSrVcGjqz5ULP3iQ5pQF4rJS+2s2VPYMjjzZNDzX+c6m9KLjVX1 KZyFM9MmIT8lAwjmSNwop4A06Kh6kUbxdO1nf8GBp91XjjAObibdS1LFjs0B/pLkVZDwuKrzZ31 EHYGaDORlkk52UQI6G7KDTnEE2AhrOY8egIGBHJ3D2JWK9KaVR/s3wjPCsS8EsSje50oPtakcvC PvntuR5bKQNetU0iXwtGWV6y2MMlRCbLogAZOWrtCnNlOW3FK4GsrDvHkZTkJgbiJ1MRwHpN/3N OO+wQvHOe+O7BAYV6hg= X-Received: by 2002:a05:6808:448c:b0:45e:dbc6:9635 with SMTP id 5614622812f47-4637b913590mr278298b6e.54.1770839782961; Wed, 11 Feb 2026 11:56:22 -0800 (PST) MIME-Version: 1.0 References: <40d694df-39fd-4a4a-9459-9d6489165f60@gogi.tv> In-Reply-To: <40d694df-39fd-4a4a-9459-9d6489165f60@gogi.tv> From: surya poondla Date: Wed, 11 Feb 2026 11:56:12 -0800 X-Gm-Features: AZwV_QgDEfOyFHYafKQxDtgJ9YsxyL5P7-RN5JV42VM0qWIvNX2QzAEjkt0y-ws Message-ID: Subject: Re: Two issues with REFRESH MATERIALIZED VIEW CONCURRENTLY To: Giuliano Gagliardi Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000037b650064a91c45c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000037b650064a91c45c Content-Type: text/plain; charset="UTF-8" Hi Giuliano, Thank you for the test case, yes I am able to reproduce the behavior for issue1 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) > > Adding the output here for a complete picture. postgres=# CREATE TABLE t(a text, b text); CREATE TABLE postgres=# INSERT INTO t VALUES('test', null); INSERT 0 1 postgres=# CREATE MATERIALIZED VIEW m AS SELECT * FROM t; SELECT 1 postgres=# CREATE UNIQUE INDEX ON m(a); CREATE INDEX postgres=# INSERT INTO t VALUES('test', null); INSERT 0 1 postgres=# REFRESH MATERIALIZED VIEW CONCURRENTLY m; REFRESH MATERIALIZED VIEW postgres=# SELECT * FROM m; a | b ------+--- test | (1 row) postgres=# REFRESH MATERIALIZED VIEW m; ERROR: could not create unique index "m_a_idx" DETAIL: Key (a)=(test) is duplicated. postgres=# SELECT * FROM m; a | b ------+--- test | (1 row) Yes, I believe "REFRESH MATERIALIZED VIEW CONCURRENTLY m;" should ideally throw the same error as REFRESH MATERIALIZED VIEW m; I am still trying to understand the CONCURRENTLY behavior in detail and will share more of my findings on this potential issue. Regards, Surya Poondla --00000000000037b650064a91c45c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Giuliano,

Thank yo= u for the test case, yes I am able to reproduce the behavior for issue1
=

I n= oticed 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 duplic= ate
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;
=C2=A0 =C2=A0 =C2=A0-> no error, but m still contains only one row!
REFRESH MATERIALIZED VIEW m;
=C2=A0 =C2=A0 =C2=A0-> error (as expected)

Addi= ng the output here for a complete picture.
postgres=3D# CREATE TABLE t(a= text, b text);
CREATE TABLE
postgres=3D# INSERT INTO t VALUES('t= est', null);
INSERT 0 1
postgres=3D# CREATE MATERIALIZED VIEW m A= S SELECT * FROM t;
SELECT 1
postgres=3D# CREATE UNIQUE INDEX ON m(a);=
CREATE INDEX
postgres=3D# INSERT INTO t VALUES('test', null)= ;
INSERT 0 1
postgres=3D# REFRESH MATERIALIZED VIEW CONCURRENTLY m;REFRESH MATERIALIZED VIEW
postgres=3D# SELECT * FROM m;
=C2=A0 a = =C2=A0 | b
------+---
=C2=A0test |
(1 row)
postgres=3D# REFRESH= MATERIALIZED VIEW m;
ERROR: =C2=A0could not create unique index "m= _a_idx"
DETAIL: =C2=A0Key (a)=3D(test) is duplicated.
postgres= =3D# SELECT * FROM m;
=C2=A0 a =C2=A0 | b
------+---
=C2=A0test |<= br>(1 row)

Yes, I believe "REFRESH MATERIALIZED VIEW CONCURRENT= LY m;" should ideally throw the same error as=C2=A0REFRESH MATERIALIZE= D VIEW m;

I am still trying to understand the CONCURRENTLY behavior = in detail and will share more of my findings on this potential issue.
=

Regards,
Surya Poondla


--00000000000037b650064a91c45c--