Re: Fwd: pg18 bug? SELECT query doesn't work
| От | Richard Guo |
|---|---|
| Тема | Re: Fwd: pg18 bug? SELECT query doesn't work |
| Дата | |
| Msg-id | CAMbWs48nfVij2BuU=3cJhRLVpvEc6krW5erG-hTcTRk673i7TQ@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Fwd: pg18 bug? SELECT query doesn't work (Tom Lane <tgl@sss.pgh.pa.us>) |
| Ответы |
Re: Fwd: pg18 bug? SELECT query doesn't work
|
| Список | pgsql-hackers |
On Wed, Jan 7, 2026 at 11:37 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Richard Guo <guofenglinux@gmail.com> 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 => 10) from t group by 1 having add_three(i, c
=> 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
В списке pgsql-hackers по дате отправления: