-
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: classify logical optimizing rule interface and files. (#55226)
- Loading branch information
Showing
36 changed files
with
415 additions
and
254 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// 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 base | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/tidb/pkg/planner/util/optimizetrace" | ||
) | ||
|
||
// LogicalOptRule means a logical optimizing rule, which contains de-correlate, ppd, column pruning, etc. | ||
type LogicalOptRule interface { | ||
// Optimize return parameters: | ||
// 1. base.LogicalPlan: The optimized base.LogicalPlan after rule is applied | ||
// 2. bool: Used to judge whether the plan is changed or not by logical rule. | ||
// If the plan is changed, it will return true. | ||
// The default value is false. It means that no interaction rule will be triggered. | ||
// 3. error: If there is error during the rule optimizer, it will be thrown | ||
Optimize(context.Context, LogicalPlan, *optimizetrace.LogicalOptimizeOp) (LogicalPlan, bool, error) | ||
Name() string | ||
} |
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
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,17 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "rule", | ||
srcs = [ | ||
"rule_build_key_info.go", | ||
"rule_init.go", | ||
], | ||
importpath = "github.com/pingcap/tidb/pkg/planner/core/rule", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/expression", | ||
"//pkg/planner/core/base", | ||
"//pkg/planner/core/rule/util", | ||
"//pkg/planner/util/optimizetrace", | ||
], | ||
) |
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,54 @@ | ||
// 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 rule | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/tidb/pkg/expression" | ||
"github.com/pingcap/tidb/pkg/planner/core/base" | ||
"github.com/pingcap/tidb/pkg/planner/util/optimizetrace" | ||
) | ||
|
||
// BuildKeySolver is used to build key info for logical plan. | ||
type BuildKeySolver struct{} | ||
|
||
// *************************** start implementation of LogicalOptRule interface *************************** | ||
|
||
// Name implements base.LogicalOptRule.<0th> interface. | ||
func (*BuildKeySolver) Name() string { | ||
return "build_keys" | ||
} | ||
|
||
// Optimize implements base.LogicalOptRule.<1st> interface. | ||
func (*BuildKeySolver) Optimize(_ context.Context, p base.LogicalPlan, _ *optimizetrace.LogicalOptimizeOp) (base.LogicalPlan, bool, error) { | ||
planChanged := false | ||
buildKeyInfo(p) | ||
return p, planChanged, nil | ||
} | ||
|
||
// **************************** end implementation of LogicalOptRule interface **************************** | ||
|
||
// buildKeyInfo recursively calls base.LogicalPlan's BuildKeyInfo method. | ||
func buildKeyInfo(lp base.LogicalPlan) { | ||
for _, child := range lp.Children() { | ||
buildKeyInfo(child) | ||
} | ||
childSchema := make([]*expression.Schema, len(lp.Children())) | ||
for i, child := range lp.Children() { | ||
childSchema[i] = child.Schema() | ||
} | ||
lp.BuildKeyInfo(lp.Schema(), childSchema) | ||
} |
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,26 @@ | ||
// 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 rule | ||
|
||
import "github.com/pingcap/tidb/pkg/planner/core/rule/util" | ||
|
||
// rule/pkg should rely on operator/pkg to do type check and dig in and out, | ||
// rule/util doesn't have to rely on rule/pkg, but it can be put with rule | ||
// handling logic, and be referenced by operator/pkg. | ||
// the core usage only care and call about the rule/pkg and operator/pkg. | ||
|
||
func init() { | ||
util.BuildKeyInfoPortal = buildKeyInfo | ||
} |
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.