ERROR: SubPlan found with no parent plan - Mailing list pgsql-hackers

From Richard Guo
Subject ERROR: SubPlan found with no parent plan
Date
Msg-id CAMbWs48nYDu7joYeyMKYdX8kHoL_ASEax2fqZH6L+HHqO2nkXA@mail.gmail.com
Whole thread
List pgsql-hackers
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.

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.

- Richard

Attachment

pgsql-hackers by date:

Previous
From: Trakshan Mishra
Date:
Subject: Intermittent Assert("plan->magic == _SPI_PLAN_MAGIC") in 027_stream_regress
Next
From: Wolfgang Walther
Date:
Subject: Re: Add a Nix flake