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

Commit09529a7

Browse files
committed
Fix parallel index and index-only scans to fall back to serial.
Parallel executor nodes can't assume that parallel execution willhappen in every case where the plan calls for it, because it mightnot work out that way. However, parallel index scan and parallelindex-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
1 parent98e6e89 commit09529a7

File tree

2 files changed

+96
-66
lines changed

2 files changed

+96
-66
lines changed

‎src/backend/executor/nodeIndexonlyscan.c

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,38 @@ IndexOnlyNext(IndexOnlyScanState *node)
7878
econtext=node->ss.ps.ps_ExprContext;
7979
slot=node->ss.ss_ScanTupleSlot;
8080

81+
if (scandesc==NULL)
82+
{
83+
/*
84+
* We reach here if the index only scan is not parallel, or if we're
85+
* executing a index only scan that was intended to be parallel
86+
* serially.
87+
*/
88+
scandesc=index_beginscan(node->ss.ss_currentRelation,
89+
node->ioss_RelationDesc,
90+
estate->es_snapshot,
91+
node->ioss_NumScanKeys,
92+
node->ioss_NumOrderByKeys);
93+
94+
node->ioss_ScanDesc=scandesc;
95+
96+
97+
/* Set it up for index-only scan */
98+
node->ioss_ScanDesc->xs_want_itup= true;
99+
node->ioss_VMBuffer=InvalidBuffer;
100+
101+
/*
102+
* If no run-time keys to calculate or they are ready, go ahead and
103+
* pass the scankeys to the index AM.
104+
*/
105+
if (node->ioss_NumRuntimeKeys==0||node->ioss_RuntimeKeysReady)
106+
index_rescan(scandesc,
107+
node->ioss_ScanKeys,
108+
node->ioss_NumScanKeys,
109+
node->ioss_OrderByKeys,
110+
node->ioss_NumOrderByKeys);
111+
}
112+
81113
/*
82114
* OK, now that we have what we need, fetch the next tuple.
83115
*/
@@ -571,34 +603,6 @@ ExecInitIndexOnlyScan(IndexOnlyScan *node, EState *estate, int eflags)
571603
indexstate->ioss_RuntimeContext=NULL;
572604
}
573605

