ddl: make output field name in show tables/databases stmt compatible with mysql (#35136)
close pingcap/tidb#35116
This commit is contained in:
4
cmd/explaintest/r/show.result
Normal file
4
cmd/explaintest/r/show.result
Normal file
@ -0,0 +1,4 @@
|
||||
show tables like '%xx';
|
||||
Tables_in_test (%xx)
|
||||
show databases like '%xx';
|
||||
Database (%xx)
|
||||
3
cmd/explaintest/t/show.test
Normal file
3
cmd/explaintest/t/show.test
Normal file
@ -0,0 +1,3 @@
|
||||
# test show output field name
|
||||
show tables like '%xx';
|
||||
show databases like '%xx';
|
||||
@ -2933,17 +2933,17 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan,
|
||||
}.Init(b.ctx)
|
||||
isView := false
|
||||
isSequence := false
|
||||
// It depends on ShowPredicateExtractor now
|
||||
buildPattern := true
|
||||
|
||||
switch show.Tp {
|
||||
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
|
||||
}
|
||||
extractor := newShowBaseExtractor(*show)
|
||||
if extractor.Extract() {
|
||||
if extractor := newShowBaseExtractor(*show); extractor.Extract() {
|
||||
p.Extractor = extractor
|
||||
// Avoid building Selection.
|
||||
show.Pattern = nil
|
||||
buildPattern = false
|
||||
}
|
||||
case ast.ShowCreateTable, ast.ShowCreateSequence, ast.ShowPlacementForTable, ast.ShowPlacementForPartition:
|
||||
var err error
|
||||
@ -3019,7 +3019,8 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan,
|
||||
var err error
|
||||
var np LogicalPlan
|
||||
np = p
|
||||
if show.Pattern != nil {
|
||||
// If we have ShowPredicateExtractor, we do not buildSelection with Pattern
|
||||
if show.Pattern != nil && buildPattern {
|
||||
show.Pattern.Expr = &ast.ColumnNameExpr{
|
||||
Name: &ast.ColumnName{Name: p.OutputNames()[0].ColName},
|
||||
}
|
||||
@ -4645,12 +4646,20 @@ func buildShowSchema(s *ast.ShowStmt, isView bool, isSequence bool) (schema *exp
|
||||
case ast.ShowConfig:
|
||||
names = []string{"Type", "Instance", "Name", "Value"}
|
||||
case ast.ShowDatabases:
|
||||
names = []string{"Database"}
|
||||
fieldDB := "Database"
|
||||
if patternName := extractPatternLikeName(s.Pattern); patternName != "" {
|
||||
fieldDB = fmt.Sprintf("%s (%s)", fieldDB, patternName)
|
||||
}
|
||||
names = []string{fieldDB}
|
||||
case ast.ShowOpenTables:
|
||||
names = []string{"Database", "Table", "In_use", "Name_locked"}
|
||||
ftypes = []byte{mysql.TypeVarchar, mysql.TypeVarchar, mysql.TypeLong, mysql.TypeLong}
|
||||
case ast.ShowTables:
|
||||
names = []string{fmt.Sprintf("Tables_in_%s", s.DBName)}
|
||||
fieldTable := fmt.Sprintf("Tables_in_%s", s.DBName)
|
||||
if patternName := extractPatternLikeName(s.Pattern); patternName != "" {
|
||||
fieldTable = fmt.Sprintf("%s (%s)", fieldTable, patternName)
|
||||
}
|
||||
names = []string{fieldTable}
|
||||
if s.Full {
|
||||
names = append(names, "Table_type")
|
||||
}
|
||||
@ -4870,3 +4879,14 @@ func (b *PlanBuilder) buildCompactTable(node *ast.CompactTableStmt) (Plan, error
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func extractPatternLikeName(patternLike *ast.PatternLikeExpr) string {
|
||||
if patternLike == nil {
|
||||
return ""
|
||||
}
|
||||
switch v := patternLike.Pattern.(type) {
|
||||
case *driver.ValueExpr:
|
||||
return v.GetString()
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user