Skip to content

Commit 2ea19a0

Browse files
Fix bug with rescan.
1 parent eca9ce2 commit 2ea19a0

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: src/backend/executor/nodeSeqscan.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ SeqNext(SeqScanState *node)
7575

7676
if (scandesc == NULL)
7777
{
78-
int nkeys = 0;
7978
ScanKey keys = NULL;
8079

8180
/*
@@ -84,15 +83,15 @@ SeqNext(SeqScanState *node)
8483
* AM.
8584
*/
8685
if (gp_enable_runtime_filter_pushdown && !node->filter_in_seqscan)
87-
keys = ScanKeyListToArray(node->filters, &nkeys);
86+
keys = ScanKeyListToArray(node->filters, &node->num_scan_keys);
8887

8988
/*
9089
* We reach here if the scan is not parallel, or if we're serially
9190
* executing a scan that was planned to be parallel.
9291
*/
9392
scandesc = table_beginscan_es(node->ss.ss_currentRelation,
9493
estate->es_snapshot,
95-
nkeys, keys,
94+
node->num_scan_keys, keys,
9695
NULL,
9796
&node->ss.ps);
9897
node->ss.ss_currentScanDesc = scandesc;
@@ -283,12 +282,27 @@ void
283282
ExecReScanSeqScan(SeqScanState *node)
284283
{
285284
TableScanDesc scan;
285+
ScanKey keys;
286286

287287
scan = node->ss.ss_currentScanDesc;
288288

289+
/*
290+
* Clear all the pushdown scan keys.
291+
*/
292+
keys = NULL;
293+
if (node->num_scan_keys)
294+
{
295+
keys = (ScanKey)palloc(sizeof(ScanKeyData) * node->num_scan_keys);
296+
for (int i = 0; i < node->num_scan_keys; ++i)
297+
keys[i].sk_flags = SK_EMPYT;
298+
}
299+
289300
if (scan != NULL)
290301
table_rescan(scan, /* scan desc */
291-
NULL); /* new scan keys */
302+
keys); /* new scan keys */
303+
304+
if (keys)
305+
pfree(keys);
292306

293307
ExecScanReScan((ScanState *) node);
294308
}
@@ -455,7 +469,10 @@ ScanKeyListToArray(List *keys, int *num)
455469
ScanKey sk;
456470

457471
if (list_length(keys) == 0)
472+
{
473+
*num = 0;
458474
return NULL;
475+
}
459476

460477
Assert(num);
461478
*num = list_length(keys);

Diff for: src/include/nodes/execnodes.h

+2
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,8 @@ typedef struct SeqScanState
15531553
List *filters; /* the list of struct ScanKeyData */
15541554
bool filter_in_seqscan; /* check scan slot with runtime filters in
15551555
seqscan node or in am */
1556+
int num_scan_keys; /* valid if filter_in_seqscan is false,
1557+
number of pushdown scan keys */
15561558
} SeqScanState;
15571559

15581560
/* ----------------

0 commit comments

Comments
 (0)