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 1w5vrY-003m5z-2R for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 01:19:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w5vrW-006wTj-2v for pgsql-bugs@arkaria.postgresql.org; Fri, 27 Mar 2026 01:19:47 +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 1w5vrW-006wTa-1o for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 01:19:47 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w5vrT-00000001OEg-2IpG for pgsql-bugs@lists.postgresql.org; Fri, 27 Mar 2026 01:19:46 +0000 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-b7cf4a975d2so205715466b.2 for ; Thu, 26 Mar 2026 18:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774574381; cv=none; d=google.com; s=arc-20240605; b=gbi5RT1Fq/4GeGfgxDc7CFCWSWbD/ntUaYO52GURrIZ5ZHehcCF6ygmQnpW5ukhysF 9i39bsL93W89+yaTZQcOUCseh9F7DiBgotiM0oZD1mqRJQZ3WPahOlBAB5nNHzhQ8g5Z dzE7AAW5ZMWJMQ6i9EA0JIqupHcmNP7dgSwLUpUhwHbkOjRDRptpmtxl+fxZnVAUNpaU epqhtsZ9P7jsOgvv3ZBUDNzp44PoRG6zkd+syx44VeFyhd1fQI7jVDI+1GN070IH+gzA Y+PDWnKPlRvXdGQZrYegygVSYp+agL0lmZIcgdmKq3Iwr1JmLmkeQ/qKbiwwYe+CYsIc txlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=iKYvukF1KkZX1LNtMJUnrtjE9yoLEKLKN5v8U5PyzRo=; fh=s5fXy6iGPpmxEXd3vG75hCSckbMrtEfp7g8UbzBGHnA=; b=hgPuVST0IbHf1w0SS/+HrCh2C5NBLnpPW0cvKgt+kweM2S9usJk7UdgDg0Gkkonau4 RoMXoA42rDPGL7Warh4tu0LLZEjYuz91c9PJjwAxiZCPyVNDND3uSPafBGAwwCAa6nKZ V1iux9+0T2Hqh1C3sukImUfcKyTrzas5VVR2DVlLPU87qy59CVwPVhfIECeJa84udbKN jqWoHrocQIRL8MJSl++JVPK/16w0kshACi0SojY12JdmLt9wtraR6eMzyRIozm8dngHd wBAfJtTvx76P+AvyWY0edFsxElHLrHQYfOybESHn8pm7c7pE2Z9CMwVBY/neTiYFuMyv 0twg==; 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=20251104; t=1774574381; x=1775179181; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=iKYvukF1KkZX1LNtMJUnrtjE9yoLEKLKN5v8U5PyzRo=; b=f1WCAMQ4NpYbFdRXHUGFXNqyw3vd7a3K8fNL8LiduG0agpLXnE7jbfugSVFL7dxjoN KCdqvBSkQwVwHvhtFUC08YcBXspUcWnpI+VUeNyRivXD6V4SIeGh0/dGQmTGTWB0o3+t p9A2+wQSdQN4fwm8r9muMSUytwGaHFfuqPfNl/dF9h5gytCrzMMxfcJ/thiY21n1U3gF 5Cx0p0AJoXvTEHsr1FBdFQh9QOdpamTLuVWdavQTlHkWlXlQp82bnoCxaa2qm0m9RuSd uAskBRJtR5JzOzMwVXZPzXpzI/pm3UPKmDnCA7oGhAtU+Y8VPhCOrjkYTAZIfT7id0IL zZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774574381; x=1775179181; h=content-transfer-encoding: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=iKYvukF1KkZX1LNtMJUnrtjE9yoLEKLKN5v8U5PyzRo=; b=BIDN2TU9rQ8CgrlN2qpt/ufrO/mMMcnuCT+GvNLFF5yIMi4fq60PtituUfIol0j8mT 8jH0EGk5xHlWK9uz8+i1kE/HDz0YzfWf2mIWwvnEP1BmC89B+qMA4DHh1Km1pGJXibUv ViBlqeP0dnRlqZkaKNLtUJno8FLOUkQpHDzgSAR3aev9+zbx0qevWjX9HtWFCuJWJ31F qrzdOwr7t7Ec3zNHizJo31f1YsxVNFYFL/USMXb2EYqeRTw9wXD5aidXd7NUvH5XZTKT MR//9t2koZGVl2P5ZmH60GPciyiWpd8NunvBNjpa0K7VRi644hy6F/Vbunj2nPrkBfBS zXMA== X-Forwarded-Encrypted: i=1; AJvYcCWc6n2Z/tgqE9uF/UJI4cZAM2ZTp1SzuaejX0RZLX9Ea8LJzD9rQNj2k/haCxHEflBTbDCDJgxyPMIo@lists.postgresql.org X-Gm-Message-State: AOJu0YxXIre9wQ13ixeQPoTeNq2RPWKdHEa8dgogVeMB/Qdqmy3pDYFV uWtIGdVIQPunoUjfS4AFQFBJhJW0UibVMmCOisXTneynHAjkQ0uvegw53TrjiF2w/U7feFQNGEA OxZj6H7HBmWeLLeWx7F36f0Qvvara59M= X-Gm-Gg: ATEYQzw/Q2FWBZ34bIu/5PjsM2/n2dDzaHBMmKwlmUgERvxsDkadXUSvBu2LruGcPlt +aKP6GWElzg/oM23TNw0y1NMrevKVD67gfonYBi0NGjUgg8Lyg+ZXOGnshZQPd/Bg0O5HFtgO7O WhjZdYz5+4vYx/v2HyUTpgn1NrEcSj4IKm6C2D2Q0R2Ie/6h1xAYg358F351/fIngSLdSV2/7/m IBYDEi0frZ0bGzfNzKcJXRJkLIz4rg/9akSQyktDq1nO61+6EXXJyjRaVQhF1KDjEIgIQG5E4Dy H+pQwI6L X-Received: by 2002:a17:907:3e07:b0:b9b:2456:989c with SMTP id a640c23a62f3a-b9b502beaaemr33089366b.6.1774574380584; Thu, 26 Mar 2026 18:19:40 -0700 (PDT) MIME-Version: 1.0 References: <19435-3cc1a87f291129f1@postgresql.org> <5a039d60-d13b-4cf0-a807-9c7269f06831@gmail.com> In-Reply-To: From: Tender Wang Date: Fri, 27 Mar 2026 09:19:29 +0800 X-Gm-Features: AQROBzAFpp7oMRDwVx5bpkjCgaFCRDqK6zjRPoo_SI_ShCrrbSXY_9e-ao8LwXk Message-ID: Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables To: Andrei Lepikhov Cc: Alexander Korotkov , Kirill Reshke , Fujii Masao , ammmkilo@163.com, pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrei Lepikhov =E4=BA=8E2026=E5=B9=B43=E6=9C=8827=E6= =97=A5=E5=91=A8=E4=BA=94 03:59=E5=86=99=E9=81=93=EF=BC=9A > > On 20/3/26 15:02, Alexander Korotkov wrote: > > OK. I've pushed this. Let's go back to > > restrict_infos_logically_equal(). I'm still not convinced that we > > need to check if required_relids is singleton. Why we can ignore > > outer_relids for singleton, but can't do if, for instance, two > > relations involved? > > Let's continue. In the attachment, the Tender's proposal that I changed > a little and added some tests. > > As you can see in the tests, the SINGLETON limitation keeps duplicates > of clauses like 'a.x + b.y =3D c'. > This example shows the main flaw of this approach. Introducing the > restrict_infos_logically_equal(), we do a little more job than just the > equal() routine could because of the context where we call this function > and on which clauses. > But skipping all other RestrictInfo fields except required_relids seems > excessive. - see the example with security_level difference - ignoring > its value, we potentially might remove the clause with enforced security > level in favour of an unsecured one. Yes, it seems too strict to require all fields to be equal, but skipping some fields is unsafe. > That's more, further some new optimisations might introduce more fields > into RestrictInfo that should be checked to correctly decide on the > equality, and we may forget to arrange this specific place. > Agree. > So, formally it works, and making the following replacement, we close > the singleton issue: > > - if (bms_membership(a->required_relids) =3D=3D BMS_SINGLETON && > - a->security_level =3D=3D b->security_level) > + if (bms_equal(a->required_relids, b->required_relids) && > + a->security_level =3D=3D b->security_level && > + a->is_pushed_down =3D=3D b->is_pushed_down) > The singleton issue does not seem to be the correct way; I don't dive deeply to cover all cases. > but I'm unsure, in general, that this approach is conservative enough. > Maybe we shouldn=E2=80=99t change this logic and invent one more optimisa= tion > =E2=80=98deduplication=E2=80=99 stage later, before the selectivity estim= ation stage. --=20 Thanks, Tender Wang