From 0d304f3ecd802845ee7a3383d368def60232ecad Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Thu, 1 Aug 2024 13:19:42 +0530 Subject: [PATCH] fix: show tables to use any keyspace on system schema Signed-off-by: Harshit Gangal --- go/test/endtoend/vtgate/misc_test.go | 9 ++++++--- go/vt/vtgate/executor_test.go | 9 +++++++++ go/vt/vtgate/vcursor_impl.go | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/go/test/endtoend/vtgate/misc_test.go b/go/test/endtoend/vtgate/misc_test.go index 128d930718c..bcb4f68a935 100644 --- a/go/test/endtoend/vtgate/misc_test.go +++ b/go/test/endtoend/vtgate/misc_test.go @@ -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) { diff --git a/go/vt/vtgate/executor_test.go b/go/vt/vtgate/executor_test.go index cce717674d6..b8e2b996780 100644 --- a/go/vt/vtgate/executor_test.go +++ b/go/vt/vtgate/executor_test.go @@ -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) diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index ae9c073e123..ee000abed8f 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -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 }