574-
/*
575-
* Initialize scan descriptor.
576-
*/
577-
if (!node->scan.plan.parallel_aware)
578-
{
579-
indexstate->ioss_ScanDesc=index_beginscan(currentRelation,
580-
indexstate->ioss_RelationDesc,
581-
estate->es_snapshot,
582-
indexstate->ioss_NumScanKeys,
583-
indexstate->ioss_NumOrderByKeys);
584-
585-
586-
/* Set it up for index-only scan */
587-
indexstate->ioss_ScanDesc->xs_want_itup= true;
588-
indexstate->ioss_VMBuffer=InvalidBuffer;
589-
590-
/*
591-
* If no run-time keys to calculate, go ahead and pass the scankeys to
592-
* the index AM.
593-
*/
594-
if (indexstate->ioss_NumRuntimeKeys==0)
595-
index_rescan(indexstate->ioss_ScanDesc,
596-
indexstate->ioss_ScanKeys,
597-
indexstate->ioss_NumScanKeys,
598-
indexstate->ioss_OrderByKeys,
599-
indexstate->ioss_NumOrderByKeys);
600-
}
601-
602606
/*
603607
* all done.
604608
*/
@@ -657,10 +661,10 @@ ExecIndexOnlyScanInitializeDSM(IndexOnlyScanState *node,
657661
node->ioss_VMBuffer=InvalidBuffer;
658662

659663
/*
660-
* If no run-time keys to calculate, go ahead and pass the scankeys to
661-
* the index AM.
664+
* If no run-time keys to calculate or they are ready, go ahead and pass
665+
* thescankeys to theindex AM.
662666
*/
663-
if (node->ioss_NumRuntimeKeys==0)
667+
if (node->ioss_NumRuntimeKeys==0||node->ioss_RuntimeKeysReady)
664668
index_rescan(node->ioss_ScanDesc,
665669
node->ioss_ScanKeys,node->ioss_NumScanKeys,
666670
node->ioss_OrderByKeys,node->ioss_NumOrderByKeys);
@@ -687,10 +691,10 @@ ExecIndexOnlyScanInitializeWorker(IndexOnlyScanState *node, shm_toc *toc)
687691
node->ioss_ScanDesc->xs_want_itup= true;
688692

689693
/*
690-
* If no run-time keys to calculate, go ahead and pass the scankeys to the
691-
* index AM.
694+
* If no run-time keys to calculate or they are ready, go ahead and pass
695+
*the scankeys to theindex AM.
692696
*/
693-
if (node->ioss_NumRuntimeKeys==0)
697+
if (node->ioss_NumRuntimeKeys==0||node->ioss_RuntimeKeysReady)
694698
index_rescan(node->ioss_ScanDesc,
695699
node->ioss_ScanKeys,node->ioss_NumScanKeys,
696700
node->ioss_OrderByKeys,node->ioss_NumOrderByKeys);

‎src/backend/executor/nodeIndexscan.c

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ IndexNext(IndexScanState *node)
102102
econtext=node->ss.ps.ps_ExprContext;
103103
slot=node->ss.ss_ScanTupleSlot;
104104

105+
if (scandesc==NULL)
106+
{
107+
/*
108+
* We reach here if the index scan is not parallel, or if we're
109+
* executing a index scan that was intended to be parallel serially.
110+
*/
111+
scandesc=index_beginscan(node->ss.ss_currentRelation,
112+
node->iss_RelationDesc,
113+
estate->es_snapshot,
114+
node->iss_NumScanKeys,
115+
node->iss_NumOrderByKeys);
116+
117+
node->iss_ScanDesc=scandesc;
118+
119+
/*
120+
* If no run-time keys to calculate or they are ready, go ahead and
121+
* pass the scankeys to the index AM.
122+
*/
123+
if (node->iss_NumRuntimeKeys==0||node->iss_RuntimeKeysReady)
124+
index_rescan(scandesc,
125+
node->iss_ScanKeys,node->iss_NumScanKeys,
126+
node->iss_OrderByKeys,node->iss_NumOrderByKeys);
127+
}
128+
105129
/*
106130
* ok, now that we have what we need, fetch the next tuple.
107131
*/
@@ -154,6 +178,7 @@ IndexNext(IndexScanState *node)
154178
staticTupleTableSlot*
155179
IndexNextWithReorder(IndexScanState*node)
156180
{
181+
EState*estate;
157182
ExprContext*econtext;
158183
IndexScanDescscandesc;
159184
HeapTupletuple;
@@ -164,6 +189,8 @@ IndexNextWithReorder(IndexScanState *node)
164189
bool*lastfetched_nulls;
165190
intcmp;
166191

192+
estate=node->ss.ps.state;
193+
167194
/*
168195
* Only forward scan is supported with reordering. Note: we can get away
169196
* with just Asserting here because the system will not try to run the
@@ -174,12 +201,36 @@ IndexNextWithReorder(IndexScanState *node)
174201
* explicitly.
175202
*/
176203
Assert(!ScanDirectionIsBackward(((IndexScan*)node->ss.ps.plan)->indexorderdir));
177-
Assert(ScanDirectionIsForward(node->ss.ps.state->es_direction));
204+
Assert(ScanDirectionIsForward(estate->es_direction));
178205

179206
scandesc=node->iss_ScanDesc;
180207
econtext=node->ss.ps.ps_ExprContext;
181208
slot=node->ss.ss_ScanTupleSlot;
182209

210+
if (scandesc==NULL)
211+
{
212+
/*
213+
* We reach here if the index scan is not parallel, or if we're
214+
* executing a index scan that was intended to be parallel serially.
215+
*/
216+
scandesc=index_beginscan(node->ss.ss_currentRelation,
217+
node->iss_RelationDesc,
218+
estate->es_snapshot,
219+
node->iss_NumScanKeys,
220+
node->iss_NumOrderByKeys);
221+
222+
node->iss_ScanDesc=scandesc;
223+
224+
/*
225+
* If no run-time keys to calculate or they are ready, go ahead and
226+
* pass the scankeys to the index AM.
227+
*/
228+
if (node->iss_NumRuntimeKeys==0||node->iss_RuntimeKeysReady)
229+
index_rescan(scandesc,
230+
node->iss_ScanKeys,node->iss_NumScanKeys,
231+
node->iss_OrderByKeys,node->iss_NumOrderByKeys);
232+
}
233+
183234
for (;;)
184235
{
185236
/*
@@ -1038,31 +1089,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
10381089
indexstate->iss_RuntimeContext=NULL;
10391090
}
10401091

1041-
/*
1042-
* for parallel-aware node, we initialize the scan descriptor after
1043-
* initializing the shared memory for parallel execution.
1044-
*/
1045-
if (!node->scan.plan.parallel_aware)
1046-
{
1047-
/*
1048-
* Initialize scan descriptor.
1049-
*/
1050-
indexstate->iss_ScanDesc=index_beginscan(currentRelation,
1051-
indexstate->iss_RelationDesc,
1052-
estate->es_snapshot,
1053-
indexstate->iss_NumScanKeys,
1054-
indexstate->iss_NumOrderByKeys);
1055-
1056-
/*
1057-
* If no run-time keys to calculate, go ahead and pass the scankeys to
1058-
* the index AM.
1059-
*/
1060-
if (indexstate->iss_NumRuntimeKeys==0)
1061-
index_rescan(indexstate->iss_ScanDesc,
1062-
indexstate->iss_ScanKeys,indexstate->iss_NumScanKeys,
1063-
indexstate->iss_OrderByKeys,indexstate->iss_NumOrderByKeys);
1064-
}
1065-
10661092
/*
10671093
* all done.
10681094
*/
@@ -1674,10 +1700,10 @@ ExecIndexScanInitializeDSM(IndexScanState *node,
16741700
piscan);
16751701

16761702
/*
1677-
* If no run-time keys to calculate, go ahead and pass the scankeys to the
1678-
* index AM.
1703+
* If no run-time keys to calculate or they are ready, go ahead and pass
1704+
*the scankeys to theindex AM.
16791705
*/
1680-
if (node->iss_NumRuntimeKeys==0)
1706+
if (node->iss_NumRuntimeKeys==0||node->iss_RuntimeKeysReady)
16811707
index_rescan(node->iss_ScanDesc,
16821708
node->iss_ScanKeys,node->iss_NumScanKeys,
16831709
node->iss_OrderByKeys,node->iss_NumOrderByKeys);
@@ -1703,10 +1729,10 @@ ExecIndexScanInitializeWorker(IndexScanState *node, shm_toc *toc)
17031729
piscan);
17041730

17051731
/*
1706-
* If no run-time keys to calculate, go ahead and pass the scankeys to the
1707-
* index AM.
1732+
* If no run-time keys to calculate or they are ready, go ahead and pass
1733+
*the scankeys to theindex AM.
17081734
*/
1709-
if (node->iss_NumRuntimeKeys==0)
1735+
if (node->iss_NumRuntimeKeys==0||node->iss_RuntimeKeysReady)
17101736
index_rescan(node->iss_ScanDesc,
17111737
node->iss_ScanKeys,node->iss_NumScanKeys,
17121738
node->iss_OrderByKeys,node->iss_NumOrderByKeys);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp