From f86f13162c0e0aaa29691935ff34e4b9f38a51a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Taylor?= Date: Thu, 9 May 2024 12:41:41 +0200 Subject: [PATCH] fix: handle table_schema = '' without failing (#15901) --- .../informationschema/informationschema_test.go | 4 ++++ go/vt/vtgate/engine/route_test.go | 4 ++-- go/vt/vtgate/engine/routing.go | 13 ++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go b/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go index 887eefc7747..ec55711a31f 100644 --- a/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go +++ b/go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go @@ -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) { diff --git a/go/vt/vtgate/engine/route_test.go b/go/vt/vtgate/engine/route_test.go index 7120ba53172..b2f4020cb59 100644 --- a/go/vt/vtgate/engine/route_test.go +++ b/go/vt/vtgate/engine/route_test.go @@ -130,7 +130,7 @@ 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)}, @@ -138,7 +138,7 @@ func TestInformationSchemaWithTableAndSchemaWithRoutedTables(t *testing.T) { 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"}, diff --git a/go/vt/vtgate/engine/routing.go b/go/vt/vtgate/engine/routing.go index a4f6dabde20..e05366c4aeb 100644 --- a/go/vt/vtgate/engine/routing.go +++ b/go/vt/vtgate/engine/routing.go @@ -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 {