Skip to content

Commit 8d108fb

Browse files
committed
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.
1 parent 2848dc5 commit 8d108fb

File tree

1 file changed

+47
-34
lines changed

1 file changed

+47
-34
lines changed

src/backend/executor/nodeTidscan.c

Lines changed: 47 additions & 34 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.34 2003/08/04 02:39:59 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.35 2003/09/26 01:17:01 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -29,19 +29,32 @@
2929
#include "access/heapam.h"
3030
#include "parser/parsetree.h"
3131

32-
static int TidListCreate(List *, ExprContext *, ItemPointerData[]);
32+
33+
static void TidListCreate(TidScanState *tidstate);
3334
static TupleTableSlot *TidNext(TidScanState *node);
3435

35-
static int
36-
TidListCreate(List *evalList, ExprContext *econtext, ItemPointerData tidList[])
36+
37+
/*
38+
* Compute the list of TIDs to be visited, by evaluating the expressions
39+
* for them.
40+
*/
41+
static void
42+
TidListCreate(TidScanState *tidstate)
3743
{
38-
List *lst;
39-
ItemPointer itemptr;
40-
bool isNull;
44+
List *evalList = tidstate->tss_tideval;
45+
ExprContext *econtext = tidstate->ss.ps.ps_ExprContext;
46+
ItemPointerData *tidList;
4147
int numTids = 0;
48+
List *lst;
49+
50+
tidList = (ItemPointerData *)
51+
palloc(length(tidstate->tss_tideval) * sizeof(ItemPointerData));
4252

4353
foreach(lst, evalList)
4454
{
55+
ItemPointer itemptr;
56+
bool isNull;
57+
4558
itemptr = (ItemPointer)
4659
DatumGetPointer(ExecEvalExprSwitchContext(lfirst(lst),
4760
econtext,
@@ -53,7 +66,10 @@ TidListCreate(List *evalList, ExprContext *econtext, ItemPointerData tidList[])
5366
numTids++;
5467
}
5568
}
56-
return numTids;
69+
70+
tidstate->tss_TidList = tidList;
71+
tidstate->tss_NumTids = numTids;
72+
tidstate->tss_TidPtr = -1;
5773
}
5874

5975
/* ----------------------------------------------------------------
@@ -75,10 +91,10 @@ TidNext(TidScanState *node)
7591
TupleTableSlot *slot;
7692
Index scanrelid;
7793
Buffer buffer = InvalidBuffer;
94+
ItemPointerData *tidList;
7895
int numTids;
7996
bool bBackward;
8097
int tidNumber;
81-
ItemPointerData *tidList;
8298

8399
/*
84100
* extract necessary information from tid scan node
@@ -87,8 +103,6 @@ TidNext(TidScanState *node)
87103
direction = estate->es_direction;
88104
snapshot = estate->es_snapshot;
89105
heapRelation = node->ss.ss_currentRelation;
90-
numTids = node->tss_NumTids;
91-
tidList = node->tss_TidList;
92106
slot = node->ss.ss_ScanTupleSlot;
93107
scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid;
94108

@@ -118,6 +132,15 @@ TidNext(TidScanState *node)
118132
return (slot);
119133
}
120134

135+
/*
136+
* First time through, compute the list of TIDs to be visited
137+
*/
138+
if (node->tss_TidList == NULL)
139+
TidListCreate(node);
140+
141+
tidList = node->tss_TidList;
142+
numTids = node->tss_NumTids;
143+
121144
tuple = &(node->tss_htup);
122145

123146
/*
@@ -174,9 +197,7 @@ TidNext(TidScanState *node)
174197

175198
/*
176199
* We must check to see if the current tuple would have been
177-
* matched by an earlier tid, so we don't double report it. We
178-
* do this by passing the tuple through ExecQual and look for
179-
* failure with all previous qualifications.
200+
* matched by an earlier tid, so we don't double report it.
180201
*/
181202
for (prev_tid = 0; prev_tid < node->tss_TidPtr;
182203
prev_tid++)
@@ -244,11 +265,9 @@ void
244265
ExecTidReScan(TidScanState *node, ExprContext *exprCtxt)
245266
{
246267
EState *estate;
247-
ItemPointerData *tidList;
248268
Index scanrelid;
249269

250270
estate = node->ss.ps.state;
251-
tidList = node->tss_TidList;
252271
scanrelid = ((TidScan *) node->ss.ps.plan)->scan.scanrelid;
253272

254273
/* If we are being passed an outer tuple, save it for runtime key calc */
@@ -264,6 +283,10 @@ ExecTidReScan(TidScanState *node, ExprContext *exprCtxt)
264283
return;
265284
}
266285

286+
if (node->tss_TidList)
287+
pfree(node->tss_TidList);
288+
node->tss_TidList = NULL;
289+
node->tss_NumTids = 0;
267290
node->tss_TidPtr = -1;
268291
}
269292

@@ -341,9 +364,6 @@ TidScanState *
341364
ExecInitTidScan(TidScan *node, EState *estate)
342365
{
343366
TidScanState *tidstate;
344-
ItemPointerData *tidList;
345-
int numTids;
346-
int tidPtr;
347367
List *rangeTable;
348368
RangeTblEntry *rtentry;
349369
Oid relid;
@@ -375,6 +395,10 @@ ExecInitTidScan(TidScan *node, EState *estate)
375395
ExecInitExpr((Expr *) node->scan.plan.qual,
376396
(PlanState *) tidstate);
377397

398+
tidstate->tss_tideval = (List *)
399+
ExecInitExpr((Expr *) node->tideval,
400+
(PlanState *) tidstate);
401+
378402
#define TIDSCAN_NSLOTS 2
379403

380404
/*
@@ -384,22 +408,11 @@ ExecInitTidScan(TidScan *node, EState *estate)
384408
ExecInitScanTupleSlot(estate, &tidstate->ss);
385409

386410
/*
387-
* get the tid node information
411+
* mark tid list as not computed yet
388412
*/
389-
tidList = (ItemPointerData *) palloc(length(node->tideval) * sizeof(ItemPointerData));
390-
tidstate->tss_tideval = (List *)
391-
ExecInitExpr((Expr *) node->tideval,
392-
(PlanState *) tidstate);
393-
numTids = TidListCreate(tidstate->tss_tideval,
394-
tidstate->ss.ps.ps_ExprContext,
395-
tidList);
396-
tidPtr = -1;
397-
398-
CXT1_printf("ExecInitTidScan: context is %d\n", CurrentMemoryContext);
399-
400-
tidstate->tss_NumTids = numTids;
401-
tidstate->tss_TidPtr = tidPtr;
402-
tidstate->tss_TidList = tidList;
413+
tidstate->tss_TidList = NULL;
414+
tidstate->tss_NumTids = 0;
415+
tidstate->tss_TidPtr = -1;
403416

404417
/*
405418
* get the range table and direction information from the execution

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy