Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle table_schema = '' without failing #15901

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading