Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6799a6c

Browse files
committed
Repair problems with EvalPlanQual where target table is scanned as
inner indexscan (ie, one with runtime keys). ExecIndexReScan mustcompute or recompute runtime keys even if we are rescanning in theEPQ case. TidScan seems to have comparable problems. Per bugnoted by Barry Lind 11-Feb-02.
1 parent0cdf4d9 commit6799a6c

File tree

2 files changed

+64
-47
lines changed

2 files changed

+64
-47
lines changed

‎src/backend/executor/nodeIndexscan.c

Lines changed: 46 additions & 40 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.65 2001/11/12 17:18:06 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.66 2002/02/11 20:10:48 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -301,24 +301,13 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
301301
IndexScanState*indexstate;
302302
ExprContext*econtext;
303303
ScanDirectiondirection;
304+
intnumIndices;
304305
IndexScanDescPtrscanDescs;
305306
ScanKey*scanKeys;
306-
IndexScanDescscan;
307-
ScanKeyskey;
308-
intnumIndices;
309-
inti;
310307
int**runtimeKeyInfo;
311308
int*numScanKeys;
312-
List*indxqual;
313-
List*qual;
314-
intn_keys;
315-
ScanKeyscan_keys;
316-
int*run_keys;
309+
inti;
317310
intj;
318-
Expr*clause;
319-
Node*scanexpr;
320-
Datumscanvalue;
321-
boolisNull;
322311

323312
estate=node->scan.plan.state;
324313
indexstate=node->indxstate;
@@ -330,10 +319,6 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
330319
scanKeys=indexstate->iss_ScanKeys;
331320
runtimeKeyInfo=indexstate->iss_RuntimeKeyInfo;
332321
numScanKeys=indexstate->iss_NumScanKeys;
333-
if (ScanDirectionIsBackward(node->indxorderdir))
334-
indexstate->iss_IndexPtr=numIndices;
335-
else
336-
indexstate->iss_IndexPtr=-1;
337322

338323
if (econtext)
339324
{
@@ -359,28 +344,27 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
359344
ResetExprContext(econtext);
360345
}
361346

362-
/* If this is re-scanning of PlanQual ... */
363-
if (estate->es_evTuple!=NULL&&
364-
estate->es_evTuple[node->scan.scanrelid-1]!=NULL)
365-
{
366-
estate->es_evTupleNull[node->scan.scanrelid-1]= false;
367-
return;
368-
}
369-
370347
/*
371-
* get the index qualifications and recalculate the appropriate values
348+
* If we are doing runtime key calculations (ie, the index keys depend
349+
* on data from an outer scan), compute the new key values
372350
*/
373-
indxqual=node->indxqual;
374-
for (i=0;i<numIndices;i++)
351+
if (runtimeKeyInfo)
375352
{
376-
qual=lfirst(indxqual);
377-
indxqual=lnext(indxqual);
378-
n_keys=numScanKeys[i];
379-
scan_keys= (ScanKey)scanKeys[i];
353+
List*indxqual;
380354

381-
if (runtimeKeyInfo)
355+
indxqual=node->indxqual;
356+
for (i=0;i<numIndices;i++)
382357
{
358+
List*qual=lfirst(indxqual);
359+
intn_keys;
360+
ScanKeyscan_keys;
361+
int*run_keys;
362+
363+
indxqual=lnext(indxqual);
364+
n_keys=numScanKeys[i];
365+
scan_keys=scanKeys[i];
383366
run_keys=runtimeKeyInfo[i];
367+
384368
for (j=0;j<n_keys;j++)
385369
{
386370
/*
@@ -398,7 +382,11 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
398382
*/
399383
if (run_keys[j]!=NO_OP)
400384
{
401-
clause=nth(j,qual);
385+
Expr*clause=nth(j,qual);
386+
Node*scanexpr;
387+
Datumscanvalue;
388+
boolisNull;
389+
402390
scanexpr= (run_keys[j]==RIGHT_OP) ?
403391
(Node*)get_rightop(clause) :
404392
(Node*)get_leftop(clause);
@@ -415,13 +403,31 @@ ExecIndexReScan(IndexScan *node, ExprContext *exprCtxt, Plan *parent)
415403
}
416404
}
417405
}
418-
scan=scanDescs[i];
419-
skey=scanKeys[i];
420-
index_rescan(scan,direction,skey);
421-
}
422406

