econtext = node->ss.ps.ps_ExprContext;
slot = node->ss.ss_ScanTupleSlot;
+ if (scandesc == NULL)
+ {
+ /*
+ * We reach here if the index only scan is not parallel, or if we're
+ * executing a index only scan that was intended to be parallel
+ * serially.
+ */
+ scandesc = index_beginscan(node->ss.ss_currentRelation,
+ node->ioss_RelationDesc,
+ estate->es_snapshot,
+ node->ioss_NumScanKeys,
+ node->ioss_NumOrderByKeys);
+
+ node->ioss_ScanDesc = scandesc;
+
+
+ /* Set it up for index-only scan */
+ node->ioss_ScanDesc->xs_want_itup = true;
+ node->ioss_VMBuffer = InvalidBuffer;
+
+ /*
+ * If no run-time keys to calculate or they are ready, go ahead and
+ * pass the scankeys to the index AM.
+ */
+ if (node->ioss_NumRuntimeKeys == 0 || node->ioss_RuntimeKeysReady)
+ index_rescan(scandesc,
+ node->ioss_ScanKeys,
+ node->ioss_NumScanKeys,
+ node->ioss_OrderByKeys,
+ node->ioss_NumOrderByKeys);
+ }
+
/*
* OK, now that we have what we need, fetch the next tuple.
*/
indexstate->ioss_RuntimeContext = NULL;
}
- /*
- * Initialize scan descriptor.
- */
- if (!node->scan.plan.parallel_aware)
- {
- indexstate->ioss_ScanDesc = index_beginscan(currentRelation,
- indexstate->ioss_RelationDesc,
- estate->es_snapshot,
- indexstate->ioss_NumScanKeys,
- indexstate->ioss_NumOrderByKeys);
-
-
- /* Set it up for index-only scan */
- indexstate->ioss_ScanDesc->xs_want_itup = true;
- indexstate->ioss_VMBuffer = InvalidBuffer;
-
- /*
- * If no run-time keys to calculate, go ahead and pass the scankeys to
- * the index AM.
- */
- if (indexstate->ioss_NumRuntimeKeys == 0)
- index_rescan(indexstate->ioss_ScanDesc,
- indexstate->ioss_ScanKeys,
- indexstate->ioss_NumScanKeys,
- indexstate->ioss_OrderByKeys,
- indexstate->ioss_NumOrderByKeys);
- }
-
/*
* all done.
*/
node->ioss_VMBuffer = InvalidBuffer;
/*
- * If no run-time keys to calculate, go ahead and pass the scankeys to
- * the index AM.
+ * If no run-time keys to calculate or they are ready, go ahead and pass
+ * the scankeys to the index AM.
*/
- if (node->ioss_NumRuntimeKeys == 0)
+ if (node->ioss_NumRuntimeKeys == 0 || node->ioss_RuntimeKeysReady)
index_rescan(node->ioss_ScanDesc,
node->ioss_ScanKeys, node->ioss_NumScanKeys,
node->ioss_OrderByKeys, node->ioss_NumOrderByKeys);
node->ioss_ScanDesc->xs_want_itup = true;
/*
- * If no run-time keys to calculate, go ahead and pass the scankeys to the
- * index AM.
+ * If no run-time keys to calculate or they are ready, go ahead and pass
+ * the scankeys to the index AM.
*/
- if (node->ioss_NumRuntimeKeys == 0)
+ if (node->ioss_NumRuntimeKeys == 0 || node->ioss_RuntimeKeysReady)
index_rescan(node->ioss_ScanDesc,
node->ioss_ScanKeys, node->ioss_NumScanKeys,
node->ioss_OrderByKeys, node->ioss_NumOrderByKeys);
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
+ * executing a index scan that was intended to be parallel serially.
+ */
+ scandesc = index_beginscan(node->ss.ss_currentRelation,
+ node->iss_RelationDesc,
+ estate->es_snapshot,
+ node->iss_NumScanKeys,
+ node->iss_NumOrderByKeys);
+
+ 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)
+ index_rescan(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.
*/
static TupleTableSlot *
IndexNextWithReorder(IndexScanState *node)
{
+ EState *estate;
ExprContext *econtext;
IndexScanDesc scandesc;
HeapTuple tuple;
bool *lastfetched_nulls;
int cmp;
+ estate = node->ss.ps.state;
+
/*
* Only forward scan is supported with reordering. Note: we can get away
* with just Asserting here because the system will not try to run the
* explicitly.
*/
Assert(!ScanDirectionIsBackward(((IndexScan *) node->ss.ps.plan)->indexorderdir));
- Assert(ScanDirectionIsForward(node->ss.ps.state->es_direction));
+ Assert(ScanDirectionIsForward(estate->es_direction));
scandesc = node->iss_ScanDesc;
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
+ * executing a index scan that was intended to be parallel serially.
+ */
+ scandesc = index_beginscan(node->ss.ss_currentRelation,
+ node->iss_RelationDesc,
+ estate->es_snapshot,
+ node->iss_NumScanKeys,
+ node->iss_NumOrderByKeys);
+
+ 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)
+ index_rescan(scandesc,
+ node->iss_ScanKeys, node->iss_NumScanKeys,
+ node->iss_OrderByKeys, node->iss_NumOrderByKeys);
+ }
+
for (;;)
{
/*
indexstate->iss_RuntimeContext = NULL;
}
- /*
- * 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.
- */
- indexstate->iss_ScanDesc = index_beginscan(currentRelation,
- indexstate->iss_RelationDesc,
- estate->es_snapshot,
- indexstate->iss_NumScanKeys,
- indexstate->iss_NumOrderByKeys);
-
- /*
- * If no run-time keys to calculate, go ahead and pass the scankeys to
- * the index AM.
- */
- if (indexstate->iss_NumRuntimeKeys == 0)
- index_rescan(indexstate->iss_ScanDesc,
- indexstate->iss_ScanKeys, indexstate->iss_NumScanKeys,
- indexstate->iss_OrderByKeys, indexstate->iss_NumOrderByKeys);
- }
-
/*
* all done.
*/
piscan);
/*
- * If no run-time keys to calculate, go ahead and pass the scankeys to the
- * index AM.
+ * 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)
index_rescan(node->iss_ScanDesc,
node->iss_ScanKeys, node->iss_NumScanKeys,
node->iss_OrderByKeys, node->iss_NumOrderByKeys);
piscan);
/*
- * If no run-time keys to calculate, go ahead and pass the scankeys to the
- * index AM.
+ * 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)
index_rescan(node->iss_ScanDesc,
node->iss_ScanKeys, node->iss_NumScanKeys,
node->iss_OrderByKeys, node->iss_NumOrderByKeys);