Re: Remove dead macro exec_subplan_get_plan

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Remove dead macro exec_subplan_get_plan
Date: 2022-09-06 07:50:08
Message-ID: c1843941-bb0d-4d02-92cd-bb2599016678@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,all

Regards,
Zhang Mingli
On Sep 6, 2022, 10:22 +0800, Richard Guo <guofenglinux(at)gmail(dot)com>, wrote:
>
> On Tue, Sep 6, 2022 at 1:18 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> > Zhang Mingli <zmlpostgres(at)gmail(dot)com> writes:
> > > Macro exec_subplan_get_plan is not used anymore.
> > > Attach a patch to remove it.
> >
> > Hm, I wonder why it's not used anymore.  Maybe we no longer need
> > that list at all?  If we do, should use of the macro be
> > re-introduced in the accessors?

The PlannedStmt->subplans list is still used at several places.

> Seems nowadays no one fetches the Plan from PlannedStmt->subplans with a
> certain plan_id any more. Previously back in eab6b8b2 where this macro
> was introduced, it was used in explain_outNode and ExecInitSubPlan.
>
> I find a similar macro, planner_subplan_get_plan, who fetches the Plan
> from glob->subplans. We can use it in the codes where needed. For
> example, in the new function SS_make_multiexprs_unique.
>
>      /* Found one, get the associated subplan */
> -    plan = (Plan *) list_nth(root->glob->subplans, splan->plan_id - 1);
> +    plan = planner_subplan_get_plan(root, splan);
>
> Thanks
> Richard

Yeah, searched on history and found:
exec_subplan_get_plan was once used in ExecInitSubPlan() to create planstate.

```
Plan    *plan = exec_subplan_get_plan(estate->es_plannedstmt, subplan);
...
node->planstate = ExecInitNode(plan, sp_estate, eflags);
```

And now in ExecInitSubPlan(), planstate comes from es_subplanstates.

```
/* Link the SubPlanState to already-initialized subplan */
sstate->planstate = (PlanState *) list_nth(estate->es_subplanstates, subplan->plan_id - 1);
```

And estate->es_subplanstates is evaluated through a for-range of subplans list at some functions.

```
foreach(l, plannedstmt->subplans)
{
 ...
 estate->es_subplanstates = lappend(estate->es_subplanstates, subplanstate);
}
```

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2022-09-06 07:51:43 Re: Return value of PathNameOpenFile()
Previous Message kuroda.hayato@fujitsu.com 2022-09-06 07:47:21 RE: test_decoding assertion failure for the loss of top-sub transaction relationship