423-
if (runtimeKeyInfo)
424407
indexstate->iss_RuntimeKeysReady= true;
408+
}
409+
410+
/* If this is re-scanning of PlanQual ... */
411+
if (estate->es_evTuple!=NULL&&
412+
estate->es_evTuple[node->scan.scanrelid-1]!=NULL)
413+
{
414+
estate->es_evTupleNull[node->scan.scanrelid-1]= false;
415+
return;
416+
}
417+
418+
/* reset index scans */
419+
if (ScanDirectionIsBackward(node->indxorderdir))
420+
indexstate->iss_IndexPtr=numIndices;
421+
else
422+
indexstate->iss_IndexPtr=-1;
423+
424+
for (i=0;i<numIndices;i++)
425+
{
426+
IndexScanDescscan=scanDescs[i];
427+
ScanKeyskey=scanKeys[i];
428+
429+
index_rescan(scan,direction,skey);
430+
}
425431
}
426432

427433
/* ----------------------------------------------------------------

‎src/backend/executor/nodeTidscan.c

Lines changed: 18 additions & 7 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.21 2001/10/28 06:25:43 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeTidscan.c,v 1.22 2002/02/11 20:10:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -108,6 +108,11 @@ TidNext(TidScan *node)
108108
if (estate->es_evTupleNull[node->scan.scanrelid-1])
109109
returnslot;/* return empty slot */
110110

111+
/*
112+
* XXX shouldn't we check here to make sure tuple matches TID list?
113+
* In runtime-key case this is not certain, is it?
114+
*/
115+
111116
ExecStoreTuple(estate->es_evTuple[node->scan.scanrelid-1],
112117
slot,InvalidBuffer, false);
113118

@@ -250,16 +255,22 @@ ExecTidReScan(TidScan *node, ExprContext *exprCtxt, Plan *parent)
250255
TidScanState*tidstate;
251256
ItemPointerData*tidList;
252257

253-
tidstate=node->tidstate;
254258
estate=node->scan.plan.state;
255-
tidstate->tss_TidPtr=-1;
259+
tidstate=node->tidstate;
256260
tidList=tidstate->tss_TidList;
257261

258262
/* If we are being passed an outer tuple, save it for runtime key calc */
259263
if (exprCtxt!=NULL)
260264
node->scan.scanstate->cstate.cs_ExprContext->ecxt_outertuple=
261265
exprCtxt->ecxt_outertuple;
262266

267+
/* do runtime calc of target TIDs, if needed */
268+
if (node->needRescan)
269+
tidstate->tss_NumTids=
270+
TidListCreate(node->tideval,
271+
node->scan.scanstate->cstate.cs_ExprContext,
272+
tidList);
273+
263274
/* If this is re-scanning of PlanQual ... */
264275
if (estate->es_evTuple!=NULL&&
265276
estate->es_evTuple[node->scan.scanrelid-1]!=NULL)
@@ -268,9 +279,7 @@ ExecTidReScan(TidScan *node, ExprContext *exprCtxt, Plan *parent)
268279
return;
269280
}
270281

271-
tidstate->tss_NumTids=TidListCreate(node->tideval,
272-
node->scan.scanstate->cstate.cs_ExprContext,
273-
tidList);
282+
tidstate->tss_TidPtr=-1;
274283

275284
/*
276285
* perhaps return something meaningful
@@ -432,7 +441,9 @@ ExecInitTidScan(TidScan *node, EState *estate, Plan *parent)
432441
tidList= (ItemPointerData*)palloc(length(node->tideval)*sizeof(ItemPointerData));
433442
numTids=0;
434443
if (!node->needRescan)
435-
numTids=TidListCreate(node->tideval,scanstate->cstate.cs_ExprContext,tidList);
444+
numTids=TidListCreate(node->tideval,
445+
scanstate->cstate.cs_ExprContext,
446+
tidList);
436447
tidPtr=-1;
437448

438449
CXT1_printf("ExecInitTidScan: context is %d\n",CurrentMemoryContext);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp