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 1uVObh-000BjB-HR for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Jun 2025 06: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 1uVObe-006hdk-Gx for pgsql-bugs@arkaria.postgresql.org; Sat, 28 Jun 2025 06:00:07 +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.94.2) (envelope-from ) id 1uVObe-006hdb-7d for pgsql-bugs@lists.postgresql.org; Sat, 28 Jun 2025 06:00:06 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uVObc-004Wjz-0r for pgsql-bugs@lists.postgresql.org; Sat, 28 Jun 2025 06:00:06 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-60c93c23b08so923823a12.3 for ; Fri, 27 Jun 2025 23:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751090403; x=1751695203; 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=wHjSWRYUSdWD6Ui7eLpfduaN4lfxrhveFb/PQYHU9sw=; b=kfwBUwvl0m9Tg+y5TbgIsjzB8j+MjmWCjsKwhzL6cv7caowfgCogCnma1eNHJcjUpn M3K7qJwIRkr+f2MccsjxP8goBPGptYKAZUyZ4eECLrJnnxv0Tip/7ly5lWdSymBNKFiF 9kvCYN0BMqDUXkD9vddS8jLWUdRu7NyFBLoDyDHYTumr1mK0bOvFHM7kTOKplCbdOSP/ Kam/CkBUie+oV7IrxxdKahf3xUJYKwqA+oavVZRvxFM1pYG40WVCwUO4Rt5AiP2X5DAd VBZfO09/Vby+yuGk75+HRmqaN7hK+UfGQ493WSTF++/Iz075VyeK5Y+TRX16ZmGyeRZj cpgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751090403; x=1751695203; 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=wHjSWRYUSdWD6Ui7eLpfduaN4lfxrhveFb/PQYHU9sw=; b=nXcGd1i+D2GwYWznm0dDA18H/MWGV1ElQ1SHljC6tqTH4FBLX/V2dDChuMQIvixeEj X0OHIL2w7WGjzchPFOfdUDipNwmPPwREDe69knr5Z1kVBPMbD/I6gxc1BAokkPkIHLM5 9xHiwNPuVyxiLYd4P7xmh68yKJcjafEYduWr9HV68d5KnXCcXdXrzd3llzWqMi9/bPs2 I7WsP3g9eHbSHkjtM09mR7az5KQ824bMlS1n/wxQPC2RcMoJ4Ys/+vlyOUBI67tAQd9n yqBz73mWO7viHi8YehgmWfeT5y6YViY53TuDJCUddGMJSW/l8eodrcGo+GMlyVSOThFL gHnw== X-Gm-Message-State: AOJu0YyHJENHk6V+THeT8sclkO78i9ZOXgaGpfuOIJHS1k0mxWmRlqI1 VD9x6LMK9J0KSvHNNng5fqcJbXlAcH/bStv0BrVfuPcnX0ECse/gceJlrgI+Jbg2 X-Gm-Gg: ASbGncvuaRBIf2U4K+WNPx+zYGBBklzAOQDUNPBLt3fOAWpYUvcGP4VQWElqTOdGqN+ vzg+zzqFwV1cVTDoDlB35CCWnDxXeeloQyUk6Lad6h8Xfl6Zvwp1iAjNJ4Ui6axlv8BApAYr57M 9tGfCPPfH3vev8Hi306RgVKIRRT3ybJMPEwczKCiseJj4lugJDnPKcGEmvdriOJDwBlPvRu2MzB UsjdPr59OGbA8BV1WJF+Z9Pa4XW8DJhBwVkCO/XZSfNfKvIYpe7Qwa67Jq2Gve/M11M2xeYZpTi 1LyUUTmkjz27e6b78Z3BqS3K/zWtFON2id1ylXP2j6pLMnzcqlLU7U0LprpWM1P1 X-Google-Smtp-Source: AGHT+IG9D5Yn49v2fKdyp+vE7N7yjke28Jow2mgfF253aVyQ+sol+FT4ANwN5jWt6XqAl+F+l7ahDw== X-Received: by 2002:a05:6402:84f:b0:606:baba:79f2 with SMTP id 4fb4d7f45d1cf-60c88e60f84mr5384480a12.33.1751090402544; Fri, 27 Jun 2025 23:00:02 -0700 (PDT) Received: from [192.168.0.50] ([89.149.68.212]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ae353ca2edcsm247482466b.180.2025.06.27.23.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Jun 2025 23:00:01 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------TANvO0oUGfqzFszZ0ANe4P8d" Message-ID: <6072cd36-8d7b-457a-a7c6-7cf41c05fe6c@gmail.com> Date: Sat, 28 Jun 2025 09:00:01 +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 , Richard Guo Cc: pgsql-bugs@lists.postgresql.org 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> <1487176.1750963077@sss.pgh.pa.us> <2056150.1751049350@sss.pgh.pa.us> <2075249.1751060239@sss.pgh.pa.us> Content-Language: en-US From: Alexander Lakhin In-Reply-To: <2075249.1751060239@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. --------------TANvO0oUGfqzFszZ0ANe4P8d Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Tom and Richard, 28.06.2025 00:37, Tom Lane wrote: > ... BTW, looking at these two patches again, I wonder if it'd be > better to put the hackery for SubLink conversion into > identify_current_nestloop_params? That'd remove the need to argue > that we don't have to fix both copies of a nestloop-parameter PHV. > The responsibility doesn't clearly belong to > identify_current_nestloop_params, but it doesn't clearly belong > to create_nestloop_plan either, so neither choice seems superior > from a modularity standpoint. I've discovered a query which fails with an error after a16ef313f with both v2 patches applied: create temp table t(i int primary key); select * from     (select k from         (select i, coalesce(i, j) as k from             (select i from t union all select 1)             join (select 1 as j limit 1) on i = j)         right join (select 1) on true         join (select 1) on i is not null     ),     lateral (select k offset 1); ERROR:  XX000: variable not found in subplan target list LOCATION:  fix_upper_expr_mutator, setrefs.c:3310 Thank you for working on this! Best regards, Alexander --------------TANvO0oUGfqzFszZ0ANe4P8d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Tom and Richard,

28.06.2025 00:37, Tom Lane wrote:
... BTW, looking at these two patches again, I wonder if it'd be
better to put the hackery for SubLink conversion into
identify_current_nestloop_params?  That'd remove the need to argue
that we don't have to fix both copies of a nestloop-parameter PHV.
The responsibility doesn't clearly belong to
identify_current_nestloop_params, but it doesn't clearly belong
to create_nestloop_plan either, so neither choice seems superior
from a modularity standpoint.

I've discovered a query which fails with an error after a16ef313f with
both v2 patches applied:
create temp table t(i int primary key);
select * from
    (select k from
        (select i, coalesce(i, j) as k from
            (select i from t union all select 1)
            join (select 1 as j limit 1) on i = j)
        right join (select 1) on true
        join (select 1) on i is not null
    ),
    lateral (select k offset 1);
ERROR:  XX000: variable not found in subplan target list
LOCATION:  fix_upper_expr_mutator, setrefs.c:3310

Thank you for working on this!

Best regards,
Alexander
--------------TANvO0oUGfqzFszZ0ANe4P8d--