Skip to content

Commit f8a75b0

Browse files
authored
executor: fix hash join v2 bug that mistakenly think the join has other condition (#56834)
close #56825
1 parent 7ce5bd7 commit f8a75b0

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

pkg/executor/builder.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,13 +1514,28 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
15141514
return nil
15151515
}
15161516

1517+
joinOtherCondition := v.OtherConditions
1518+
joinLeftCondition := v.LeftConditions
1519+
joinRightCondition := v.RightConditions
1520+
if len(joinOtherCondition) == 0 {
1521+
// sometimes the OtherCondtition could be a not nil slice with length = 0
1522+
// in HashJoinV2, it is assumed that if there is no other condition, e.HashJoinCtxV2.OtherCondition should be nil
1523+
joinOtherCondition = nil
1524+
}
1525+
if len(joinLeftCondition) == 0 {
1526+
joinLeftCondition = nil
1527+
}
1528+
if len(joinRightCondition) == 0 {
1529+
joinRightCondition = nil
1530+
}
1531+
15171532
e := &join.HashJoinV2Exec{
15181533
BaseExecutor: exec.NewBaseExecutor(b.ctx, v.Schema(), v.ID(), leftExec, rightExec),
15191534
ProbeSideTupleFetcher: &join.ProbeSideTupleFetcherV2{},
15201535
ProbeWorkers: make([]*join.ProbeWorkerV2, v.Concurrency),
15211536
BuildWorkers: make([]*join.BuildWorkerV2, v.Concurrency),
15221537
HashJoinCtxV2: &join.HashJoinCtxV2{
1523-
OtherCondition: v.OtherConditions,
1538+
OtherCondition: joinOtherCondition,
15241539
},
15251540
}
15261541
e.HashJoinCtxV2.SessCtx = b.ctx
@@ -1541,12 +1556,12 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
15411556
joinedTypes = append(joinedTypes, rhsTypes...)
15421557

15431558
if v.InnerChildIdx == 1 {
1544-
if len(v.RightConditions) > 0 {
1559+
if joinRightCondition != nil {
15451560
b.err = errors.Annotate(exeerrors.ErrBuildExecutor, "join's inner condition should be empty")
15461561
return nil
15471562
}
15481563
} else {
1549-
if len(v.LeftConditions) > 0 {
1564+
if joinLeftCondition != nil {
15501565
b.err = errors.Annotate(exeerrors.ErrBuildExecutor, "join's inner condition should be empty")
15511566
return nil
15521567
}
@@ -1558,21 +1573,21 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
15581573
if v.InnerChildIdx == 1 {
15591574
buildSideExec, buildKeys = leftExec, v.LeftJoinKeys
15601575
e.ProbeSideTupleFetcher.ProbeSideExec, probeKeys = rightExec, v.RightJoinKeys
1561-
e.HashJoinCtxV2.BuildFilter = v.LeftConditions
1576+
e.HashJoinCtxV2.BuildFilter = joinLeftCondition
15621577
} else {
15631578
buildSideExec, buildKeys = rightExec, v.RightJoinKeys
15641579
e.ProbeSideTupleFetcher.ProbeSideExec, probeKeys = leftExec, v.LeftJoinKeys
1565-
e.HashJoinCtxV2.BuildFilter = v.RightConditions
1580+
e.HashJoinCtxV2.BuildFilter = joinRightCondition
15661581
}
15671582
} else {
15681583
if v.InnerChildIdx == 0 {
15691584
buildSideExec, buildKeys = leftExec, v.LeftJoinKeys
15701585
e.ProbeSideTupleFetcher.ProbeSideExec, probeKeys = rightExec, v.RightJoinKeys
1571-
e.HashJoinCtxV2.ProbeFilter = v.RightConditions
1586+
e.HashJoinCtxV2.ProbeFilter = joinRightCondition
15721587
} else {
15731588
buildSideExec, buildKeys = rightExec, v.RightJoinKeys
15741589
e.ProbeSideTupleFetcher.ProbeSideExec, probeKeys = leftExec, v.LeftJoinKeys
1575-
e.HashJoinCtxV2.ProbeFilter = v.LeftConditions
1590+
e.HashJoinCtxV2.ProbeFilter = joinLeftCondition
15761591
}
15771592
}
15781593
probeKeyColIdx := make([]int, len(probeKeys))
@@ -1598,9 +1613,9 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
15981613
e.LUsed = append(e.LUsed, childrenUsedSchema[0]...)
15991614
e.RUsed = make([]int, 0, len(childrenUsedSchema[1]))
16001615
e.RUsed = append(e.RUsed, childrenUsedSchema[1]...)
1601-
if v.OtherConditions != nil {
1616+
if joinOtherCondition != nil {
16021617
leftColumnSize := v.Children()[0].Schema().Len()
1603-
e.LUsedInOtherCondition, e.RUsedInOtherCondition = extractUsedColumnsInJoinOtherCondition(v.OtherConditions, leftColumnSize)
1618+
e.LUsedInOtherCondition, e.RUsedInOtherCondition = extractUsedColumnsInJoinOtherCondition(joinOtherCondition, leftColumnSize)
16041619
}
16051620
// todo add partition hash join exec
16061621
executor_metrics.ExecutorCountHashJoinExec.Inc()

0 commit comments

Comments
 (0)