From 16d45399c8ad7f0898a82b267696dcd0a77a64dc Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 9 May 2024 10:20:52 +0200 Subject: [PATCH 1/2] fix: handle table_schema = '' without failing Signed-off-by: Andres Taylor --- .../informationschema/informationschema_test.go | 4 ++++ go/vt/vtgate/engine/routing.go | 13 ++++++------- 2 files changed, 10 insertions(+), 7 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/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 { From 21b9c35ca70eecf782d288bbf1aed257f5e7a379 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Thu, 9 May 2024 10:49:06 +0200 Subject: [PATCH 2/2] test: update expectations Signed-off-by: Andres Taylor --- go/vt/vtgate/engine/route_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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"},