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 cf8039e commit 9dce594
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 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
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/onecase.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"comment": "Add your test case here for debugging and run go test -run=One.",
"query": "",
"query": "select table_schema, table_name, ordinal_position from information_schema.columns where table_schema = '' limit 1",
"plan": {

}
Expand Down

0 comments on commit 9dce594

Please sign in to comment.