Get rid of runtime handling of AlternativeSubPlan?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Get rid of runtime handling of AlternativeSubPlan?
Date: 2020-06-22 00:20:25
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Back in bd3daddaf232d95b0c9ba6f99b0170a0147dd8af, which introduced
AlternativeSubPlans, I wrote:

There is a lot more that could be done based on this infrastructure: in
particular it's interesting to consider switching to the hash plan if we start
out using the non-hashed plan but find a lot more upper rows going by than we
expected. I have therefore left some minor inefficiencies in place, such as
initializing both subplans even though we will currently only use one.

That commit will be twelve years old come August, and nobody has either
built anything else atop it or shown any interest in making the plan choice
switchable mid-run. So it seems like kind of a failed experiment.

Therefore, I'm considering the idea of ripping out all executor support
for AlternativeSubPlan and instead having the planner replace an
AlternativeSubPlan with the desired specific SubPlan somewhere late in
planning, possibly setrefs.c.

Admittedly, the relevant executor support only amounts to a couple hundred
lines, but that's not nothing. A perhaps-more-useful effect is to get rid
of the confusing and poorly documented EXPLAIN output that you get for an

I also noted that the existing subplan-selection logic in
ExecInitAlternativeSubPlan is really pretty darn bogus, in that it uses a
one-size-fits-all execution count estimate of parent->plan->plan_rows, no
matter which subexpression the subplan is in. This is only appropriate
for subplans in the plan node's targetlist, and can be either too high
or too low elsewhere. It'd be relatively easy for setrefs.c to do
better, I think, since it knows which subexpression it's working on
at any point.


regards, tom lane


Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2020-06-22 01:29:31 Re: Get rid of runtime handling of AlternativeSubPlan?
Previous Message Mark Dilger 2020-06-22 00:14:39 Re: new heapcheck contrib module