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 1vdJFz-00GYYy-0L for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 02:26:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdJFw-00BOgr-1j for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 02:26:41 +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 1vdJFw-00BOgi-0i for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 02:26:41 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdJFv-004dmM-2B for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 02:26:40 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-3eae4e590a4so810093fac.1 for ; Tue, 06 Jan 2026 18:26:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767752799; x=1768357599; 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=9Z7KD6JuE977F4Pc9iIR3/LDjNhTeed81ZQ2qMqxlWI=; b=auXehYcQQ9Uaa/BV4APIjJ3jBSfHGJI6tfAAbxJWNfNpu1c+OXzEZIYPiJFrx+qgjX qS7LKzno9ogc2YLtj53NmHLIa6vub7i1T546rBpB6hnklpqw3vkw3FO80PLGRAgzcw2z x2BIuHLK2qt+85H2PezXpwt4Uq2Ox3elCDd0Ghu1fypTZLs1B79kC0TSQ2fQ2ZDbpBaq PYmtHywj5N+5wDFnoKFnyHE/tbTCoVNQbEZgIvqqasRos3F30xBYTWqwsq+Z3OQRBgx/ Muf7xfFb83wKa4IEdcfEPPgOGxBFMcsuGZ5Or6yzn9o1iGQS83b96MvmD+/k7bTjn2gE NQxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767752799; x=1768357599; 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=9Z7KD6JuE977F4Pc9iIR3/LDjNhTeed81ZQ2qMqxlWI=; b=i62HYuiqSj8kmxNOVimQorJ+gV3Dnd7cER7q8nJ1ZUQNEiq3KX7KgtfZ+97Fhp85HK hikQ4TEQm5BrBMGB3IM1YM3TbHRM4K/v0GdOllWTArVeHEFXeYht/wL/bLsz6fpfYxku ELcHLB+vhuGdbPfiSyvSb506oKOD4N8U3dTkCa6KNmUQoTsn7tr7KQWDWj8Bts5IEdAd osXxEW0PaUGW15+Jb2QtTCRPEddYhybF3hJBEtjkj+awjolDycTfasZKzHbCp9DvAMfE AZsHKMG97I9B7Me6KobbdSipqs1PTL+nUfPZvuNNq2lnl1A+Li+pL8OnBQFLQbq8KfUO vy3Q== X-Gm-Message-State: AOJu0Ywgorw36RjQ7Z5jCoTGIDhALLHWxFf0h7cpcZIlQyqRPDNcVrGx +78+ScGKhzl7Z5dkT78m/ah4+u5eNzQ20229tfJ0iScdhc9i36lKcq9br3WDIPB8Lc/sRvQQnte CuxMC2AxzTbyzJn587QGwlhk265qjEqY= X-Gm-Gg: AY/fxX50CrJLeUHoeTmkjO7CSMJTT6omIjCIZ6zMOQ1AnTNsaLfNL+SsmCpPg26aojx PL1mt+KOrYJ+rbJp8ztBY2mcEDj0XPkmk693TUhCDnaxQiw4JM9sGRlPiaS+w5h+Jnw/XK5hGlB zls3eEcpnEi0RcUwIyMVTDRAkOeUOcKN/032jN2iC7F0qpE0Oa2AQrwaOh5Q0/3eamcFDqCM2Iw uzMA0sNWqhg+TIJv8u5w7J26IsUdh73bjeZgL5PErWMZLhSFCFRSwy9xkS4MSoih99vgQsupA== X-Google-Smtp-Source: AGHT+IFI0L55XyCf00JMXaTNrNIE1hYKs6Dv0q4Kw6g3CuHvp1AiZXD5xWcjX+6bWIqVwZDhk8CGptPLrlz24pyzGmU= X-Received: by 2002:a05:6820:808a:b0:65d:3c7:b79 with SMTP id 006d021491bc7-65f54ef189emr292264eaf.25.1767752798752; Tue, 06 Jan 2026 18:26:38 -0800 (PST) MIME-Version: 1.0 References: <7900964C-F99E-481E-BEE5-4338774CEB9F@gmail.com> <1607957.1767725532@sss.pgh.pa.us> In-Reply-To: From: Richard Guo Date: Wed, 7 Jan 2026 11:26:27 +0900 X-Gm-Features: AQt7F2pixrxfC68O1JaHTch05fu66j1Rz2tUF5MMBcZH8TWjLYqxfybiCt0mp7M Message-ID: Subject: Fwd: pg18 bug? SELECT query doesn't work To: Tom Lane , Eric Ridge Cc: Pg Hackers 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 (resending, as the previous one has been held for moderation) ---------- Forwarded message --------- From: Richard Guo Date: Wed, Jan 7, 2026 at 11:18=E2=80=AFAM Subject: Re: pg18 bug? SELECT query doesn't work To: Tom Lane Cc: Eric Ridge , pgsql-general , Pg Hackers On Wed, Jan 7, 2026 at 3:52=E2=80=AFAM Tom Lane wrote: > Eric Ridge writes: > > # SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as animal FR= OM generate_series(1, 10) GROUP BY 1) x WHERE animal ilike 'c%'; > > ERROR: set-valued function called in context that cannot accept a set > > LINE 1: SELECT * FROM (SELECT upper(unnest(ARRAY['cat', 'dog'])) as ... > I agree that this is a bug. "git bisect" says it broke at > > 247dea89f7616fdf06b7272b74abafc29e8e5860 is the first bad commit > commit 247dea89f7616fdf06b7272b74abafc29e8e5860 (HEAD) > Author: Richard Guo > Date: Tue Sep 10 12:35:34 2024 +0900 > > Introduce an RTE for the grouping step > > I've not probed further than that, but my guess is that now we check > for set-returning tlist items while the tlist still has grouping Vars, > thus missing the fact that there's a SRF represented by one of those > Vars. This prompts us to flatten a subquery we shouldn't have > flattened (because that ends by introducing a SRF into the outer > WHERE). Thanks for the report and the diagnosis. The first part of your diagnosis is correct. This issue is caused by a failure to notice the SRF in the target list, as the item is hidden under a grouped Var. This doesn't lead to incorrect subquery flattening though, since such a subquery must involve grouping, and is_simple_subquery() would refuse to flatten it. Instead, it incorrectly indicates that the subquery's restriction clause is safe to push down, which mistakenly introduces SRFs into the subquery's WHERE quals. I think the problem is that when we check whether a subquery's restriction clauses are safe to push down, we are still working with a 'raw' parse tree that hasn't been preprocessed. We might be able to fix this specific issue by manually flattening the grouped Vars in the subquery's tlist before performing the safety check: check_output_expressions(Query *subquery, pushdown_safety_info *safetyInfo= ) { ListCell *lc; + List *flattened_targetList =3D subquery->targetList; - foreach(lc, subquery->targetList) + if (subquery->hasGroupRTE) + { + flattened_targetList =3D (List *) + flatten_group_exprs(NULL, subquery, (Node *) subquery->targetLi= st); + } + + foreach(lc, flattened_targetList) { TargetEntry *tle =3D (TargetEntry *) lfirst(lc); (I wonder whether this same issue exists for join alias Vars.) - Richard