@@ -1514,13 +1514,28 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
1514
1514
return nil
1515
1515
}
1516
1516
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
+
1517
1532
e := & join.HashJoinV2Exec {
1518
1533
BaseExecutor : exec .NewBaseExecutor (b .ctx , v .Schema (), v .ID (), leftExec , rightExec ),
1519
1534
ProbeSideTupleFetcher : & join.ProbeSideTupleFetcherV2 {},
1520
1535
ProbeWorkers : make ([]* join.ProbeWorkerV2 , v .Concurrency ),
1521
1536
BuildWorkers : make ([]* join.BuildWorkerV2 , v .Concurrency ),
1522
1537
HashJoinCtxV2 : & join.HashJoinCtxV2 {
1523
- OtherCondition : v . OtherConditions ,
1538
+ OtherCondition : joinOtherCondition ,
1524
1539
},
1525
1540
}
1526
1541
e .HashJoinCtxV2 .SessCtx = b .ctx
@@ -1541,12 +1556,12 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
1541
1556
joinedTypes = append (joinedTypes , rhsTypes ... )
1542
1557
1543
1558
if v .InnerChildIdx == 1 {
1544
- if len ( v . RightConditions ) > 0 {
1559
+ if joinRightCondition != nil {
1545
1560
b .err = errors .Annotate (exeerrors .ErrBuildExecutor , "join's inner condition should be empty" )
1546
1561
return nil
1547
1562
}
1548
1563
} else {
1549
- if len ( v . LeftConditions ) > 0 {
1564
+ if joinLeftCondition != nil {
1550
1565
b .err = errors .Annotate (exeerrors .ErrBuildExecutor , "join's inner condition should be empty" )
1551
1566
return nil
1552
1567
}
@@ -1558,21 +1573,21 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
1558
1573
if v .InnerChildIdx == 1 {
1559
1574
buildSideExec , buildKeys = leftExec , v .LeftJoinKeys
1560
1575
e .ProbeSideTupleFetcher .ProbeSideExec , probeKeys = rightExec , v .RightJoinKeys
1561
- e .HashJoinCtxV2 .BuildFilter = v . LeftConditions
1576
+ e .HashJoinCtxV2 .BuildFilter = joinLeftCondition
1562
1577
} else {
1563
1578
buildSideExec , buildKeys = rightExec , v .RightJoinKeys
1564
1579
e .ProbeSideTupleFetcher .ProbeSideExec , probeKeys = leftExec , v .LeftJoinKeys
1565
- e .HashJoinCtxV2 .BuildFilter = v . RightConditions
1580
+ e .HashJoinCtxV2 .BuildFilter = joinRightCondition
1566
1581
}
1567
1582
} else {
1568
1583
if v .InnerChildIdx == 0 {
1569
1584
buildSideExec , buildKeys = leftExec , v .LeftJoinKeys
1570
1585
e .ProbeSideTupleFetcher .ProbeSideExec , probeKeys = rightExec , v .RightJoinKeys
1571
- e .HashJoinCtxV2 .ProbeFilter = v . RightConditions
1586
+ e .HashJoinCtxV2 .ProbeFilter = joinRightCondition
1572
1587
} else {
1573
1588
buildSideExec , buildKeys = rightExec , v .RightJoinKeys
1574
1589
e .ProbeSideTupleFetcher .ProbeSideExec , probeKeys = leftExec , v .LeftJoinKeys
1575
- e .HashJoinCtxV2 .ProbeFilter = v . LeftConditions
1590
+ e .HashJoinCtxV2 .ProbeFilter = joinLeftCondition
1576
1591
}
1577
1592
}
1578
1593
probeKeyColIdx := make ([]int , len (probeKeys ))
@@ -1598,9 +1613,9 @@ func (b *executorBuilder) buildHashJoinV2(v *plannercore.PhysicalHashJoin) exec.
1598
1613
e .LUsed = append (e .LUsed , childrenUsedSchema [0 ]... )
1599
1614
e .RUsed = make ([]int , 0 , len (childrenUsedSchema [1 ]))
1600
1615
e .RUsed = append (e .RUsed , childrenUsedSchema [1 ]... )
1601
- if v . OtherConditions != nil {
1616
+ if joinOtherCondition != nil {
1602
1617
leftColumnSize := v .Children ()[0 ].Schema ().Len ()
1603
- e .LUsedInOtherCondition , e .RUsedInOtherCondition = extractUsedColumnsInJoinOtherCondition (v . OtherConditions , leftColumnSize )
1618
+ e .LUsedInOtherCondition , e .RUsedInOtherCondition = extractUsedColumnsInJoinOtherCondition (joinOtherCondition , leftColumnSize )
1604
1619
}
1605
1620
// todo add partition hash join exec
1606
1621
executor_metrics .ExecutorCountHashJoinExec .Inc ()
0 commit comments