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 1vdO1E-00HX36-0T for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 07:31: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 1vdO1C-00CV2n-27 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Jan 2026 07:31: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 1vdO1C-00CV2f-15 for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 07:31:47 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdO1A-0052Ux-2D for pgsql-hackers@lists.postgresql.org; Wed, 07 Jan 2026 07:31:46 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-65f59501df9so7294eaf.1 for ; Tue, 06 Jan 2026 23:31:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767771103; x=1768375903; 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=+IPivsDdJQgBi9gA5TDwz9IkloY61RTSzJL4EuaCSRY=; b=TXB0onnecZsBUM1i/+xFDaY+kbQEG/RtTgw6xTS07WGs3U9arOfr4IJaFTUIpwa4Wm ercKc4putH1e4PtNy29AZh4ZhCr3LSf8ChsKkI8ioqXN7DSqO9kZ0bwvZv7Yg+sSzQFm 8Apx3jzc//xgC/XTZVZmaDwibdNZMCOPE0irDU01Fy6wsnTOu79XowNHahGO6J7rJAIm +ATIyNFys9ixI2Wd1+9zgQamOWRW62bhywE5Gmb1OktHaEBkhCr1QLDIsrU7tLbLOBuE JlWtCX0cS0tOSRbK2fRYMIQsyLWHppwFhQLO2m3TbFpPlF0A4HAX+zCQGn7+hdCv4c2Z lRMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767771103; x=1768375903; 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=+IPivsDdJQgBi9gA5TDwz9IkloY61RTSzJL4EuaCSRY=; b=G1fpYt5oYJs+k/umAjbxLC2vgp25gZixcWlb1Y99DPn5lKY9bZN3acjzYiNVWlxUOz M8UlQrfvYEyynAJBIq70On/v08EalBKlk4dpBoJK9adfI7cp5cS39dxSOfjFz2QwrBJ9 Xz+W7mThli0wUhXawu3jENfarzwVkc4xetPAKeSKLvVC4qBZQW/9ZeqKeNZl08kFSTS4 dcQ3ZIvolnOj6V7ezGikAVENSOqf6Ihj/8K+ERjlRtxhBZNE31L/ZYkemNfrBXTQzMxd dd3kFgCGYTdIFYE/V/dmM1ZMHPAjLn7besKNGjZPzgnDT3JO79ggRhb6uqTmn2zUtSaN vS2g== X-Forwarded-Encrypted: i=1; AJvYcCXLf8hNSuDKPmISUk3vFBEpe/CBmNXs4hb4PcgVmlx5QvCh0maXop3Nh1quqRQkJB6MXRZvYGln5fG8phel@lists.postgresql.org X-Gm-Message-State: AOJu0Yx/3h3YMF9PH9E52jJMVpitHNG6j802W6xbF/U6t7nk3kLJlQ9x Wa5Nyu3qi887N6AyWK7qb3O1xgiI/uMGCt9wA66lN/4UIHup7uo1K+dRULesxNOTdcqN6ZZ7Saz ttgl81ROVplJ9f6Ey6hoUtdLbwjZBYiGyAEp6 X-Gm-Gg: AY/fxX4xP/QDlbGZ8gKyGIlUe0IG+099ejIxrOar07FkngYPeZftG2P+vD4u6ktEQtH PvcQIZDhVMwmqp+SBZnwARdJSPjn8S/obSCneFgwO0yKW7SXB2+FQPGDmx/2LdKtg8VpM/vDTNr B/D/UAG7PIM8WpK9uURLtfiq+CBDvayHu2sZUWxKsOuOwJCG2vUNpE4QHth9yxVQ8qLPe4FhuNE USH16TfKfXz8DLpn74vwxAxRk+o0zdcJvCkhDfCD8TPGEXiaLI0nNOP5cyb2xJigZ7pTzyN X-Google-Smtp-Source: AGHT+IHsi9Yv60qiHRgo6qNWYpm048sR4yqiAKy924znC/Ri0Gssu5o11hNXzAhhx/N0tWKRtoK/mr+BIAVYc1yJPJ0= X-Received: by 2002:a05:6820:60b:b0:65c:fdfd:9794 with SMTP id 006d021491bc7-65f54f1ab2bmr601556eaf.29.1767771103323; Tue, 06 Jan 2026 23:31:43 -0800 (PST) MIME-Version: 1.0 References: <7900964C-F99E-481E-BEE5-4338774CEB9F@gmail.com> <1607957.1767725532@sss.pgh.pa.us> <1654153.1767753474@sss.pgh.pa.us> In-Reply-To: <1654153.1767753474@sss.pgh.pa.us> From: Richard Guo Date: Wed, 7 Jan 2026 16:31:27 +0900 X-Gm-Features: AQt7F2oE-BpeTu8otI114knBLFli2RF7s-7QN7oO3H9l5hjb7RO3XISnxxEqt1w Message-ID: Subject: Re: Fwd: pg18 bug? SELECT query doesn't work To: Tom Lane Cc: Eric Ridge , 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 On Wed, Jan 7, 2026 at 11:37=E2=80=AFAM Tom Lane wrote: > Richard Guo writes: > > (I wonder whether this same issue exists for join alias Vars.) > Seems highly likely that we'd have noticed if it did. I think > flatten_join_alias_vars happens early enough that no interesting > decisions have been made yet. I wonder whether we could fix the > current problem by doing grouping-Var expansion earlier? Hmm, I don't think so. The decision on whether to push down a subquery's restriction clauses is made even before we invoke subquery_planner() on that subquery. At that stage, join alias Vars have not yet been flattened, meaning the underlying expressions are still hidden. What I was wondering is whether this could cause subquery_is_pushdown_safe() to make the wrong decision. For the same reason, it seems that doing grouping-Var expansion earlier wouldn't help with this bug, unless we move that expansion ahead of the subquery_planner() call entirely. In addition, it seems to me that it would cause problems if we move the expansion of grouped Vars to before we've done with expression preprocessing on targetlist and havingQual. For example, consider this query: select not a from t group by rollup(not a) having not not a; If we do grouping-Var expansion before the havingQual is preprocessed, the HAVING clause "not not a" would be reduced to "a" and thus fail to be matched to lower tlist. > I'm also wondering (don't recall the details of your patch) > whether you are repeating eval_const_expressions after > grouping-Var expansion. If not, there are going to be bugs > there, like failure to handle named args in function calls. > That could be another reason to make this happen earlier. Currently we're not repeating eval_const_expressions after the grouping-Var expansion, but I fail to wrap my head around why that would be a problem. I ran a simple test with named args in function calls: create table t (i int); CREATE OR REPLACE FUNCTION add_three( a int DEFAULT 0, b int DEFAULT 0, c int DEFAULT 0 ) RETURNS int AS $$ SELECT a + b + c; $$ LANGUAGE sql; explain (verbose, costs off) select add_three(i, c =3D> 10) from t group by 1 having add_three(i, c =3D> 10) > 100; QUERY PLAN ------------------------------------------ HashAggregate Output: (((i + 0) + 10)) Group Key: ((t.i + 0) + 10) -> Seq Scan on public.t Output: ((i + 0) + 10) Filter: (((t.i + 0) + 10) > 100) (6 rows) ... and the named args are expanded as expected. - Richard