Skip to content

Commit f86f131

Browse files
authored
fix: handle table_schema = '' without failing (#15901)
1 parent f3c34f5 commit f86f131

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

go/test/endtoend/vtgate/queries/informationschema/informationschema_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ func TestMultipleSchemaPredicates(t *testing.T) {
201201
_, err := mcmp.VtConn.ExecuteFetch(query, 1000, true)
202202
require.Error(t, err)
203203
require.Contains(t, err.Error(), "specifying two different database in the query is not supported")
204+
205+
if utils.BinaryIsAtLeastAtVersion(20, "vtgate") {
206+
_, _ = mcmp.ExecNoCompare("select * from information_schema.columns where table_schema = '' limit 1")
207+
}
204208
}
205209

206210
func TestInfrSchemaAndUnionAll(t *testing.T) {

go/vt/vtgate/engine/route_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ func TestInformationSchemaWithTableAndSchemaWithRoutedTables(t *testing.T) {
130130
expectedLog: []string{
131131
"FindTable(tableName)",
132132
"ResolveDestinations routedKeyspace [] Destinations:DestinationAnyShard()",
133-
"ExecuteMultiShard routedKeyspace.1: dummy_select {table_name: type:VARCHAR value:\"routedTable\"} false false"},
133+
"ExecuteMultiShard routedKeyspace.1: dummy_select {__vtschemaname: type:VARCHAR table_name: type:VARCHAR value:\"routedTable\"} false false"},
134134
}, {
135135
testName: "table name predicate - not routed",
136136
tableName: map[string]evalengine.Expr{"table_name": evalengine.NewLiteralString([]byte("tableName"), collations.SystemCollation)},
137137
routed: false,
138138
expectedLog: []string{
139139
"FindTable(tableName)",
140140
"ResolveDestinations ks [] Destinations:DestinationAnyShard()",
141-
"ExecuteMultiShard ks.1: dummy_select {table_name: type:VARCHAR value:\"tableName\"} false false"},
141+
"ExecuteMultiShard ks.1: dummy_select {__vtschemaname: type:VARCHAR table_name: type:VARCHAR value:\"tableName\"} false false"},
142142
}, {
143143
testName: "schema predicate",
144144
tableSchema: []string{"myKeyspace"},

go/vt/vtgate/engine/routing.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,22 +192,21 @@ func (rp *RoutingParameters) routeInfoSchemaQuery(ctx context.Context, vcursor V
192192

193193
env := evalengine.NewExpressionEnv(ctx, bindVars, vcursor)
194194
var specifiedKS string
195-
for _, tableSchema := range rp.SysTableTableSchema {
195+
for idx, tableSchema := range rp.SysTableTableSchema {
196196
result, err := env.Evaluate(tableSchema)
197197
if err != nil {
198198
return nil, err
199199
}
200200
ks := result.Value(vcursor.ConnCollation()).ToString()
201-
if specifiedKS == "" {
201+
switch {
202+
case idx == 0:
202203
specifiedKS = ks
203-
}
204-
if specifiedKS != ks {
204+
case specifiedKS != ks:
205205
return nil, vterrors.Errorf(vtrpcpb.Code_UNIMPLEMENTED, "specifying two different database in the query is not supported")
206206
}
207207
}
208-
if specifiedKS != "" {
209-
bindVars[sqltypes.BvSchemaName] = sqltypes.StringBindVariable(specifiedKS)
210-
}
208+
209+
bindVars[sqltypes.BvSchemaName] = sqltypes.StringBindVariable(specifiedKS)
211210

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

0 commit comments

Comments
 (0)