Re: Consistent segfault in complex query - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Consistent segfault in complex query
Date
Msg-id 5943.1536877122@sss.pgh.pa.us
Whole thread Raw
In response to Re: Consistent segfault in complex query  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Consistent segfault in complex query
List pgsql-hackers
I wrote:
> Your other idea of forcing initPlan parameters to be evaluated before we
> enter the EPQ execution environment is probably more workable.

Concretely, the attached seems to be enough to fix it (though I only
tried the simplest case you posted).

I don't find anything to love about ExecEvalParamExecParams: it's badly
named, badly located, full of undocumented assumptions, and probably
causes a memory leak.  Plus it doesn't exist as far back as we need it
for this.  But fixing those problems is a separable task.  In the
meantime, this is an expedient way to test whether this approach can work.

            regards, tom lane

diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index c583e02..35c9eb2 100644
*** a/src/backend/executor/execMain.c
--- b/src/backend/executor/execMain.c
***************
*** 46,51 ****
--- 46,52 ----
  #include "commands/matview.h"
  #include "commands/trigger.h"
  #include "executor/execdebug.h"
+ #include "executor/execExpr.h"
  #include "foreign/fdwapi.h"
  #include "mb/pg_wchar.h"
  #include "miscadmin.h"
*************** EvalPlanQualBegin(EPQState *epqstate, ES
*** 3078,3083 ****
--- 3079,3087 ----
          {
              int            i;

+             /* First, force evaluation of any initPlans needed by subplan */
+             ExecEvalParamExecParams(planstate->plan->extParam, parentestate);
+
              i = list_length(parentestate->es_plannedstmt->paramExecTypes);

              while (--i >= 0)
*************** EvalPlanQualStart(EPQState *epqstate, ES
*** 3170,3175 ****
--- 3174,3182 ----
      {
          int            i;

+         /* First, force evaluation of any initPlans needed by subplan */
+         ExecEvalParamExecParams(planTree->extParam, parentestate);
+
          i = list_length(parentestate->es_plannedstmt->paramExecTypes);
          estate->es_param_exec_vals = (ParamExecData *)
              palloc0(i * sizeof(ParamExecData));

pgsql-hackers by date:

Previous
From: Andrew Gierth
Date:
Subject: Re: Consistent segfault in complex query
Next
From: Tom Lane
Date:
Subject: Re: Consistent segfault in complex query