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 1vdgco-003U8P-16 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 03:23:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdgcn-00HAJs-0n for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 03:23:50 +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 1vdgcm-00HAJj-2r for pgsql-hackers@lists.postgresql.org; Thu, 08 Jan 2026 03:23:49 +0000 Received: from mail-oo1-xc2d.google.com ([2607:f8b0:4864:20::c2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vdgcl-004oo8-2l for pgsql-hackers@lists.postgresql.org; Thu, 08 Jan 2026 03:23:48 +0000 Received: by mail-oo1-xc2d.google.com with SMTP id 006d021491bc7-65d1bff2abaso1674810eaf.1 for ; Wed, 07 Jan 2026 19:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767842627; x=1768447427; 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=lTUjRXszsBtTBfle4PR0lDwhU5HfLS6QNCBwi2aLQXg=; b=NSirDjAaSXOdBJARyCDE/Pa8jeNxmwu9AXWepgsWxlNaw0vqmP2AbnQ1aFJ+7T49L3 ZcCSfvjrkRlOs/V2HJuOHEBI3zRQ3JFrT5WuqrySrOQp+uqaNZ3YE6KZ+Br6PeKnrvll f8fYkRGtf04PjoyuF/HZGgK4Gr9volt+VVESYWKmSf3DB9LW473jVOvZ0dN7Be36K8ER 3kLvBYP2kWlamgLYRR8/qhGtbyoe6jc9MyHYDbVzwr6lrEVVCs0Ay6Q2UGUmoGh5P++2 hUHrpG66dioGCr6jFKLbv2z3bSgOxiwFjB3vyq2xjatCOmcM6VdvjFiNvIpsh2IMMrBd RkHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767842627; x=1768447427; 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=lTUjRXszsBtTBfle4PR0lDwhU5HfLS6QNCBwi2aLQXg=; b=cCVWH3Igx9e9XV0AJihTx+v8IbDBPwthXgssvvEbRG0xBVNwafLf54jzsCP6nq2w+k uJCG+MzH/YdsZbBp/ylB+5VcWVMf3jnUjr+Q63kM5w2yBjuI8/1Z8/vpu4nwPAalHJVe UyjYnlcDS5ve8MHkps5Y3k+CWWkiY0W8o3fAkZfTLdYtQVVBX6rUTCLIFWUnYpJPGtYu KHU4KTFuXrhDHWoIbR4asSHekTKJxqBOlcUl/Ey9FA1BCB3oYV5hPQqX6vG4C9Z6uUqE jE0fjShAH5szHTZao1ckPGpYaugmXGCtYwovZhUjoTAMtp28JvPcnjOg3T+0+VJGEKLQ 72MA== X-Forwarded-Encrypted: i=1; AJvYcCUL55g9OwKJXgQDSAkUfFCwPPCjpo5mjWm1XudVep6dKRbkjue8HHfcz08P9BvMCli6xdI1je/tayDOoMK6@lists.postgresql.org X-Gm-Message-State: AOJu0Yzb8mGY3JHsR7VPcmvpuXXuxOyWbxLQcJE57lEK9KPfXutjoONp EDVfr3tc4AS78LJzOxae7XXz4PhGy/CcH+ChqfFrC5JDnox2umx53VCJ7CICQF7TprszGbw/Ik1 a5/FyEJ3ZeyY9ahruj9rdF0Ihz7cJjd+U2y3y X-Gm-Gg: AY/fxX5U5+4o1be8lubhxN79ZMuuTvZvZ5JMNa45RzudGfbqc96YqUOvhOTdm9mIRt4 cUR8y2KfleaiVDideAqenRyGCtY9Mi9/t5oSZEg5uNY93T5Nb8IYo68tWXeW9qvQlPYnUPkw7xs 9gO9oZcdeds7nGaukGWZttVkXFaWY029d7erLJ3WBopaTxQ6FOIpxPpBj0oXWdGMnvJzE49rxhk tUoEA+5J6aX9R4XFMOF3SNlEMHgV7iBsKREVshKppzrC7naRumho8kFsoJP4yNH1JH/5W9yEA== X-Google-Smtp-Source: AGHT+IF5+1v2mZ4s5gC9hMIEUNO+fr7aMguo0cI9K5RauuPoELv7DsvP023A69Or7sd4V1/SuLbPoLTchBeRWeMCSJM= X-Received: by 2002:a05:6820:168b:b0:659:9a49:8e96 with SMTP id 006d021491bc7-65f54ef7f6amr1928668eaf.26.1767842626855; Wed, 07 Jan 2026 19:23:46 -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> <1752324.1767805242@sss.pgh.pa.us> In-Reply-To: <1752324.1767805242@sss.pgh.pa.us> From: Richard Guo Date: Thu, 8 Jan 2026 12:23:36 +0900 X-Gm-Features: AQt7F2qpFbOyQ2K7zJjIjXCBlb8KzbKOIMfQHJfzOiICztfFkcLJQO4PSFn_a2w 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 Thu, Jan 8, 2026 at 2:00=E2=80=AFAM Tom Lane wrote: > The main problem, as you say, is that allpaths.c is coming to > conclusions about the contents of output expressions of the > subquery without having done any of this. The only really > simple answer I can see is to make a copy of the subquery's > tlist and apply these transformations to it before we run > the subquery_is_pushdown_safe logic. That's ... ugly. It seems that allpaths.c checks the subquery's output only for two specific cases: to determine if it contains SRFs or volatile functions. Because of this, it seems that we don't need to apply the full set of transformations to it. We only need to account for join alias Vars and grouping Vars, as these can hide underlying expressions. The underlying expression of a join alias Var can only be a Var (potentially coerced) from one of the join's input rels, or a COALESCE expression containing the two input Vars. Therefore, it should not be able to contain SRFs or volatile functions, and thus we do not need to expand it beforehand. (This also answers my previous question about whether the current bug exists for join alias Vars.) Therefore, it seems to me that we only need to expand the grouping Vars beforehand when checking the subquery's output, as in the changes I proposed earlier. It's still ugly, but less so I think. > Perhaps another idea could be to shove the responsibility for this > down into subquery_planner (or make it call a callback at the right > point), and handle transferring of parent restriction clauses into > HAVING only after we've finished preprocessing the subquery's tlist. > That's an uncomfortably big change to be making in a released branch, > but it might still be a better way than duplicating preprocessing. Agreed. I think this is the theoretically correct way to handle the push-down of a subquery's restriction clauses. However, it seems like a non-trivial project, and it seems to require changing the signature of subquery_planner(), as we'd need to pass the subquery's RTE and RelOptInfo into it. So this looks too risky for stable branches. But maybe we can do that in dev branch. - Richard