Skip to content

Commit

Permalink
planner: move ShowPredicateExtractor interface to base package out of…
Browse files Browse the repository at this point in the history
… core (#52953)

ref #51664, ref #52714
  • Loading branch information
AilinKid committed May 6, 2024
1 parent 06ee59b commit 516977e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
3 changes: 2 additions & 1 deletion pkg/executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/pingcap/tidb/pkg/parser/tidb"
field_types "github.com/pingcap/tidb/pkg/parser/types"
plannercore "github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/plugin"
"github.com/pingcap/tidb/pkg/privilege"
"github.com/pingcap/tidb/pkg/privilege/privileges"
Expand Down Expand Up @@ -100,7 +101,7 @@ type ShowExec struct {
Flag int // Some flag parsed from sql, such as FULL.
Roles []*auth.RoleIdentity // Used for show grants.
User *auth.UserIdentity // Used by show grants, show create user.
Extractor plannercore.ShowPredicateExtractor
Extractor base.ShowPredicateExtractor

is infoschema.InfoSchema

Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/base/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ go_library(
"//pkg/planner/util/costusage",
"//pkg/planner/util/optimizetrace",
"//pkg/types",
"//pkg/util/collate",
"//pkg/util/execdetails",
"//pkg/util/tracing",
"@com_github_pingcap_tipb//go-tipb",
Expand Down
21 changes: 20 additions & 1 deletion pkg/planner/core/base/misc_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package base

import "github.com/pingcap/tipb/go-tipb"
import (
"github.com/pingcap/tidb/pkg/util/collate"
"github.com/pingcap/tipb/go-tipb"
)

// AccessObject represents what is accessed by an operator.
// It corresponds to the "access object" column in an EXPLAIN statement result.
Expand All @@ -24,3 +27,19 @@ type AccessObject interface {
// SetIntoPB transform itself into a protobuf message and set into the binary plan.
SetIntoPB(*tipb.ExplainOperator)
}

// ShowPredicateExtractor is used to extract some predicates from `PatternLikeOrIlikeExpr` clause
// and push the predicates down to the data retrieving on reading memory table stage when use ShowStmt.
//
// e.g:
// SHOW COLUMNS FROM t LIKE '%abc%'
// We must request all components from the memory table, and filter the result by the PatternLikeOrIlikeExpr predicate.
//
// it is a way to fix https://github.com/pingcap/tidb/issues/29910.
type ShowPredicateExtractor interface {
// Extract predicates which can be pushed down and returns whether the extractor can extract predicates.
Extract() bool
ExplainInfo() string
Field() string
FieldPatternLike() collate.WildcardPattern
}
2 changes: 1 addition & 1 deletion pkg/planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,7 @@ type LogicalShow struct {
logicalSchemaProducer
ShowContents

Extractor ShowPredicateExtractor
Extractor base.ShowPredicateExtractor
}

// LogicalShowDDLJobs is for showing DDL job list.
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2472,7 +2472,7 @@ type PhysicalShow struct {

ShowContents

Extractor ShowPredicateExtractor
Extractor base.ShowPredicateExtractor
}

// MemoryUsage return the memory usage of PhysicalShow
Expand Down
25 changes: 5 additions & 20 deletions pkg/planner/core/show_predicate_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/planner/core/base"
driver "github.com/pingcap/tidb/pkg/types/parser_driver"
"github.com/pingcap/tidb/pkg/util/collate"
"github.com/pingcap/tidb/pkg/util/stringutil"
Expand All @@ -35,25 +36,9 @@ const (
)

var (
_ ShowPredicateExtractor = &ShowBaseExtractor{}
_ base.ShowPredicateExtractor = &ShowBaseExtractor{}
)

// ShowPredicateExtractor is used to extract some predicates from `PatternLikeOrIlikeExpr` clause
// and push the predicates down to the data retrieving on reading memory table stage when use ShowStmt.
//
// e.g:
// SHOW COLUMNS FROM t LIKE '%abc%'
// We must request all components from the memory table, and filter the result by the PatternLikeOrIlikeExpr predicate.
//
// it is a way to fix https://github.com/pingcap/tidb/issues/29910.
type ShowPredicateExtractor interface {
// Extract predicates which can be pushed down and returns whether the extractor can extract predicates.
Extract() bool
explainInfo() string
Field() string
FieldPatternLike() collate.WildcardPattern
}

// ShowBaseExtractor is the definition of base extractor for derived predicates.
type ShowBaseExtractor struct {
ast.ShowStmt
Expand All @@ -63,7 +48,7 @@ type ShowBaseExtractor struct {
fieldPattern string
}

func newShowBaseExtractor(showStatement ast.ShowStmt) ShowPredicateExtractor {
func newShowBaseExtractor(showStatement ast.ShowStmt) base.ShowPredicateExtractor {
return &ShowBaseExtractor{ShowStmt: showStatement}
}

Expand Down Expand Up @@ -96,8 +81,8 @@ func (e *ShowBaseExtractor) Extract() bool {
return false
}

// explainInfo implements the ShowPredicateExtractor interface.
func (e *ShowBaseExtractor) explainInfo() string {
// ExplainInfo implements the base.ShowPredicateExtractor interface.
func (e *ShowBaseExtractor) ExplainInfo() string {
key := ""
switch e.ShowStmt.Tp {
case ast.ShowVariables, ast.ShowColumns:
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ func toString(in base.Plan, strs []string, idxs []int) ([]string, []int) {
case *LogicalShow:
str = "Show"
if pl := in.(*LogicalShow); pl.Extractor != nil {
str = str + "(" + pl.Extractor.explainInfo() + ")"
str = str + "(" + pl.Extractor.ExplainInfo() + ")"
}
case *PhysicalShow:
str = "Show"
if pl := in.(*PhysicalShow); pl.Extractor != nil {
str = str + "(" + pl.Extractor.explainInfo() + ")"
str = str + "(" + pl.Extractor.ExplainInfo() + ")"
}
case *LogicalShowDDLJobs, *PhysicalShowDDLJobs:
str = "ShowDDLJobs"
Expand Down

0 comments on commit 516977e

Please sign in to comment.