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 1w4BBb-001wJM-1F for pgsql-bugs@arkaria.postgresql.org; Sun, 22 Mar 2026 05:17:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4BAa-00CWVx-2W for pgsql-bugs@arkaria.postgresql.org; Sun, 22 Mar 2026 05:16:13 +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 1w4BAa-00CWVn-10 for pgsql-bugs@lists.postgresql.org; Sun, 22 Mar 2026 05:16:12 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4BAY-00000000QLC-2ro0 for pgsql-bugs@lists.postgresql.org; Sun, 22 Mar 2026 05:16:11 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b9358bc9c50so412168066b.1 for ; Sat, 21 Mar 2026 22:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774156568; cv=none; d=google.com; s=arc-20240605; b=jLz1SNyrLklV5K5MSxhSi/r4ZLs1qxVNjWKWsgP9y+0o4nEhp6LS3hG53KbXOlcIEn mATfXzGNS+dFdzr+O3IujTggDudJ1nU6fzwNk9WsdpuqNNb8J3OY0+s/fjd1ae5ijrWn qhnIWSIbntgP30G/hY1vpaUFjIyewCYHxLcEySpPF6/XrmPsSp5stcKc9uDdYbj5R9E+ Lt00ivVMhIFJ1OnL6ICLBS2XbUXirXuSSqzoFC8CcgyeonmRHOQb0D4G72Xkrp2QagAG AikY8b7qmPkR3iAYwaBpUYBMKhdv1IZLGf7RMzwpPtDk1C9oyNO1GgqelCxZRJcG7COH zoXA== 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=U221rRcjJHooyKfA/kZXbUCoWrLiiC/CaFZtzVBOqZc=; fh=rEQNt0u8SW+YMoGpd0obzcoPwNJ4xHC53/LMloM364A=; b=Djc4EJpVASECHcdofLeJ4FyYby48iUTGHAKdOwJBUNxqGJzP+HbeuzrOwbCPurA+th L6CKUlt+TGQP/rOMlnwaELPcehZXMciBkSkbF39fV13ugCHxv3Ucl68wagpfZ3Aj46lp nvRAoO4C7FclidnzivOvUY55RroSCEt9E0SmIcCSa70I2LQPV4UfW321UlqFxNy/SK/i tojcpXE2LRDaXYqFQxkt9WUvhUEoANWXxTwiufaVvQjTfp7O9B+jKKerxnWfTrw+2srL d3wG3YMnN5W1a1mVL30CLLUELhyYc+ya9uP5I+G95ouFgkIJWT7SgmZ8QyN09ovTG6AQ mz1g==; 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=1774156568; x=1774761368; 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=U221rRcjJHooyKfA/kZXbUCoWrLiiC/CaFZtzVBOqZc=; b=SYYKDf9KwboXzAQw+ARLHFzdxIPSQXvwHr22FTqiDa4jWn78oDnoN7VTWkGjjukp2W PbIhwqAa9eIiMa6GFPA/LywKlst9TpJaRYsPS08iEyGpeU7I9krU36BcbFst+51axm4j afz8MrfNPVck0bvGASkTgZPsAuz6tEX0RgLHkqOL+SqlmQ0Zj1FaRZ9ABzjivU5qDtYd kMHs/e8Vhq/athq/bPTav7y7NjKWOmgKqukcYGbimDF9jr/gwpZvLwci5OQ9XjlQ5miK +LP8pG78fLyJCWE4tYEF+9hP7VFK+ZTLT8R+g3ROEqM70kKFxGi0ed7l5vlA5uBWW6Gp 8S2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774156568; x=1774761368; 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=U221rRcjJHooyKfA/kZXbUCoWrLiiC/CaFZtzVBOqZc=; b=sUezs46C6WgyZS/GXezbRgjIHYQBQemBLoiOIMULDGpo+MdG+/xO1nReCeKZK4C8m2 VrrgB+wc4KwRd2amVOviXmPUyKRo0vxPsL0CkjpF6q2oYN9ryaPGLFJOmwYIxQJpnNt2 NSn/kPLr8s7OSFTfG5KNuql9d+qrfUtUYkISe8ouNsFy8AMknUYt8eleBEl3q3aGOqm6 Mf/ncRYnhHEvNJiBZIBbiN/oRbD88ATnsxbEt/yVC4o8pgvumA9zCMrHxFLtkSQI1And BfiYpmPNzsCmPSCN2iNzEXTvTPYAnfHRtYBVacJeJ3fDIE0CHWolPCvzYpE+L9Tqe94J +/qg== X-Forwarded-Encrypted: i=1; AJvYcCUXu7XnCyHfjktIj36WZo2dgzeljSMxSVGWA5BpuAACxQKc4L/CiFCZ2rn8Bsgi1KhPObdOjum6VpxJ@lists.postgresql.org X-Gm-Message-State: AOJu0YyBuRFWEHvF2JtkMGfBN+Zjec68uQxfu1tdLHYSAVyilh5F4F7z B/AgRkZLqQw93O8s56HD2zegoqdXne15v0RuxXZ0Iq6sSojanlJv3hDH1BRjrILjyYEdiSzdh0O /S08L4zLuZ4ogoKq2F4+LvXLWRqowZvs= X-Gm-Gg: ATEYQzz5EcqlnUWSuTf1eb4X/8F1jJ1hjL/ut1HQgjVbI9LUoqRq0pUMiDVFKgWK/UY HWSY0X3Fp+cL9mYDMQ2j5EyBNbbDZN2RQRrGW13zoMx4NFLlljH/yjkA+LUwlCEuEsCZgYe0sye Xpi7BAhRE2OERmQar8i47sjcW064KioxiA2GtqbYNfmHwPl73qr3ZyIoJQXEEj7RkiN7C/Z6oj4 rjwFi+wvAtpOoUBNEDWzQRiqJIG0+H2OBn3ETkAtiV7qrGVdxD1q7f9Uyr4uBSw0BAk1y+xr772 TGMSHv7F X-Received: by 2002:a17:907:3fa8:b0:b98:33c5:1bb2 with SMTP id a640c23a62f3a-b9833c56788mr480063366b.25.1774156567550; Sat, 21 Mar 2026 22:16:07 -0700 (PDT) MIME-Version: 1.0 References: <19435-3cc1a87f291129f1@postgresql.org> <1607553.1774017006@sss.pgh.pa.us> <1777986.1774038373@sss.pgh.pa.us> In-Reply-To: <1777986.1774038373@sss.pgh.pa.us> From: Tender Wang Date: Sun, 22 Mar 2026 13:15:56 +0800 X-Gm-Features: AaiRm50i994ALiUN2A4rw3Eb15Xk6ZBv4OdXCAmKAnaGXgufyHsimBj0lOqkvsc Message-ID: Subject: Re: BUG #19435: Error: "No relation entry for relid 2" Triggered by Complex Join with Self-Referencing Tables To: Tom Lane Cc: Alexander Korotkov , Andrei Lepikhov , 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 Hi Tom, Tom Lane =E4=BA=8E2026=E5=B9=B43=E6=9C=8821=E6=97=A5=E5= =91=A8=E5=85=AD 04:26=E5=86=99=E9=81=93=EF=BC=9A > > I wrote: > > At the very least we need to add comments, but I wonder if we > > don't actually need an Assert that ChangeVarNodesWalkExpression > > is not invoked directly on a Query. It would have done the > > right thing before this patch, but now it won't. That's an > > okay tradeoff for fixing the bare-Var case, but not documenting > > what you did is not okay. > > After further contemplation I've decided that an Assert would be > wrong, because it's not impossible that a callback would want > to invoke this on a sub-Query --- for instance, if it wanted to > short-circuit ChangeVarNodes's processing of a SubLink node, > it would need to do that. The key point is that if we do see a > Query node here, we will treat it as a sub-query not a top-level > query, which also justifies skipping the work that > ChangeVarNodesExtended does on a top-level Query. So we just > need a comment explaining that. I'm thinking about the attached. > > (BTW, by this reasoning the previous implementation of > ChangeVarNodesWalkExpression was doubly wrong, since it would > have done the wrong thing at a Query node as well as a Var node.) Thanks for pointing this out. The attached looks good to me. Do you have some advice about that the same qual is present twice in the plan, see [1]. Should we do something in restrict_infos_logically_equal(). Please take a look. --=20 Thanks, Tender Wang