diff --git a/go/vt/vtgate/planbuilder/show.go b/go/vt/vtgate/planbuilder/show.go index 452e143c958..8333844478c 100644 --- a/go/vt/vtgate/planbuilder/show.go +++ b/go/vt/vtgate/planbuilder/show.go @@ -180,10 +180,10 @@ func buildDBPlan(show *sqlparser.ShowBasic, vschema ContextVSchema) (engine.Prim 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")) + ks = append(ks, &vindexes.Keyspace{Name: "information_schema"}, + &vindexes.Keyspace{Name: "mysql"}, + &vindexes.Keyspace{Name: "sys"}, + &vindexes.Keyspace{Name: "performance_schema"}) } for _, v := range ks { diff --git a/go/vt/vtgate/planbuilder/show_test.go b/go/vt/vtgate/planbuilder/show_test.go index fc614d70262..7561d6e94e2 100644 --- a/go/vt/vtgate/planbuilder/show_test.go +++ b/go/vt/vtgate/planbuilder/show_test.go @@ -17,14 +17,48 @@ limitations under the License. package planbuilder import ( + "fmt" "testing" "github.com/stretchr/testify/require" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/sqlparser" + "vitess.io/vitess/go/vt/vtgate/vindexes" ) +func TestBuildDBPlan(t *testing.T) { + vschema := &vschemaWrapper{ + keyspace: &vindexes.Keyspace{Name: "main"}, + } + + testCases := []struct { + query string + expected string + }{{ + query: "show databases like 'main'", + expected: `[[VARCHAR("main")]]`, + }, { + query: "show databases like '%ys%'", + expected: `[[VARCHAR("mysql")] [VARCHAR("sys")]]`, + }} + + for _, s := range testCases { + t.Run(s.query, func(t *testing.T) { + parserOut, err := sqlparser.Parse(s.query) + require.NoError(t, err) + + show := parserOut.(*sqlparser.Show) + primitive, err := buildDBPlan(show.Internal.(*sqlparser.ShowBasic), vschema) + require.NoError(t, err) + + result, err := primitive.Execute(nil, nil, false) + require.NoError(t, err) + require.Equal(t, s.expected, fmt.Sprintf("%v", result.Rows)) + }) + } +} + func TestGenerateCharsetRows(t *testing.T) { rows := make([][]sqltypes.Value, 0, 4) rows0 := [][]sqltypes.Value{