diff --git a/pkg/executor/show.go b/pkg/executor/show.go index c119411b9c387..8bd86a2dacc75 100644 --- a/pkg/executor/show.go +++ b/pkg/executor/show.go @@ -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" @@ -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 diff --git a/pkg/planner/core/base/BUILD.bazel b/pkg/planner/core/base/BUILD.bazel index 162cb34897459..ffc2550f9b43a 100644 --- a/pkg/planner/core/base/BUILD.bazel +++ b/pkg/planner/core/base/BUILD.bazel @@ -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", diff --git a/pkg/planner/core/base/misc_base.go b/pkg/planner/core/base/misc_base.go index 82d20d5d74a58..7d59fe26e40ca 100644 --- a/pkg/planner/core/base/misc_base.go +++ b/pkg/planner/core/base/misc_base.go @@ -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. @@ -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 +} diff --git a/pkg/planner/core/logical_plans.go b/pkg/planner/core/logical_plans.go index b7512116812e4..f274ab3794eab 100644 --- a/pkg/planner/core/logical_plans.go +++ b/pkg/planner/core/logical_plans.go @@ -2228,7 +2228,7 @@ type LogicalShow struct { logicalSchemaProducer ShowContents - Extractor ShowPredicateExtractor + Extractor base.ShowPredicateExtractor } // LogicalShowDDLJobs is for showing DDL job list. diff --git a/pkg/planner/core/physical_plans.go b/pkg/planner/core/physical_plans.go index b83c33ccba9c7..f632490c299ee 100644 --- a/pkg/planner/core/physical_plans.go +++ b/pkg/planner/core/physical_plans.go @@ -2472,7 +2472,7 @@ type PhysicalShow struct { ShowContents - Extractor ShowPredicateExtractor + Extractor base.ShowPredicateExtractor } // MemoryUsage return the memory usage of PhysicalShow diff --git a/pkg/planner/core/show_predicate_extractor.go b/pkg/planner/core/show_predicate_extractor.go index f2695d525a1ae..bfd204553e223 100644 --- a/pkg/planner/core/show_predicate_extractor.go +++ b/pkg/planner/core/show_predicate_extractor.go @@ -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" @@ -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 @@ -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} } @@ -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: diff --git a/pkg/planner/core/stringer.go b/pkg/planner/core/stringer.go index e78c23e28c8c3..d9ba41360d035 100644 --- a/pkg/planner/core/stringer.go +++ b/pkg/planner/core/stringer.go @@ -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"