Re: ERROR: SubPlan found with no parent plan

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: ERROR: SubPlan found with no parent plan
Date: 2026-10-13 08:14:47
Message-ID: CA+HiwqFdiHVT0q9S4KTHLajLQjkDyDmUETgsmijpij8YN6ssDQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Richard,

On Sun, Sep 20, 2026 at 7:02 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
> Fuzzing with Claude reported this bug:
>
> create table pt (a int) partition by range (a);
> create table pt1 partition of pt for values from (0) to (3);
> create table pt2 partition of pt for values from (3) to (5);
> create table t (a int);
>
> select * from pt where a = (null::int in (select a from t))::int;
> ERROR: SubPlan found with no parent plan
>
> This one is interesting. In the testexpr of the SubPlan, we have the
> NULL arg and the strict comparison operator =, so the whole testexpr
> is const-folded to const NULL, which means the PARAM_EXEC Param is
> const-folded away. As a result, match_clause_to_partition_key()
> treats it as usable for executor-startup pruning, so the expression
> ends up in initial_pruning_steps, where ExecDoInitialPruning() has to
> evaluate it before any PlanState exists.

Good catch.

> I think the simplest fix is to just disallow expressions containing
> SubPlans for executor-startup pruning, like attached. There may well
> be a better approach, though.

Thanks for the patch. I am failing to see another approach that would
be simpler or better, so +1 to what you have here.

--
Thanks, Amit Langote

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2026-10-13 08:23:26 Re: json/jsonb cleanup + FmgrInfo caching
Previous Message Nisha Moond 2026-10-13 08:05:21 Re: Proposal: Conflict log history table for Logical Replication