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.94.2) (envelope-from ) id 1uTxdZ-00CyKK-JX for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jun 2025 07:00:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uTxdW-009vPB-SC for pgsql-bugs@arkaria.postgresql.org; Tue, 24 Jun 2025 07:00:07 +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.94.2) (envelope-from ) id 1uTxdW-009vP2-Jh for pgsql-bugs@lists.postgresql.org; Tue, 24 Jun 2025 07:00:07 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uTxdV-003gaj-1P for pgsql-bugs@lists.postgresql.org; Tue, 24 Jun 2025 07:00:06 +0000 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3a536ecbf6fso30423f8f.2 for ; Tue, 24 Jun 2025 00:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1750748403; x=1751353203; darn=lists.postgresql.org; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=gTuttQnifNHQwM22ilimEaueRQq9cwzabJOBYxgLISg=; b=ZYzc13W9tjcifNV1xy9HNzcK9qMOwDjXMU9xd0KgGqWQbG5U6X9fpUBPGhcjgMVl/s l/MFp87ssaSfrS5FoHTjn42ilmr2qA5Y50URUahsnr5sV3VSBtGUIdDxfWd2Mx8ym3F3 G+wdMUC7rzYKbtd4bwxJrOV1wkEdN7VFUxPR3QEI+0LvGW25bJ50OQ8ZCvUa+E06I9Kk +3wMOhvAD9jacZTTSUUcsIE+sG7vRNPvNh5V0uaAiiDmd7vkOHICwZFJ+ksfdkD1TWxS uA8n/l/ibzyB/NQYlM9JJqWk/aSX38GW6IwYGXt8AhRzyUasUgLKeIEIRsQN/plSoT/U /Atg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750748403; x=1751353203; h=in-reply-to:from:content-language:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=gTuttQnifNHQwM22ilimEaueRQq9cwzabJOBYxgLISg=; b=t9XTKNmExK5y/QWEVuNiahHSSKOcJeuaoxB88wlLNyZ8a9a199niathkurFRKlVjzo RlNB9yBWCZq5E4xD4O3zuh/OEVALF3TGURAWifSs94LafRLStneo3UMn1Gu5F/fY1cCt KAafQM+8Jru9/bFa7QuqeIb0dEaQQcFtLdLT85+x+tJXIZTXH6ZuqUsxyQTbU+Chrflx sQMeRbcePQOE42HTkjlsCQe9Vfv4V1/BLlaPOxbssYiJT57bbkigbwBKzZ9HYW6hX8gP aXNwvDcGM1bT/LgTDaZRfstRLfk73JKw7SlAXvmibEQ+NGBrO05iPwd0MbuRJcJyzZ8h ZYgQ== X-Gm-Message-State: AOJu0YxF2doDCIBLeCpvNta4s3N0s67QTLeHTEp4qzUIbiRZYiMWZXPf GKZ8fJbxexyRfswC6wJnAPnNNE++f2NbldGdvOcHGSA6iHQ1NletFiYt X-Gm-Gg: ASbGncvXjc0ORWFQ6JhJfGGY+8XtFVrrpw/UewQgBYqXGpYQukDz2o0rEXLif9iIjAt f1Uw1D+rTxVcCtaEUq/FaO9U50C2NBRuHc0d6MZl73otO08o1bJ+80B7sfIwfHS63juxWiXpARJ gEMvlZV/D7kYumdY/nI6AgZsgSLqR4cwiDLpGggGfXGPwbbqOLzEBLRykWZBT60AbdNqgKDK9VB 7qlkLTnuKUP6by+48hivG3cC6yGuZ23cJCGSTWcP9wkiuOnzSIwnQ7avMvgojQkEbXiVthtax01 XqjAOxKlorPe3tIXSscYSloDro04n7MJaKwBAcdE1YytkjGyLEOvgM8vZUNpTyXEZA== X-Google-Smtp-Source: AGHT+IEAsNkSMsxRt7oJsNkk0KPPUIGXUS1vwNMr0FIDVshD+hVjxZUOV5QV0d2NPxdXJx4Xbltvew== X-Received: by 2002:a05:6000:1aca:b0:3a3:652d:1638 with SMTP id ffacd0b85a97d-3a6e78766d8mr1408133f8f.48.1750748402581; Tue, 24 Jun 2025 00:00:02 -0700 (PDT) Received: from [192.168.0.50] ([89.149.120.224]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a6e8069467sm1120378f8f.42.2025.06.24.00.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jun 2025 00:00:01 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------JEeL0aBXSKwJP5s90sA0a9Ps" Message-ID: Date: Tue, 24 Jun 2025 10:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18953: Planner fails to build plan for complex query with LATERAL references To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org, Richard Guo References: <18953-1c9883a9d4afeb30@postgresql.org> <1268645.1749765012@sss.pgh.pa.us> <1499514.1749848324@sss.pgh.pa.us> <527134.1750087495@sss.pgh.pa.us> <835659.1750177751@sss.pgh.pa.us> <837b0dce-b2f3-4811-bccf-f42e8985d6e2@gmail.com> <3040798.1750617116@sss.pgh.pa.us> <3886446.1750703041@sss.pgh.pa.us> Content-Language: en-US From: Alexander Lakhin In-Reply-To: <3886446.1750703041@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------JEeL0aBXSKwJP5s90sA0a9Ps Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Tom and Richard, 23.06.2025 21:24, Tom Lane wrote: > Anyway, with one eye on the possibility that we'll need to back-patch > this in some form, I went for the localized fix of ensuring that > we use a copy of the PHV that's been through the normal processing. > I do want to look into restructuring the handling of these PHVs > to make this less messy, but that's not a job to undertake for v18 > (much less if we have to back-patch). I've managed to discover one more anomaly introduced by a16ef313f, that is not fixed by fix-bug-18953-some-more: CREATE TABLE t(i int PRIMARY KEY); MERGE INTO t USING   (SELECT 1 AS j FROM generate_series(1, 1))   RIGHT JOIN (SELECT 1) ON true   LEFT JOIN (SELECT 1 FROM (SELECT 1 FROM generate_series(1, 1))) ON false ON i = j WHEN NOT MATCHED THEN INSERT VALUES (1); ERROR:  XX000: wrong phnullingrels (b) (expected (b 4)) for PlaceHolderVar 1 LOCATION:  search_indexed_tlist_for_phv, setrefs.c:2958 Thank you for spending your time on this! Best regards, Alexander --------------JEeL0aBXSKwJP5s90sA0a9Ps Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Tom and Richard,

23.06.2025 21:24, Tom Lane wrote:
Anyway, with one eye on the possibility that we'll need to back-patch
this in some form, I went for the localized fix of ensuring that
we use a copy of the PHV that's been through the normal processing.
I do want to look into restructuring the handling of these PHVs
to make this less messy, but that's not a job to undertake for v18
(much less if we have to back-patch).

I've managed to discover one more anomaly introduced by a16ef313f, that is
not fixed by fix-bug-18953-some-more:
CREATE TABLE t(i int PRIMARY KEY);

MERGE INTO t
USING
  (SELECT 1 AS j FROM generate_series(1, 1))
  RIGHT JOIN (SELECT 1) ON true
  LEFT JOIN (SELECT 1 FROM (SELECT 1 FROM generate_series(1, 1))) ON false
ON i = j
WHEN NOT MATCHED THEN INSERT VALUES (1);
ERROR:  XX000: wrong phnullingrels (b) (expected (b 4)) for PlaceHolderVar 1
LOCATION:  search_indexed_tlist_for_phv, setrefs.c:2958

Thank you for spending your time on this!

Best regards,
Alexander
--------------JEeL0aBXSKwJP5s90sA0a9Ps--