Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: fix the missing Grantor when querying mysql.tables_priv #38461

Merged
merged 7 commits into from
Oct 20, 2022
1 change: 1 addition & 0 deletions executor/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (e *GrantExec) Next(ctx context.Context, req *chunk.Chunk) error {
// Create internal session to start internal transaction.
isCommit := false
internalSession, err := e.getSysSession()
internalSession.GetSessionVars().User = e.ctx.GetSessionVars().User
if err != nil {
return err
}
Expand Down
13 changes: 13 additions & 0 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,16 @@ func TestIssue34610(t *testing.T) {
tk.MustExec("GRANT SELECT ON T1 to user_1@localhost;")
tk.MustExec("GRANT SELECT ON t1 to user_1@localhost;")
}

func TestIssue38293(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.Session().GetSessionVars().User = &auth.UserIdentity{Username: "root", Hostname: "localhost"}
tk.MustExec("DROP USER IF EXISTS test")
tk.MustExec("CREATE USER test")
defer func() {
tk.MustExec("DROP USER test")
}()
tk.MustExec("GRANT SELECT ON `mysql`.`db` TO test")
tk.MustQuery("SELECT `Grantor` FROM `mysql`.`tables_priv` WHERE User = 'test'").Check(testkit.Rows("root@localhost"))
}