Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: move rule_collect_plan_stats into rules package #55282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go_library(
name = "core",
srcs = [
"access_object.go",
"collect_column_stats_usage.go",
"common_plans.go",
"core_init.go",
"debugtrace.go",
Expand Down Expand Up @@ -59,7 +58,6 @@ go_library(
"rule_aggregation_elimination.go",
"rule_aggregation_push_down.go",
"rule_aggregation_skew_rewrite.go",
"rule_collect_plan_stats.go",
"rule_column_pruning.go",
"rule_decorrelate.go",
"rule_derive_topn_from_window.go",
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/casetest/planstats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_test(
"//pkg/planner",
"//pkg/planner/core",
"//pkg/planner/core/base",
"//pkg/planner/core/rule",
"//pkg/sessionctx",
"//pkg/sessionctx/stmtctx",
"//pkg/statistics",
Expand Down
3 changes: 2 additions & 1 deletion pkg/planner/core/casetest/planstats/plan_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/pkg/planner"
plannercore "github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/planner/core/rule"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/stmtctx"
"github.com/pingcap/tidb/pkg/statistics"
Expand Down Expand Up @@ -392,7 +393,7 @@ func TestCollectDependingVirtualCols(t *testing.T) {
}

// call the function
res := plannercore.CollectDependingVirtualCols(tblID2Tbl, neededItems)
res := rule.CollectDependingVirtualCols(tblID2Tbl, neededItems)

// record and check the output
cols := make([]string, 0, len(res))
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/collect_column_stats_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func getStatsLoadItem(t *testing.T, is infoschema.InfoSchema, item model.StatsLo

func checkColumnStatsUsageForPredicates(t *testing.T, is infoschema.InfoSchema, lp base.LogicalPlan, expected []string, comment string) {
var tblColIDs []model.TableItemID
tblColIDs, _, _ = CollectColumnStatsUsage(lp, false)
tblColIDs, _, _ = rule.CollectColumnStatsUsage(lp, false)
cols := make([]string, 0, len(tblColIDs))
for _, tblColID := range tblColIDs {
col := getColumnName(t, is, tblColID, comment)
Expand All @@ -94,7 +94,7 @@ func checkColumnStatsUsageForPredicates(t *testing.T, is infoschema.InfoSchema,

func checkColumnStatsUsageForStatsLoad(t *testing.T, is infoschema.InfoSchema, lp base.LogicalPlan, expected []string, comment string) {
var loadItems []model.StatsLoadItem
_, loadItems, _ = CollectColumnStatsUsage(lp, true)
_, loadItems, _ = rule.CollectColumnStatsUsage(lp, true)
cols := make([]string, 0, len(loadItems))
for _, item := range loadItems {
col := getStatsLoadItem(t, is, item, comment)
Expand Down
10 changes: 10 additions & 0 deletions pkg/planner/core/operator/logicalop/logical_cte.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ func (cc *CTEClass) MemoryUsage() (sum int64) {
return
}

// SeedPartLogicalPlan is to get the seed part logical plan.
func (cc *CTEClass) SeedPartLogicalPlan() base.LogicalPlan {
return cc.seedPartLogicalPlan
}

// RecursivePartLogicalPlan is to get the recursive part logical plan.
func (cc *CTEClass) RecursivePartLogicalPlan() base.LogicalPlan {
return cc.recursivePartLogicalPlan
}

// *************************** start implementation of logicalPlan interface ***************************

// HashCode inherits the BaseLogicalPlan.<0th> implementation.
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ var optRuleList = []base.LogicalOptRule{
&PPDSolver{},
&OuterJoinEliminator{},
&PartitionProcessor{},
&CollectPredicateColumnsPoint{},
&rule.CollectPredicateColumnsPoint{},
&AggregationPushDownSolver{},
&DeriveTopNFromWindow{},
&PredicateSimplification{},
&PushDownTopNOptimizer{},
&SyncWaitStatsLoadPoint{},
&rule.SyncWaitStatsLoadPoint{},
&JoinReOrderSolver{},
&ColumnPruner{}, // column pruning again at last, note it will mess up the results of buildKeySolver
&PushDownSequenceSolver{},
Expand Down
17 changes: 17 additions & 0 deletions pkg/planner/core/rule/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,31 @@ go_library(
"logical_rules.go",
"rule_build_key_info.go",
"rule_constant_propagation.go",
"collect_column_stats_usage.go",
"rule_collect_plan_stats.go",
"rule_init.go",
],
importpath = "github.com/pingcap/tidb/pkg/planner/core/rule",
visibility = ["//visibility:public"],
deps = [
"//pkg/domain",
"//pkg/expression",
"//pkg/infoschema",
"//pkg/parser/model",
"//pkg/planner/core",
"//pkg/planner/core/base",
"//pkg/planner/core/operator/logicalop",
"//pkg/planner/core/rule/util",
"//pkg/planner/util/optimizetrace",
"//pkg/sessionctx/variable",
"//pkg/statistics",
"//pkg/statistics/asyncload",
"//pkg/table",
"//pkg/util/filter",
"//pkg/util/intset",
"//pkg/util/logutil",
"@com_github_pingcap_failpoint//:failpoint",
"@org_golang_x_exp//maps",
"@org_uber_go_zap//:zap",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package core
package rule

import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/domain"
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
Expand Down Expand Up @@ -124,7 +125,7 @@ func (c *columnStatsUsageCollector) updateColMapFromExpressions(col *expression.
c.updateColMap(col, expression.ExtractColumnsAndCorColumnsFromExpressions(c.cols[:0], list))
}

func (c *columnStatsUsageCollector) collectPredicateColumnsForDataSource(ds *DataSource) {
func (c *columnStatsUsageCollector) collectPredicateColumnsForDataSource(ds *core.DataSource) {
// Skip all system tables.
if filter.IsSystemSchema(ds.DBName.L) {
return
Expand Down Expand Up @@ -178,7 +179,7 @@ func (c *columnStatsUsageCollector) collectPredicateColumnsForUnionAll(p *logica
}
}

func (c *columnStatsUsageCollector) addHistNeededColumns(ds *DataSource) {
func (c *columnStatsUsageCollector) addHistNeededColumns(ds *core.DataSource) {
c.visitedPhysTblIDs.Insert(int(ds.PhysicalTableID))
if c.collectMode&collectHistNeededColumns == 0 {
return
Expand Down Expand Up @@ -232,12 +233,12 @@ func (c *columnStatsUsageCollector) collectFromPlan(lp base.LogicalPlan) {
}
if c.collectMode&collectPredicateColumns != 0 {
switch x := lp.(type) {
case *DataSource:
case *core.DataSource:
c.collectPredicateColumnsForDataSource(x)
case *LogicalIndexScan:
case *core.LogicalIndexScan:
c.collectPredicateColumnsForDataSource(x.Source)
c.addPredicateColumnsFromExpressions(x.AccessConds)
case *LogicalTableScan:
case *core.LogicalTableScan:
c.collectPredicateColumnsForDataSource(x.Source)
c.addPredicateColumnsFromExpressions(x.AccessConds)
case *logicalop.LogicalProjection:
Expand Down Expand Up @@ -336,11 +337,11 @@ func (c *columnStatsUsageCollector) collectFromPlan(lp base.LogicalPlan) {
// Since c.visitedPhysTblIDs is also collected here and needs to be collected even collectHistNeededColumns is not set,
// so we do the c.collectMode check in addHistNeededColumns() after collecting c.visitedPhysTblIDs.
switch x := lp.(type) {
case *DataSource:
case *core.DataSource:
c.addHistNeededColumns(x)
case *LogicalIndexScan:
case *core.LogicalIndexScan:
c.addHistNeededColumns(x.Source)
case *LogicalTableScan:
case *core.LogicalTableScan:
c.addHistNeededColumns(x.Source)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package core
package rule

import (
"context"
Expand Down