Skip to content

Commit

Permalink
fix: handle table_schema = '' without failing (vitessio#15901)
Browse files Browse the repository at this point in the history
  • Loading branch information
systay authored May 9, 2024
1 parent f3c34f5 commit f86f131
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func TestMultipleSchemaPredicates(t *testing.T) {
_, err := mcmp.VtConn.ExecuteFetch(query, 1000, true)
require.Error(t, err)
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")

if utils.BinaryIsAtLeastAtVersion(20, "vtgate") {
_, _ = mcmp.ExecNoCompare("select * from information_schema.columns where table_schema = '' limit 1")
}
}

func TestInfrSchemaAndUnionAll(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/engine/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ func TestInformationSchemaWithTableAndSchemaWithRoutedTables(t *testing.T) {
expectedLog: []string{
"FindTable(tableName)",
"ResolveDestinations routedKeyspace [] Destinations:DestinationAnyShard()",
"ExecuteMultiShard routedKeyspace.1: dummy_select {table_name: type:VARCHAR value:\"routedTable\"} false false"},
"ExecuteMultiShard routedKeyspace.1: dummy_select {__vtschemaname: type:VARCHAR table_name: type:VARCHAR value:\"routedTable\"} false false"},
}, {
testName: "table name predicate - not routed",
tableName: map[string]evalengine.Expr{"table_name": evalengine.NewLiteralString([]byte("tableName"), collations.SystemCollation)},
routed: false,
expectedLog: []string{
"FindTable(tableName)",
"ResolveDestinations ks [] Destinations:DestinationAnyShard()",
"ExecuteMultiShard ks.1: dummy_select {table_name: type:VARCHAR value:\"tableName\"} false false"},
"ExecuteMultiShard ks.1: dummy_select {__vtschemaname: type:VARCHAR table_name: type:VARCHAR value:\"tableName\"} false false"},
}, {
testName: "schema predicate",
tableSchema: []string{"myKeyspace"},
Expand Down
13 changes: 6 additions & 7 deletions go/vt/vtgate/engine/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,21 @@ func (rp *RoutingParameters) routeInfoSchemaQuery(ctx context.Context, vcursor V

env := evalengine.NewExpressionEnv(ctx, bindVars, vcursor)
var specifiedKS string
for _, tableSchema := range rp.SysTableTableSchema {
for idx, tableSchema := range rp.SysTableTableSchema {
result, err := env.Evaluate(tableSchema)
if err != nil {
return nil, err
}
ks := result.Value(vcursor.ConnCollation()).ToString()
if specifiedKS == "" {
switch {
case idx == 0:
specifiedKS = ks
}
if specifiedKS != ks {
case specifiedKS != ks:
return nil, vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "specifying two different database in the query is not supported")
}
}
if specifiedKS != "" {
bindVars[sqltypes.BvSchemaName] = sqltypes.StringBindVariable(specifiedKS)
}

bindVars[sqltypes.BvSchemaName] = sqltypes.StringBindVariable(specifiedKS)

tableNames := map[string]string{}
for tblBvName, sysTableName := range rp.SysTableTableName {
Expand Down

0 comments on commit f86f131

Please sign in to comment.