Skip to content

Commit 8a62d5a

Browse files
authored
exeuctor: add a helper variable to help ga hash join v2 step by step for all kinds of join types (#57116)
ref #53127
1 parent 4cfe22c commit 8a62d5a

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

pkg/executor/join/joinversion/join_version.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const (
2525
HashJoinVersionOptimized = "optimized"
2626
)
2727

28+
var (
29+
// UseHashJoinV2ForNonGAJoin is added because Hash join contains a lots of types(like inner join, outer join, semi join, nullaware semi join, etc)
30+
// we want to GA these different kind of joins step by step, but don't want to add a new session variable for each of the join,
31+
// so we add this variable to control whether to use hash join v2 for nonGA joins(enable it for test, disable it in a release version).
32+
// PhysicalHashJoin.isGAForHashJoinV2() defines whether the join is GA for hash join v2, we can make each join GA separately by updating
33+
// this function one by one
34+
UseHashJoinV2ForNonGAJoin = false
35+
)
36+
37+
func init() {
38+
// This variable is set to true for test, need to be set back to false in release version
39+
UseHashJoinV2ForNonGAJoin = true
40+
}
41+
2842
// IsOptimizedVersion returns true if hashJoinVersion equals to HashJoinVersionOptimized
2943
func IsOptimizedVersion(hashJoinVersion string) bool {
3044
return strings.ToLower(hashJoinVersion) == HashJoinVersionOptimized

pkg/planner/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ go_library(
9696
"//pkg/distsql",
9797
"//pkg/domain",
9898
"//pkg/errctx",
99+
"//pkg/executor/join/joinversion",
99100
"//pkg/expression",
100101
"//pkg/expression/aggregation",
101102
"//pkg/expression/exprctx",

pkg/planner/core/physical_plans.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"unsafe"
2222

2323
"github.com/pingcap/errors"
24+
"github.com/pingcap/tidb/pkg/executor/join/joinversion"
2425
"github.com/pingcap/tidb/pkg/expression"
2526
"github.com/pingcap/tidb/pkg/expression/aggregation"
2627
"github.com/pingcap/tidb/pkg/kv"
@@ -1472,8 +1473,34 @@ type PhysicalHashJoin struct {
14721473
runtimeFilterList []*RuntimeFilter `plan-cache-clone:"must-nil"` // plan with runtime filter is not cached
14731474
}
14741475

1476+
func (p *PhysicalHashJoin) isGAForHashJoinV2() bool {
1477+
// nullaware join
1478+
if len(p.LeftNAJoinKeys) > 0 {
1479+
return false
1480+
}
1481+
// cross join
1482+
if len(p.LeftJoinKeys) == 0 {
1483+
return false
1484+
}
1485+
// join with null equal condition
1486+
for _, value := range p.IsNullEQ {
1487+
if value {
1488+
return false
1489+
}
1490+
}
1491+
switch p.JoinType {
1492+
case logicalop.LeftOuterJoin, logicalop.RightOuterJoin, logicalop.InnerJoin:
1493+
return true
1494+
default:
1495+
return false
1496+
}
1497+
}
1498+
14751499
// CanUseHashJoinV2 returns true if current join is supported by hash join v2
14761500
func (p *PhysicalHashJoin) CanUseHashJoinV2() bool {
1501+
if !p.isGAForHashJoinV2() && !joinversion.UseHashJoinV2ForNonGAJoin {
1502+
return false
1503+
}
14771504
switch p.JoinType {
14781505
case logicalop.LeftOuterJoin, logicalop.RightOuterJoin, logicalop.InnerJoin:
14791506
// null aware join is not supported yet

0 commit comments

Comments
 (0)