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 1w7Tve-005MKd-2Z for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 07:54:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7Tvc-008gGo-39 for pgsql-hackers@arkaria.postgresql.org; Tue, 31 Mar 2026 07:54:25 +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 1w7Tvc-008gGg-1o for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 07:54:25 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7Tva-00000001w1r-34Er for pgsql-hackers@lists.postgresql.org; Tue, 31 Mar 2026 07:54:23 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2b258d93ffeso9268335ad.3 for ; Tue, 31 Mar 2026 00:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774943661; x=1775548461; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WqiJSjwtFaC8AJlyawFbdP4CQYZoya5JpyLajfwDqDM=; b=Ttw3UTlV8JcNkSqOyicLXPYRyD4SROxYvOWr5dsgW0ji8DZ49tXHR+HYrxvv6FK/D9 KbCKD69svzd20hsGmcKv2+enz552dSpJG8Qf3f1s8qxHjGBed/BvE76qhmASGadbNcSG z3Gd1C/zxxq1DRwF+FOh42tlzIEhKQ4t09chIAOpRipJDJ8/5ar4G5qBlF0F4SgK+nP7 W4t4NgcKifB8ldfpJEFsWZIH+4GWkSxLiIdllOhkIdzPKkZThJ3Xac6/MsPlSOHt85o6 85s+vGRyiIKIqlupSNp7UjBJezeebW05ofyxc1PtOXS9cr7BMd6LLxT7bHhvrUuNzquN zyYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774943661; x=1775548461; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WqiJSjwtFaC8AJlyawFbdP4CQYZoya5JpyLajfwDqDM=; b=EslGsohPIyQy7CPDjBDuktw22uhl23nl6+/ECdiE5suHudhOBCAL5jOaGRK9NyjYhO 4Rtwq9ILhs+0Tnq9DiSvR4V7ThKMEpuCiZDR7oyynk6Lksuiud9SXEDxMskPRZehDrMl g8+3tx8l13hDXam2O+zPclgEV/0WOgoAXHix9mDGS2bOaRd0YkNAg7gE0YPY7kjodoWc BaMFUuHiOJii1vf+JPRemkd8F7XkD4bbtwK54Y2QJ+rHvKSjxtxnEV6YxkSdIo+rE3jw /pTTOs8IAstqhvWq99VcsLH/14rddG9DjQMFB8TTF5F1N0YqZuDFHivGBY1yrLoLFuks Q8Yw== X-Forwarded-Encrypted: i=1; AJvYcCXUmH5qP6VJNrmalvcgVFcHcmiKNqRsk2fYpGdz53d38KVjLcFxUi+Hb4OKX/8v0QKpxqEAoar1PctGRSm1@lists.postgresql.org X-Gm-Message-State: AOJu0YycOUD1TPlt1yG/MgGYBcNOrH9FJHwP2U8zPHL5HPwuByElHIlr Zt4RIR2yqJ7vyKRiT8yEFU3xizPGJpn/dWErEzIOTj9UyBFQOwLAnt4s X-Gm-Gg: ATEYQzyGUf+sldOs3jBskax9njL88bTeERBk1ym9X0Q/NJPE8Pxh0kVAUTmPz98ZbGW RGGoTPCPQZxXOyn6aLBw+xMPvGvo2sSiYfqEvAdwyhSQItSTVYmkaSfNYkDn0wD1tQh+pJSmMcQ UDtdLKooZeVfs37bMN3aIgOJzsXR8Uy7+c0l8qbyQeLrrp6GJuoeo/tUclTLAjAD2dwAR6z6tW2 0QxG3OGSFk4RQ4Zsq2JN8Dl9KZnMVkMoD2MLIftuw4qY/3iHOBWIv16zFGXpf1wlsex7ECdzIbz ua0spWnSVwqfjZDJUs7rf41utcOuYy8Iklgv2eK7CMoGG8Vm8r/C7HcUq0LD9h3YrcA5pw+r/vF U54gIh3RFCzJByXESoBUAyDr3borrkbep3G1neNQ+bZVpuq9D28vYZZBua6SAQLhRcViYC1h+5e lIHA+FO86LQ3ND0Xa0Lm8U8/a+gyAKzw== X-Received: by 2002:a17:903:40cf:b0:2b2:5035:dc3a with SMTP id d9443c01a7336-2b25035e037mr82629005ad.42.1774943661393; Tue, 31 Mar 2026 00:54:21 -0700 (PDT) Received: from smtpclient.apple ([203.10.98.27]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b24264286fsm107672675ad.14.2026.03.31.00.54.19 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Mar 2026 00:54:20 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: Bug: wrong relname in RemoveSubscriptionRel() error detail From: Chao Li In-Reply-To: Date: Tue, 31 Mar 2026 15:53:46 +0800 Cc: "Zhijie Hou (Fujitsu)" , Nisha Moond , PostgreSQL Hackers Content-Transfer-Encoding: quoted-printable Message-Id: References: To: Amit Kapila X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mar 30, 2026, at 20:19, Amit Kapila = wrote: >=20 > On Mon, Mar 30, 2026 at 1:44=E2=80=AFPM Zhijie Hou (Fujitsu) > wrote: >>=20 >> On Monday, March 30, 2026 2:33 PM Chao Li = wrote: >>>> On Mar 30, 2026, at 14:16, Nisha Moond >>> wrote: >>>>=20 >>>> On Fri, Mar 27, 2026 at 3:22=E2=80=AFPM Chao Li = wrote: >>>>> This looks like a first-day bug introducing by ce0fdbf, so I think = it=E2=80=99s worth >>>>> back-patching. >>>>>=20 >>>> I tried reproducing the said bug on HEAD, but it doesn=E2=80=99t = seem to exist >>>> in the current code. >>>>=20 >>>> To hit the mentioned error, the subid has to be invalid - >>>> if (!OidIsValid(subid) && <=3D=3D >>>> And currently, the only path that uses an invalid subid is via >>>> heap_drop_with_catalog() : >>>> =E2=80=A6 >>>> /* >>>> * Remove any associated relation synchronization states. >>>> */ >>>> RemoveSubscriptionRel(InvalidOid, relid); >>>> =E2=80=A6 >>>>=20 >>>> But here relid is always a valid OID (it's the table being = dropped). >>>> The corresponding pg_class row is deleted after >>>> RemoveSubscriptionRel(), i.e. via a later call to >>>> DeleteRelationTuple(relid); >>>>=20 >>>> It can only happen with a hypothetical future caller of >>>> RemoveSubscriptionRel(InvalidOid, InvalidOid). And in that case, = using >>>> "subrel->srrelid" would be correct. >>>>=20 >>>> So this doesn=E2=80=99t appear to be a real issue in the current = code, and >>>> doesn=E2=80=99t look like a bug to fix now. IMO, if such a caller = is added in >>>> the future, we can add a guard at that point. >>>>=20 >>>> -- >>>> Thanks, >>>> Nisha >>>=20 >>> Hi Nisha, >>>=20 >>> Thanks for your review. >>>=20 >>> I think one current call site may have been overlooked. In = DropSubscription(), >>> we have: >>> ``` >>> /* Remove any associated relation synchronization states. */ >>> RemoveSubscriptionRel(subid, InvalidOid); >>> ``` >>=20 >> This won't trigger the bug either, since it passes a valid = subscription OID to >> the function, while the function only reports an error when an = invalid OID is >> passed. >>=20 >>>=20 >>> I agree this is an edge-case bug and may be difficult to reproduce = in practice. >>> But from the function=E2=80=99s semantics, it seems clear to me that = the wrong >>> relation OID is used in the error detail, regardless of how easy it = is to trigger >>> today. >>=20 >> Since this is a public function, I think it should be OK to fix it as = it's good >> to make the function future-proof anyway. >>=20 >=20 > Even if it is exposed, it is not clear to me in which case one would > like to use it the way it can lead to a problem. I feel unless we have > some concrete case it may not be beneficial to change it. >=20 > --=20 > With Regards, > Amit Kapila. Hi Amit, Yes, I agree there is no current use case that would trigger this bug. Looking at the function header comment again: ``` /* * Drop subscription relation mapping. These can be for a particular * subscription, or for a particular relation, or both. */ void RemoveSubscriptionRel(Oid subid, Oid relid) ``` Looks like the function comment does not clearly say that both subid and = relid being InvalidOid is a supported case. To me, =E2=80=9Ca particular = subscription=E2=80=9D or =E2=80=9Ca particular relation=E2=80=9D reads = as a specific valid OID, so the comment is really silent about the case = where both are invalid. If we consider subid =3D=3D InvalidOid && relid =3D=3D InvalidOid to be = invalid usage, then I think it would be better to make that explicit, = for example by documenting it and adding an Assert. Otherwise, the = current behavior can still lead to a misleading error detail in that = path. =46rom the code readability perspective, I also think subrel->srrelid is = a better choice here regardless. This error is reporting the relation = whose table synchronization is actually in progress, and that relation = comes from the current mapping row, not from the input argument used as = a filter. So using subrel->srrelid makes the code and the error = construction easier to understand. Given that there is no known practical case that triggers it today, I = agree that back-patching is not needed. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/