diff --git a/executor/show.go b/executor/show.go index 1006ace9c4020..2271ee1188efe 100644 --- a/executor/show.go +++ b/executor/show.go @@ -1468,17 +1468,11 @@ func (e *ShowExec) fetchShowCreatePlacementPolicy() error { func (e *ShowExec) fetchShowCollation() error { var ( fieldPatternsLike collate.WildcardPattern - FieldFilterEnable bool fieldFilter string ) if e.Extractor != nil { - extractor := (e.Extractor).(*plannercore.ShowCollationExtractor) - if extractor.FieldPatterns != "" { - fieldPatternsLike = collate.GetCollatorByID(collate.CollationName2ID(mysql.UTF8MB4DefaultCollation)).Pattern() - fieldPatternsLike.Compile(extractor.FieldPatterns, byte('\\')) - } - FieldFilterEnable = extractor.Field != "" - fieldFilter = extractor.Field + fieldPatternsLike = e.Extractor.FieldPatternLike() + fieldFilter = e.Extractor.Field() } collations := collate.GetSupportedCollations() @@ -1487,7 +1481,7 @@ func (e *ShowExec) fetchShowCollation() error { if v.IsDefault { isDefault = "Yes" } - if FieldFilterEnable && strings.ToLower(v.Name) != fieldFilter { + if fieldFilter != "" && strings.ToLower(v.Name) != fieldFilter { continue } else if fieldPatternsLike != nil && !fieldPatternsLike.DoMatch(v.Name) { continue diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 3af2fc451c918..7a11f48fa5812 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -2933,7 +2933,7 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan, isSequence := false switch show.Tp { - case ast.ShowDatabases, ast.ShowVariables, ast.ShowTables, ast.ShowColumns, ast.ShowTableStatus: + case ast.ShowDatabases, ast.ShowVariables, ast.ShowTables, ast.ShowColumns, ast.ShowTableStatus, ast.ShowCollation: if (show.Tp == ast.ShowTables || show.Tp == ast.ShowTableStatus) && p.DBName == "" { return nil, ErrNoDB } diff --git a/planner/core/show_predicate_extractor.go b/planner/core/show_predicate_extractor.go index fedb40aaf951b..f5742e9f34dbe 100644 --- a/planner/core/show_predicate_extractor.go +++ b/planner/core/show_predicate_extractor.go @@ -27,9 +27,10 @@ import ( ) const ( - fieldKey = "field" - tableKey = "table" - databaseKey = "database" + fieldKey = "field" + tableKey = "table" + databaseKey = "database" + collationKey = "collation" ) var ( @@ -104,6 +105,8 @@ func (e *ShowBaseExtractor) explainInfo() string { key = tableKey case ast.ShowDatabases: key = databaseKey + case ast.ShowCollation: + key = collationKey } r := new(bytes.Buffer) @@ -137,25 +140,3 @@ func (e *ShowBaseExtractor) FieldPatternLike() collate.WildcardPattern { fieldPatternsLike.Compile(e.fieldPattern, byte('\\')) return fieldPatternsLike } - -// ShowCollationExtractor is used to extract some predicates of collations. -type ShowCollationExtractor struct { - ShowBaseExtractor -} - -func (e *ShowCollationExtractor) explainInfo() string { - r := new(bytes.Buffer) - if len(e.Field) > 0 { - r.WriteString(fmt.Sprintf("collation:[%s], ", e.Field)) - } - if len(e.FieldPatterns) > 0 { - r.WriteString(fmt.Sprintf("collation_pattern:[%s], ", e.FieldPatterns)) - } - - // remove the last ", " in the message info - s := r.String() - if len(s) > 2 { - return s[:len(s)-2] - } - return s -}