Skip to content

Commit

Permalink
fix: show tables to use any keyspace on system schema (#16521)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal authored Aug 1, 2024
1 parent 498450f commit d122ac6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,13 @@ func TestShowTables(t *testing.T) {
conn, closer := start(t)
defer closer()

query := "show tables;"
qr := utils.Exec(t, conn, query)

qr := utils.Exec(t, conn, "show tables")
assert.Equal(t, "Tables_in_ks", qr.Fields[0].Name)

// no error on executing `show tables` on system schema
utils.Exec(t, conn, `use mysql`)
utils.Exec(t, conn, "show tables")
utils.Exec(t, conn, "show tables from information_schema")
}

func TestCastConvert(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions go/vt/vtgate/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,15 @@ func TestExecutorShowTargeted(t *testing.T) {
}
}

func TestExecutorShowFromSystemSchema(t *testing.T) {
executor, _, _, _, ctx := createExecutorEnv(t)

session := NewSafeSession(&vtgatepb.Session{TargetString: "mysql"})

_, err := executor.Execute(ctx, nil, "TestExecutorShowFromSystemSchema", session, "show tables", nil)
require.NoError(t, err)
}

func TestExecutorUse(t *testing.T) {
executor, _, _, _, ctx := createExecutorEnv(t)

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ func commentedShardQueries(shardQueries []*querypb.BoundQuery, marginComments sq

// TargetDestination implements the ContextVSchema interface
func (vc *vcursorImpl) TargetDestination(qualifier string) (key.Destination, *vindexes.Keyspace, topodatapb.TabletType, error) {
keyspaceName := vc.keyspace
keyspaceName := vc.getActualKeyspace()
if vc.destination == nil && qualifier != "" {
keyspaceName = qualifier
}
Expand Down

0 comments on commit d122ac6

Please sign in to comment.