Skip to content

Commit

Permalink
exeuctor: add a helper variable to help ga hash join v2 step by step …
Browse files Browse the repository at this point in the history
…for all kinds of join types (#57116)

ref #53127
  • Loading branch information
windtalker authored Nov 5, 2024
1 parent 4cfe22c commit 8a62d5a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/executor/join/joinversion/join_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ const (
HashJoinVersionOptimized = "optimized"
)

var (
// UseHashJoinV2ForNonGAJoin is added because Hash join contains a lots of types(like inner join, outer join, semi join, nullaware semi join, etc)
// 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,
// 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).
// PhysicalHashJoin.isGAForHashJoinV2() defines whether the join is GA for hash join v2, we can make each join GA separately by updating
// this function one by one
UseHashJoinV2ForNonGAJoin = false
)

func init() {
// This variable is set to true for test, need to be set back to false in release version
UseHashJoinV2ForNonGAJoin = true
}

// IsOptimizedVersion returns true if hashJoinVersion equals to HashJoinVersionOptimized
func IsOptimizedVersion(hashJoinVersion string) bool {
return strings.ToLower(hashJoinVersion) == HashJoinVersionOptimized
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ go_library(
"//pkg/distsql",
"//pkg/domain",
"//pkg/errctx",
"//pkg/executor/join/joinversion",
"//pkg/expression",
"//pkg/expression/aggregation",
"//pkg/expression/exprctx",
Expand Down
27 changes: 27 additions & 0 deletions pkg/planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"unsafe"

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

func (p *PhysicalHashJoin) isGAForHashJoinV2() bool {
// nullaware join
if len(p.LeftNAJoinKeys) > 0 {
return false
}
// cross join
if len(p.LeftJoinKeys) == 0 {
return false
}
// join with null equal condition
for _, value := range p.IsNullEQ {
if value {
return false
}
}
switch p.JoinType {
case logicalop.LeftOuterJoin, logicalop.RightOuterJoin, logicalop.InnerJoin:
return true
default:
return false
}
}

// CanUseHashJoinV2 returns true if current join is supported by hash join v2
func (p *PhysicalHashJoin) CanUseHashJoinV2() bool {
if !p.isGAForHashJoinV2() && !joinversion.UseHashJoinV2ForNonGAJoin {
return false
}
switch p.JoinType {
case logicalop.LeftOuterJoin, logicalop.RightOuterJoin, logicalop.InnerJoin:
// null aware join is not supported yet
Expand Down

0 comments on commit 8a62d5a

Please sign in to comment.