Commit 8d108fb1 authored by Tom Lane's avatar Tom Lane

Fix tid scan evaluation of non-constant TID values; can't try to do it

during ExecInitTidScan, because the rest of the executor isn't ready.
parent 2848dc5f
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.34 2003/08/04 02:39:59 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.35 2003/09/26 01:17:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -29,19 +29,32 @@ ...@@ -29,19 +29,32 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "parser/parsetree.h" #include "parser/parsetree.h"
static int TidListCreate(List *, ExprContext *, ItemPointerData[]);
static void TidListCreate(TidScanState *tidstate);
static TupleTableSlot *TidNext(TidScanState *node); static TupleTableSlot *TidNext(TidScanState *node);
static int
TidListCreate(List *evalList, ExprContext *econtext, ItemPointerData tidList[]) /*
* Compute the list of TIDs to be visited, by evaluating the expressions
* for them.
*/
static void
TidListCreate(TidScanState *tidstate)
{ {
List *lst; List *evalList = tidstate->tss_tideval;
ItemPointer itemptr; ExprContext *econtext = tidstate->ss.ps.ps_ExprContext;
bool isNull; ItemPointerData *tidList;
int numTids = 0; int numTids = 0;
List *lst;
tidList = (ItemPointerData *)
palloc(length(tidstate->tss_tideval) * sizeof(ItemPointerData));
foreach(lst, evalList) foreach(lst, evalList)
{ {
ItemPointer itemptr;
bool isNull;
itemptr = (ItemPointer) itemptr = (ItemPointer)
DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst), DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst),
econtext, econtext,
...@@ -53,7 +66,10 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointerData tidList[]) ...@@ -53,7 +66,10 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointerData tidList[])
numTids++; numTids++;
} }
} }
return numTids;
tidstate->tss_TidList = tidList;
tidstate->tss_NumTids = numTids;
tidstate->tss_TidPtr = -1;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
...@@ -75,10 +91,10 @@ TidNext(TidScanState *node) ...@@ -75,10 +91,10 @@ TidNext(TidScanState *node)
TupleTableSlot *slot; TupleTableSlot *slot;
Index scanrelid; Index scanrelid;
Buffer buffer = InvalidBuffer; Buffer buffer = InvalidBuffer;
ItemPointerData *tidList;
int numTids; int numTids;
bool bBackward; bool bBackward;
int tidNumber; int tidNumber;
ItemPointerData *tidList;
/* /*
* extract necessary information from tid scan node * extract necessary information from tid scan node
...@@ -87,8 +103,6 @@ TidNext(TidScanState *node) ...@@ -87,8 +103,6 @@ TidNext(TidScanState *node)
direction = estate->es_direction; direction = estate->es_direction;
snapshot = estate->es_snapshot; snapshot = estate->es_snapshot;
heapRelation = node->ss.ss_currentRelation; heapRelation = node->ss.ss_currentRelation;
numTids = node->tss_NumTids;
tidList = node->tss_TidList;
slot = node->ss.ss_ScanTupleSlot; slot = node->ss.ss_ScanTupleSlot;
scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid; scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid;
...@@ -118,6 +132,15 @@ TidNext(TidScanState *node) ...@@ -118,6 +132,15 @@ TidNext(TidScanState *node)
return (slot); return (slot);
} }
/*
* First time through, compute the list of TIDs to be visited
*/
if (node->tss_TidList == NULL)
TidListCreate(node);
tidList = node->tss_TidList;
numTids = node->tss_NumTids;
tuple = &(node->tss_htup); tuple = &(node->tss_htup);
/* /*
...@@ -174,9 +197,7 @@ TidNext(TidScanState *node) ...@@ -174,9 +197,7 @@ TidNext(TidScanState *node)
/* /*
* We must check to see if the current tuple would have been * We must check to see if the current tuple would have been
* matched by an earlier tid, so we don't double report it. We * matched by an earlier tid, so we don't double report it.
* do this by passing the tuple through ExecQual and look for
* failure with all previous qualifications.
*/ */
for (prev_tid = 0; prev_tid < node->tss_TidPtr; for (prev_tid = 0; prev_tid < node->tss_TidPtr;
prev_tid++) prev_tid++)
...@@ -244,11 +265,9 @@ void ...@@ -244,11 +265,9 @@ void
ExecTidReScan(TidScanState *node, ExprContext *exprCtxt) ExecTidReScan(TidScanState *node, ExprContext *exprCtxt)
{ {
EState *estate; EState *estate;
ItemPointerData *tidList;
Index scanrelid; Index scanrelid;
estate = node->ss.ps.state; estate = node->ss.ps.state;
tidList = node->tss_TidList;
scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid; scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid;
/* If we are being passed an outer tuple, save it for runtime key calc */ /* If we are being passed an outer tuple, save it for runtime key calc */
...@@ -264,6 +283,10 @@ ExecTidReScan(TidScanState *node, ExprContext *exprCtxt) ...@@ -264,6 +283,10 @@ ExecTidReScan(TidScanState *node, ExprContext *exprCtxt)
return; return;
} }
if (node->tss_TidList)
pfree(node->tss_TidList);
node->tss_TidList = NULL;
node->tss_NumTids = 0;
node->tss_TidPtr = -1; node->tss_TidPtr = -1;
} }
...@@ -341,9 +364,6 @@ TidScanState * ...@@ -341,9 +364,6 @@ TidScanState *
ExecInitTidScan(TidScan *node, EState *estate) ExecInitTidScan(TidScan *node, EState *estate)
{ {
TidScanState *tidstate; TidScanState *tidstate;
ItemPointerData *tidList;
int numTids;
int tidPtr;
List *rangeTable; List *rangeTable;
RangeTblEntry *rtentry; RangeTblEntry *rtentry;
Oid relid; Oid relid;
...@@ -375,6 +395,10 @@ ExecInitTidScan(TidScan *node, EState *estate) ...@@ -375,6 +395,10 @@ ExecInitTidScan(TidScan *node, EState *estate)
ExecInitExpr((Expr *) node->scan.plan.qual, ExecInitExpr((Expr *) node->scan.plan.qual,
(PlanState *) tidstate); (PlanState *) tidstate);
tidstate->tss_tideval = (List *)
ExecInitExpr((Expr *) node->tideval,
(PlanState *) tidstate);
#define TIDSCAN_NSLOTS 2 #define TIDSCAN_NSLOTS 2
/* /*
...@@ -384,22 +408,11 @@ ExecInitTidScan(TidScan *node, EState *estate) ...@@ -384,22 +408,11 @@ ExecInitTidScan(TidScan *node, EState *estate)
ExecInitScanTupleSlot(estate, &tidstate->ss); ExecInitScanTupleSlot(estate, &tidstate->ss);
/* /*
* get the tid node information * mark tid list as not computed yet
*/ */
tidList = (ItemPointerData *) palloc(length(node->tideval) * sizeof(ItemPointerData)); tidstate->tss_TidList = NULL;
tidstate->tss_tideval = (List *) tidstate->tss_NumTids = 0;
ExecInitExpr((Expr *) node->tideval, tidstate->tss_TidPtr = -1;
(PlanState *) tidstate);
numTids = TidListCreate(tidstate->tss_tideval,
tidstate->ss.ps.ps_ExprContext,
tidList);
tidPtr = -1;
CXT1_printf("ExecInitTidScan: context is %d\n", CurrentMemoryContext);
tidstate->tss_NumTids = numTids;
tidstate->tss_TidPtr = tidPtr;
tidstate->tss_TidList = tidList;
/* /*
* get the range table and direction information from the execution * get the range table and direction information from the execution
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment