From: | Zhang Mingli <zmlpostgres(at)gmail(dot)com> |
---|---|
To: | exclusion(at)gmail(dot)com, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #18778: Query planning fails in ExecInitExprRec with unrecognized node type |
Date: | 2025-01-18 15:52:01 |
Message-ID: | dc467c76-e5e5-4eaf-950b-32097f32d4f2@Spark |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Zhang Mingli
www.hashdata.xyz
On Jan 17, 2025 at 07:35 +0800, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, wrote:
> PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> > The following script:
> > CREATE TABLE t (id int, PRIMARY KEY (id)) PARTITION BY RANGE (id);
> > CREATE TABLE t0 PARTITION OF t FOR VALUES FROM (0) TO (1);
> > CREATE TABLE t1 PARTITION OF t FOR VALUES FROM (1) TO (2);
>
> > SELECT 1 FROM (SELECT EXISTS (SELECT 1 FROM t0 WHERE id = t00.id) AS b FROM
> > t0 t00) r, t
> > WHERE t.id > CASE WHEN jsonb_build_object(b) IS NULL THEN 1 ELSE 1 END;
>
> > fails with:
> > ERROR: XX000: unrecognized node type: 24
>
> Thanks for the report! setrefs.c is supposed to remove
> AlternativeSubPlan nodes from the plan, but it's failing to do so
> here. Digging, the un-cleaned-up AlternativeSubPlan is inside the
> exec_pruning_steps of an Append node's part_prune_info, and I see
> that setrefs is totally unaware that those expressions might need
> processing. I think it ought to be applying fix_scan_expr to them,
> as per the attached. There are a bunch of tidying-up things that
> fix_scan_expr does, so I suspect that there may be more bug symptoms
> reachable from this oversight. Some of the missed processing may be
> redundant --- for example it's likely that
> record_plan_function_dependency is duplicative because functions used
> here would also be used elsewhere in the query. But it's hard to
> believe it all is.
>
Hi, I have tested the patch, and confirm that it works well. Additionally, I believe it might be worth creating a test case for it.
And I have a question that may not be directly related to the issue: why is there a Subplan 2, and it appears to be unused?
explain(costs off, verbose) SELECT 1 FROM (SELECT EXISTS (SELECT 1 FROM t0 WHERE id = t00.id) AS b FROM
t0 t00) r, t WHERE t.id > CASE WHEN jsonb_build_object(b) IS NULL THEN 1 ELSE 1 END;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------
Nested Loop
Output: 1
-> Seq Scan on public.t0 t00
Output: t00.id
-> Append
-> Index Only Scan using t0_pkey on public.t0 t_1
Output: t_1.id
Index Cond: (t_1.id > CASE WHEN (jsonb_build_object(EXISTS(SubPlan 1)) IS NULL) THEN 1 ELSE 1 END)
SubPlan 2
-> Seq Scan on public.t0 t0_1
Output: t0_1.id
-> Index Only Scan using t1_pkey on public.t1 t_2
Output: t_2.id
Index Cond: (t_2.id > CASE WHEN (jsonb_build_object(EXISTS(SubPlan 1)) IS NULL) THEN 1 ELSE 1 END)
SubPlan 1
-> Index Only Scan using t0_pkey on public.t0
Index Cond: (t0.id = t00.id)
(17 rows)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2025-01-18 16:51:37 | Re: BUG #18778: Query planning fails in ExecInitExprRec with unrecognized node type |
Previous Message | Andrew Dunstan | 2025-01-18 14:37:07 | Re: pg_rewind fails on Windows where tablespaces are used |