added default database in 'show database'

Signed-off-by: akilan <Akilanselva@hotmail.com>
This commit is contained in:
akilan 2021-01-07 13:24:43 +04:00 коммит произвёл Akilan
Родитель d9ebaa3359
Коммит ebbf34efa4
7 изменённых файлов: 31 добавлений и 9 удалений

Просмотреть файл

@ -1243,6 +1243,8 @@ func (ty ShowCommandType) ToString() string {
return VariableGlobalStr
case VariableSession:
return VariableSessionStr
case Keyspace:
return KeyspaceStr
default:
return "Unknown ShowCommandType"
}

Просмотреть файл

@ -219,6 +219,7 @@ const (
StatusSessionStr = " status"
VariableGlobalStr = " global variables"
VariableSessionStr = " variables"
KeyspaceStr = " keyspaces"
// DropKeyType strings
PrimaryKeyTypeStr = "primary key"
@ -458,6 +459,7 @@ const (
StatusSession
VariableGlobal
VariableSession
Keyspace
)
// DropKeyType constants

Просмотреть файл

@ -1479,10 +1479,10 @@ var (
output: "show variables",
}, {
input: "show vitess_keyspaces",
output: "show databases",
output: "show keyspaces",
}, {
input: "show vitess_keyspaces like '%'",
output: "show databases like '%'",
output: "show keyspaces like '%'",
}, {
input: "show vitess_shards",
}, {

Просмотреть файл

@ -7753,13 +7753,13 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line sql.y:2346
{
yyVAL.statement = &Show{&ShowBasic{Command: Database, Filter: yyDollar[3].showFilter}}
yyVAL.statement = &Show{&ShowBasic{Command: Keyspace, Filter: yyDollar[3].showFilter}}
}
case 429:
yyDollar = yyS[yypt-3 : yypt+1]
//line sql.y:2350
{
yyVAL.statement = &Show{&ShowBasic{Command: Database, Filter: yyDollar[3].showFilter}}
yyVAL.statement = &Show{&ShowBasic{Command: Keyspace, Filter: yyDollar[3].showFilter}}
}
case 430:
yyDollar = yyS[yypt-4 : yypt+1]

Просмотреть файл

@ -2344,11 +2344,11 @@ show_statement:
}
| SHOW KEYSPACES like_or_where_opt
{
$$ = &Show{&ShowBasic{Command: Database, Filter: $3}}
$$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}}
}
| SHOW VITESS_KEYSPACES like_or_where_opt
{
$$ = &Show{&ShowBasic{Command: Database, Filter: $3}}
$$ = &Show{&ShowBasic{Command: Keyspace, Filter: $3}}
}
| SHOW FUNCTION STATUS like_or_where_opt
{

Просмотреть файл

@ -437,11 +437,19 @@ func TestExecutorShow(t *testing.T) {
executor, _, _, sbclookup := createLegacyExecutorEnv()
session := NewSafeSession(&vtgatepb.Session{TargetString: "@master"})
for _, query := range []string{"show databases", "show vitess_keyspaces", "show keyspaces", "show DATABASES", "show schemas", "show SCHEMAS"} {
for _, query := range []string{"show vitess_keyspaces", "show keyspaces"} {
qr, err := executor.Execute(ctx, "TestExecute", session, query, nil)
require.NoError(t, err)
require.EqualValues(t, 5, qr.RowsAffected, fmt.Sprintf("unexpected results running query: %s", query))
}
for _, query := range []string{"show databases", "show DATABASES", "show schemas", "show SCHEMAS"} {
qr, err := executor.Execute(ctx, "TestExecute", session, query, nil)
require.NoError(t, err)
// Showing default tables (5+4[default])
require.EqualValues(t, 9, qr.RowsAffected, fmt.Sprintf("unexpected results running query: %s", query))
}
_, err := executor.Execute(ctx, "TestExecute", session, "show variables", nil)
require.NoError(t, err)
_, err = executor.Execute(ctx, "TestExecute", session, "show collation", nil)

Просмотреть файл

@ -57,7 +57,7 @@ func buildShowBasicPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engi
case sqlparser.Collation, sqlparser.Function, sqlparser.Privilege, sqlparser.Procedure,
sqlparser.VariableGlobal, sqlparser.VariableSession:
return showSendAnywhere(show, vschema)
case sqlparser.Database:
case sqlparser.Database, sqlparser.Keyspace:
ks, err := vschema.AllKeyspace()
if err != nil {
return nil, err
@ -73,7 +73,17 @@ func buildShowBasicPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engi
filter = regexp.MustCompile(".*")
}
rows := make([][]sqltypes.Value, 0, len(ks))
//rows := make([][]sqltypes.Value, 0, len(ks)+4)
var rows [][]sqltypes.Value
if show.Command == sqlparser.Database {
//Hard code default databases
rows = append(rows, buildVarCharRow("information_schema"))
rows = append(rows, buildVarCharRow("mysql"))
rows = append(rows, buildVarCharRow("sys"))
rows = append(rows, buildVarCharRow("performance_schema"))
}
for _, v := range ks {
if filter.MatchString(v.Name) {
rows = append(rows, buildVarCharRow(v.Name))