aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeIndexonlyscan.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-03-08 08:15:24 -0500
committerRobert Haas <rhaas@postgresql.org>2017-03-08 08:15:24 -0500
commit09529a70bb5a77935d086d651c63396767d240d7 (patch)
tree6413df5b74055c6fd5a0f2ffd1bfce3a09f91b8b /src/backend/executor/nodeIndexonlyscan.c
parent98e6e89040a0534ca26914c66cae9dd49ef62ad9 (diff)
downloadpostgresql-09529a70bb5a77935d086d651c63396767d240d7.tar.gz
postgresql-09529a70bb5a77935d086d651c63396767d240d7.zip
Fix parallel index and index-only scans to fall back to serial.
Parallel executor nodes can't assume that parallel execution will happen in every case where the plan calls for it, because it might not work out that way. However, parallel index scan and parallel index-only scan failed to do the right thing here. Repair. Amit Kapila, per a report from me. Discussion: http://postgr.es/m/CAA4eK1Kq5qb_u2AOoda5XBB91vVWz90w=LgtRLgsssriS8pVTw@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeIndexonlyscan.c')
-rw-r--r--src/backend/executor/nodeIndexonlyscan.c72
1 files changed, 38 insertions, 34 deletions
diff --git a/src/backend/executor/nodeIndexonlyscan.c b/src/backend/executor/nodeIndexonlyscan.c
index 4a7f39a7c7d..db7f2e120ea 100644
--- a/src/backend/executor/nodeIndexonlyscan.c
+++ b/src/backend/executor/nodeIndexonlyscan.c
@@ -78,6 +78,38 @@ IndexOnlyNext(IndexOnlyScanState *node)
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.
*/
@@ -572,34 +604,6 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
}
/*
- * 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.
*/
return indexstate;
@@ -657,10 +661,10 @@ ExecIndexOnlyScanInitializeDSM(IndexOnlyScanState *node,
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);
@@ -687,10 +691,10 @@ ExecIndexOnlyScanInitializeWorker(IndexOnlyScanState *node, shm_toc *toc)
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);