Skip to content

Commit 199bf90

Browse files
authored
executor: try to optimize index hash join query by reduce cop task count (#54841)
close #54840
1 parent 60c7e61 commit 199bf90

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pkg/executor/join/index_lookup_hash_join.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (e *IndexNestedLoopHashJoin) Open(ctx context.Context) error {
146146
return nil
147147
}
148148

149-
func (e *IndexNestedLoopHashJoin) startWorkers(ctx context.Context) {
149+
func (e *IndexNestedLoopHashJoin) startWorkers(ctx context.Context, initBatchSize int) {
150150
concurrency := e.Ctx().GetSessionVars().IndexLookupJoinConcurrency()
151151
if e.stats != nil {
152152
e.stats.concurrency = concurrency
@@ -164,7 +164,7 @@ func (e *IndexNestedLoopHashJoin) startWorkers(ctx context.Context) {
164164
}
165165
e.joinChkResourceCh = make([]chan *chunk.Chunk, concurrency)
166166
e.WorkerWg.Add(1)
167-
ow := e.newOuterWorker(innerCh)
167+
ow := e.newOuterWorker(innerCh, initBatchSize)
168168
go util.WithRecovery(func() { ow.run(e.ctxWithCancel) }, e.finishJoinWorkers)
169169

170170
for i := 0; i < concurrency; i++ {
@@ -221,7 +221,7 @@ func (e *IndexNestedLoopHashJoin) wait4JoinWorkers() {
221221
// Next implements the IndexNestedLoopHashJoin Executor interface.
222222
func (e *IndexNestedLoopHashJoin) Next(ctx context.Context, req *chunk.Chunk) error {
223223
if !e.prepared {
224-
e.startWorkers(ctx)
224+
e.startWorkers(ctx, req.RequiredRows())
225225
e.prepared = true
226226
}
227227
req.Reset()
@@ -411,14 +411,16 @@ func (*indexHashJoinOuterWorker) pushToChan(ctx context.Context, task *indexHash
411411
return false
412412
}
413413

414-
func (e *IndexNestedLoopHashJoin) newOuterWorker(innerCh chan *indexHashJoinTask) *indexHashJoinOuterWorker {
414+
func (e *IndexNestedLoopHashJoin) newOuterWorker(innerCh chan *indexHashJoinTask, initBatchSize int) *indexHashJoinOuterWorker {
415+
maxBatchSize := e.Ctx().GetSessionVars().IndexJoinBatchSize
416+
batchSize := min(initBatchSize, maxBatchSize)
415417
ow := &indexHashJoinOuterWorker{
416418
outerWorker: outerWorker{
417419
OuterCtx: e.OuterCtx,
418420
ctx: e.Ctx(),
419421
executor: e.Children(0),
420-
batchSize: 32,
421-
maxBatchSize: e.Ctx().GetSessionVars().IndexJoinBatchSize,
422+
batchSize: batchSize,
423+
maxBatchSize: maxBatchSize,
422424
parentMemTracker: e.memTracker,
423425
lookup: &e.IndexLookUpJoin,
424426
},

0 commit comments

Comments
 (0)