Skip to content

Commit

Permalink
fix: handle table_schema = '' without failing
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay committed May 9, 2024
1 parent cbf89bd commit 16d4539
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 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
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 16d4539

Please sign in to comment.