Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: try to optimize index join query by reduce cop task count #55359

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pkg/executor/join/index_lookup_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (e *IndexLookUpJoin) Open(ctx context.Context) error {
return nil
}

func (e *IndexLookUpJoin) startWorkers(ctx context.Context) {
func (e *IndexLookUpJoin) startWorkers(ctx context.Context, initBatchSize int) {
concurrency := e.Ctx().GetSessionVars().IndexLookupJoinConcurrency()
if e.stats != nil {
e.stats.concurrency = concurrency
Expand All @@ -197,23 +197,25 @@ func (e *IndexLookUpJoin) startWorkers(ctx context.Context) {
e.cancelFunc = cancelFunc
innerCh := make(chan *lookUpJoinTask, concurrency)
e.WorkerWg.Add(1)
go e.newOuterWorker(resultCh, innerCh).run(workerCtx, e.WorkerWg)
go e.newOuterWorker(resultCh, innerCh, initBatchSize).run(workerCtx, e.WorkerWg)
for i := 0; i < concurrency; i++ {
innerWorker := e.newInnerWorker(innerCh)
e.WorkerWg.Add(1)
go innerWorker.run(workerCtx, e.WorkerWg)
}
}

func (e *IndexLookUpJoin) newOuterWorker(resultCh, innerCh chan *lookUpJoinTask) *outerWorker {
func (e *IndexLookUpJoin) newOuterWorker(resultCh, innerCh chan *lookUpJoinTask, initBatchSize int) *outerWorker {
maxBatchSize := e.Ctx().GetSessionVars().IndexJoinBatchSize
batchSize := min(initBatchSize, maxBatchSize)
ow := &outerWorker{
OuterCtx: e.OuterCtx,
ctx: e.Ctx(),
executor: e.Children(0),
resultCh: resultCh,
innerCh: innerCh,
batchSize: 32,
maxBatchSize: e.Ctx().GetSessionVars().IndexJoinBatchSize,
batchSize: batchSize,
maxBatchSize: maxBatchSize,
parentMemTracker: e.memTracker,
lookup: e,
}
Expand Down Expand Up @@ -273,7 +275,7 @@ func (e *IndexLookUpJoin) newInnerWorker(taskCh chan *lookUpJoinTask) *innerWork
// Next implements the Executor interface.
func (e *IndexLookUpJoin) Next(ctx context.Context, req *chunk.Chunk) error {
if !e.prepared {
e.startWorkers(ctx)
e.startWorkers(ctx, req.RequiredRows())
e.prepared = true
}
if e.IsOuterJoin {
Expand Down