@@ -115,11 +115,15 @@ type joinReader struct {
115
115
116
116
// fetcher wraps the row.Fetcher used to perform lookups. This enables the
117
117
// joinReader to wrap the fetcher with a stat collector when necessary.
118
- fetcher rowFetcher
119
- alloc tree.DatumAlloc
120
- rowAlloc rowenc.EncDatumRowAlloc
121
- shouldLimitBatches bool
122
- readerType joinReaderType
118
+ fetcher rowFetcher
119
+ alloc tree.DatumAlloc
120
+ rowAlloc rowenc.EncDatumRowAlloc
121
+ // parallelize, if true, indicates that the KV lookups will be parallelized
122
+ // across ranges when using the DistSender API. It has no influence on the
123
+ // behavior when using the Streamer API (when the lookups are always
124
+ // parallelized).
125
+ parallelize bool
126
+ readerType joinReaderType
123
127
124
128
// txn is the transaction used by the join reader.
125
129
txn * kv.Txn
@@ -326,18 +330,19 @@ func newJoinReader(
326
330
// in case of indexJoinReaderType, we know that there's exactly one lookup
327
331
// row for each input row. Similarly, in case of spec.LookupColumnsAreKey,
328
332
// we know that there's at most one lookup row per input row. In other
329
- // cases, we use limits .
330
- shouldLimitBatches := ! spec .LookupColumnsAreKey && readerType == lookupJoinReaderType
333
+ // cases, we disable parallelism and use the TargetBytes limit .
334
+ parallelize := spec .LookupColumnsAreKey || readerType == indexJoinReaderType
331
335
if flowCtx .EvalCtx .SessionData ().ParallelizeMultiKeyLookupJoinsEnabled {
332
- shouldLimitBatches = false
336
+ parallelize = true
333
337
}
334
338
if spec .MaintainLookupOrdering {
335
- // MaintainLookupOrdering indicates the output of the lookup joiner should
336
- // be sorted by <inputCols>, <lookupCols>. It doesn't make sense for
337
- // MaintainLookupOrdering to be true when MaintainOrdering is not.
338
- // Additionally, we need to disable parallelism for the traditional fetcher
339
- // in order to ensure the lookups are ordered, so set shouldLimitBatches.
340
- spec .MaintainOrdering , shouldLimitBatches = true , true
339
+ // MaintainLookupOrdering indicates the output of the lookup joiner
340
+ // should be sorted by <inputCols>, <lookupCols>. It doesn't make sense
341
+ // for MaintainLookupOrdering to be true when MaintainOrdering is not.
342
+ //
343
+ // Additionally, we need to disable parallelism for the traditional
344
+ // fetcher in order to ensure the lookups are ordered.
345
+ spec .MaintainOrdering , parallelize = true , false
341
346
}
342
347
useStreamer , txn , err := flowCtx .UseStreamer (ctx )
343
348
if err != nil {
@@ -354,7 +359,7 @@ func newJoinReader(
354
359
input : input ,
355
360
lookupCols : lookupCols ,
356
361
outputGroupContinuationForLeftRow : spec .OutputGroupContinuationForLeftRow ,
357
- shouldLimitBatches : shouldLimitBatches ,
362
+ parallelize : parallelize ,
358
363
readerType : readerType ,
359
364
txn : txn ,
360
365
usesStreamer : useStreamer ,
@@ -862,8 +867,8 @@ func (jr *joinReader) getBatchBytesLimit() rowinfra.BytesLimit {
862
867
// BatchRequests.
863
868
return rowinfra .NoBytesLimit
864
869
}
865
- if ! jr .shouldLimitBatches {
866
- // We deem it safe to not limit the batches in order to get the
870
+ if jr .parallelize {
871
+ // We deem it safe to not use the TargetBytes limit in order to get the
867
872
// DistSender-level parallelism.
868
873
return rowinfra .NoBytesLimit
869
874
}
@@ -1047,11 +1052,13 @@ func (jr *joinReader) readInput() (
1047
1052
// fetcher only accepts a limit if the spans are sorted), and
1048
1053
// b) Pebble has various optimizations for Seeks in sorted order.
1049
1054
if jr .readerType == indexJoinReaderType && jr .maintainOrdering {
1050
- // Assert that the index join doesn't have shouldLimitBatches set. Since we
1051
- // didn't sort above, the fetcher doesn't support a limit.
1052
- if jr .shouldLimitBatches {
1055
+ // Assert that the index join has 'parallelize=true' set. Since we
1056
+ // didn't sort above, the fetcher doesn't support the TargetBytes limit
1057
+ // (which would be set via getBatchBytesLimit() if 'parallelize' was
1058
+ // false).
1059
+ if ! jr .parallelize {
1053
1060
err := errors .AssertionFailedf ("index join configured with both maintainOrdering and " +
1054
- "shouldLimitBatched ; this shouldn't have happened as the implementation doesn't support it" )
1061
+ "parallelize=false ; this shouldn't have happened as the implementation doesn't support it" )
1055
1062
jr .MoveToDraining (err )
1056
1063
return jrStateUnknown , nil , jr .DrainHelper ()
1057
1064
}
0 commit comments