Skip to content

Commit 891039c

Browse files
committed
Partial fix for EvalPlanQual bugs reported by Magnus Hagander, 3-Apr.
Ensure that outer tuple link needed for inner indexscan qual evaluation gets set in the EvalPlanQual case. This stops coredump, but we still have resource leaks due to failure to clean up EvalPlanQual properly...
1 parent a25a490 commit 891039c

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

src/backend/executor/nodeIndexscan.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.47 2000/02/18 09:29:57 inoue Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.48 2000/04/07 00:30:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -338,6 +338,11 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
338338
if (ScanDirectionIsBackward(node->indxorderdir))
339339
indexstate->iss_IndexPtr = numIndices;
340340

341+
/* If we are being passed an outer tuple, save it for runtime key calc */
342+
if (exprCtxt != NULL)
343+
node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple =
344+
exprCtxt->ecxt_outertuple;
345+
341346
/* If this is re-scanning of PlanQual ... */
342347
if (estate->es_evTuple != NULL &&
343348
estate->es_evTuple[node->scan.scanrelid - 1] != NULL)
@@ -346,12 +351,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
346351
return;
347352
}
348353

349-
/* it's possible in subselects */
350-
if (exprCtxt == NULL)
351-
exprCtxt = node->scan.scanstate->cstate.cs_ExprContext;
352-
353-
node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple = exprCtxt->ecxt_outertuple;
354-
355354
/*
356355
* get the index qualifications and recalculate the appropriate values
357356
*/
@@ -379,14 +378,16 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
379378
{
380379
clause = nth(j, qual);
381380
scanexpr = (run_keys[j] == RIGHT_OP) ?
382-
(Node *) get_rightop(clause) : (Node *) get_leftop(clause);
383-
381+
(Node *) get_rightop(clause) :
382+
(Node *) get_leftop(clause);
384383
/*
385384
* pass in isDone but ignore it. We don't iterate in
386385
* quals
387386
*/
388387
scanvalue = (Datum)
389-
ExecEvalExpr(scanexpr, exprCtxt, &isNull, &isDone);
388+
ExecEvalExpr(scanexpr,
389+
node->scan.scanstate->cstate.cs_ExprContext,
390+
&isNull, &isDone);
390391
scan_keys[j].sk_argument = scanvalue;
391392
if (isNull)
392393
scan_keys[j].sk_flags |= SK_ISNULL;

src/backend/executor/nodeTidscan.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.4 2000/01/26 05:56:24 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.5 2000/04/07 00:30:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -109,8 +109,10 @@ TidNext(TidScan *node)
109109
if (estate->es_evTupleNull[node->scan.scanrelid - 1])
110110
return slot; /* return empty slot */
111111

112+
/* probably ought to use ExecStoreTuple here... */
112113
slot->val = estate->es_evTuple[node->scan.scanrelid - 1];
113114
slot->ttc_shouldFree = false;
115+
114116
/* Flag for the next call that no more tuples */
115117
estate->es_evTupleNull[node->scan.scanrelid - 1] = true;
116118
return (slot);
@@ -255,38 +257,29 @@ ExecTidReScan(TidScan *node, ExprContext *exprCtxt, Plan *parent)
255257
{
256258
EState *estate;
257259
TidScanState *tidstate;
258-
Plan *outerPlan;
259260
ItemPointer *tidList;
260261

261262
tidstate = node->tidstate;
262263
estate = node->scan.plan.state;
263264
tidstate->tss_TidPtr = -1;
264265
tidList = tidstate->tss_TidList;
265266

266-
if ((outerPlan = outerPlan((Plan *) node)) != NULL)
267+
/* If we are being passed an outer tuple, save it for runtime key calc */
268+
if (exprCtxt != NULL)
269+
node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple =
270+
exprCtxt->ecxt_outertuple;
271+
272+
/* If this is re-scanning of PlanQual ... */
273+
if (estate->es_evTuple != NULL &&
274+
estate->es_evTuple[node->scan.scanrelid - 1] != NULL)
267275
{
268-
/* we are scanning a subplan */
269-
outerPlan = outerPlan((Plan *) node);
270-
ExecReScan(outerPlan, exprCtxt, parent);
276+
estate->es_evTupleNull[node->scan.scanrelid - 1] = false;
277+
return;
271278
}
272-
else
273-
/* otherwise, we are scanning a relation */
274-
{
275-
/* If this is re-scanning of PlanQual ... */
276-
if (estate->es_evTuple != NULL &&
277-
estate->es_evTuple[node->scan.scanrelid - 1] != NULL)
278-
{
279-
estate->es_evTupleNull[node->scan.scanrelid - 1] = false;
280-
return;
281-
}
282279

283-
/* it's possible in subselects */
284-
if (exprCtxt == NULL)
285-
exprCtxt = node->scan.scanstate->cstate.cs_ExprContext;
286-
287-
node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple = exprCtxt->ecxt_outertuple;
288-
tidstate->tss_NumTids = TidListCreate(node->tideval, exprCtxt, tidList);
289-
}
280+
tidstate->tss_NumTids = TidListCreate(node->tideval,
281+
node->scan.scanstate->cstate.cs_ExprContext,
282+
tidList);
290283

291284
/* ----------------
292285
* perhaps return something meaningful

0 commit comments

Comments
 (0)