Parallel query bugfix.

This commit is contained in:
TotaJ
2020-12-11 16:26:44 +08:00
parent db55fa203c
commit ed198e6ccc
14 changed files with 108 additions and 99 deletions

View File

@ -80,6 +80,25 @@ static TupleTableSlot* IndexNext(IndexScanState* node)
econtext = node->ss.ps.ps_ExprContext;
slot = node->ss.ss_ScanTupleSlot;
if (scandesc == NULL) {
/*
* We reach here if the index scan is not parallel, or if we're
* serially executing an index scan that was planned to be parallel.
*/
scandesc = abs_idx_beginscan(node->ss.ss_currentRelation, node->iss_RelationDesc, estate->es_snapshot,
node->iss_NumScanKeys, node->iss_NumOrderByKeys, (ScanState*)node);
node->iss_ScanDesc = scandesc;
/*
* If no run-time keys to calculate or they are ready, go ahead and
* pass the scankeys to the index AM.
*/
if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady) {
abs_idx_rescan_local(scandesc, node->iss_ScanKeys, node->iss_NumScanKeys,
node->iss_OrderByKeys, node->iss_NumOrderByKeys);
}
}
/*
* ok, now that we have what we need, fetch the next tuple.
*/
@ -687,38 +706,14 @@ IndexScanState* ExecInitIndexScan(IndexScan* node, EState* estate, int eflags)
(ScanState*)index_state);
Assert(PointerIsValid(index_state->iss_ScanDesc));
}
} else {
/*
* for parallel-aware node, we initialize the scan descriptor after
* initializing the shared memory for parallel execution.
*/
if (!node->scan.plan.parallel_aware) {
/*
* Initialize scan descriptor.
*/
index_state->iss_ScanDesc = abs_idx_beginscan(current_relation,
index_state->iss_RelationDesc,
estate->es_snapshot,
index_state->iss_NumScanKeys,
index_state->iss_NumOrderByKeys,
(ScanState*)index_state);
}
}
if (!node->scan.plan.parallel_aware) {
if (index_state->iss_ScanDesc == NULL) {
/*
* If no run-time keys to calculate, go ahead and pass the scankeys to the
* index AM.
*/
if (index_state->iss_ScanDesc == NULL) {
index_state->ss.ps.stubType = PST_Scan;
} else if (index_state->iss_NumRuntimeKeys == 0) {
abs_idx_rescan_local(index_state->iss_ScanDesc,
index_state->iss_ScanKeys,
index_state->iss_NumScanKeys,
index_state->iss_OrderByKeys,
index_state->iss_NumOrderByKeys);
}
* For non-partition table, iss_ScanDesc always none, so set stubType to PST_None.
* For partition table, if ( 0 == node->scan.itrs), scan_desc is NULL, so set stubType to PST_Scan.
*/
index_state->ss.ps.stubType = node->scan.isPartTbl ? PST_Scan : PST_None;
}
/*
@ -1395,10 +1390,10 @@ void ExecIndexScanInitializeDSM(IndexScanState *node, ParallelContext *pcxt, int
node->iss_NumScanKeys, node->iss_NumOrderByKeys, cxt->pwCtx->queryInfo.piscan[nodeid]);
/*
* If no run-time keys to calculate, go ahead and pass the scankeys to the
* If no run-time keys to calculate or they are ready, go ahead and pass the scankeys to the
* index AM.
*/
if (node->iss_NumRuntimeKeys == 0) {
if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady) {
abs_idx_rescan(node->iss_ScanDesc, node->iss_ScanKeys, node->iss_NumScanKeys, node->iss_OrderByKeys,
node->iss_NumOrderByKeys);
}
@ -1441,10 +1436,10 @@ void ExecIndexScanInitializeWorker(IndexScanState *node, void *context)
node->iss_NumScanKeys, node->iss_NumOrderByKeys, piscan);
/*
* If no run-time keys to calculate, go ahead and pass the scankeys to the
* If no run-time keys to calculate or they are ready, go ahead and pass the scankeys to the
* index AM.
*/
if (node->iss_NumRuntimeKeys == 0) {
if (node->iss_NumRuntimeKeys == 0 || node->iss_RuntimeKeysReady) {
abs_idx_rescan(node->iss_ScanDesc, node->iss_ScanKeys, node->iss_NumScanKeys, node->iss_OrderByKeys,
node->iss_NumOrderByKeys);
}