-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
planner: fix cascades about the XFormed operator should derive their …
- Loading branch information
Showing
49 changed files
with
448 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
pkg/planner/cascades/rule/apply/decorrelate_apply/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "decorrelate_apply", | ||
srcs = ["xf_decorrelate_apply.go"], | ||
importpath = "github.com/pingcap/tidb/pkg/planner/cascades/rule/apply/decorrelate_apply", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/planner/cascades/pattern", | ||
"//pkg/planner/cascades/rule", | ||
"//pkg/planner/core/base", | ||
"//pkg/planner/core/operator/logicalop", | ||
"//pkg/planner/util/coreusage", | ||
"//pkg/util/intest", | ||
"//pkg/util/plancodec", | ||
], | ||
) |
67 changes: 67 additions & 0 deletions
67
pkg/planner/cascades/rule/apply/decorrelate_apply/xf_decorrelate_apply.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package decorrelateapply | ||
|
||
import ( | ||
"github.com/pingcap/tidb/pkg/planner/cascades/pattern" | ||
"github.com/pingcap/tidb/pkg/planner/cascades/rule" | ||
corebase "github.com/pingcap/tidb/pkg/planner/core/base" | ||
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop" | ||
"github.com/pingcap/tidb/pkg/planner/util/coreusage" | ||
"github.com/pingcap/tidb/pkg/util/intest" | ||
"github.com/pingcap/tidb/pkg/util/plancodec" | ||
) | ||
|
||
var _ rule.Rule = &XFDeCorrelateApply{} | ||
|
||
// XFDeCorrelateApply pull the correlated expression from projection as child of apply. | ||
type XFDeCorrelateApply struct { | ||
*rule.BaseRule | ||
} | ||
|
||
// NewXFDeCorrelateApply creates a new XFDeCorrelateApply rule. | ||
func NewXFDeCorrelateApply() *XFDeCorrelateApply { | ||
pa := pattern.NewPattern(pattern.OperandApply, pattern.EngineTiDBOnly) | ||
pa.SetChildren(pattern.NewPattern(pattern.OperandAny, pattern.EngineTiDBOnly), pattern.NewPattern(pattern.OperandAny, pattern.EngineTiDBOnly)) | ||
return &XFDeCorrelateApply{ | ||
BaseRule: rule.NewBaseRule(rule.XFDeCorrelateApply, pa), | ||
} | ||
} | ||
|
||
// Match implements the Rule interface. | ||
func (*XFDeCorrelateApply) Match(_ corebase.LogicalPlan) bool { | ||
return true | ||
} | ||
|
||
// XForm implements the Rule interface. | ||
func (*XFDeCorrelateApply) XForm(applyGE corebase.LogicalPlan) ([]corebase.LogicalPlan, error) { | ||
children := applyGE.Children() | ||
outerPlanGE := children[0] | ||
innerPlanGE := children[1] | ||
// don't modify the apply op's CorCols in-place, which will change the hash64, apply should be re-inserted into the group otherwise. | ||
corCols := coreusage.ExtractCorColumnsBySchema4LogicalPlan(innerPlanGE.GetWrappedLogicalPlan(), outerPlanGE.GetWrappedLogicalPlan().Schema()) | ||
if len(corCols) == 0 { | ||
apply := applyGE.GetWrappedLogicalPlan().(*logicalop.LogicalApply) | ||
// If the inner plan is non-correlated, this apply will be simplified to join. | ||
clonedJoin := apply.LogicalJoin | ||
// Reset4Cascades is to reset the plan for cascades. | ||
// reset the tp and self, stats to nil, recreate the task map, re-alloc the plan id and so on. | ||
// set the new GE's stats to nil, since the inherited stats is not precious, which will be filled in physicalOpt. | ||
clonedJoin.Reset4Cascades(plancodec.TypeJoin, &clonedJoin) | ||
intest.Assert(clonedJoin.Children() != nil) | ||
return []corebase.LogicalPlan{&clonedJoin}, nil | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "ruleset", | ||
srcs = ["rule_set.go"], | ||
importpath = "github.com/pingcap/tidb/pkg/planner/cascades/rule/ruleset", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/planner/cascades/pattern", | ||
"//pkg/planner/cascades/rule", | ||
"//pkg/planner/cascades/rule/apply/decorrelate_apply", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2024 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ruleset | ||
|
||
import ( | ||
"github.com/pingcap/tidb/pkg/planner/cascades/pattern" | ||
"github.com/pingcap/tidb/pkg/planner/cascades/rule" | ||
"github.com/pingcap/tidb/pkg/planner/cascades/rule/apply/decorrelate_apply" | ||
) | ||
|
||
// DefaultRuleSet is default set of a series of rules. | ||
var DefaultRuleSet = map[pattern.Operand][]rule.Rule{ | ||
pattern.OperandApply: { | ||
decorrelateapply.NewXFDeCorrelateApply(), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.