Skip to content

Commit

Permalink
executor: fix the missing Grantor when querying mysql.`tables_pri…
Browse files Browse the repository at this point in the history
…v` (#38461) (#38560)

close #38293
  • Loading branch information
ti-chi-bot authored Oct 31, 2022
1 parent 7228bb3 commit 31f5579
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions executor/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,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
14 changes: 14 additions & 0 deletions executor/grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,3 +615,17 @@ func TestGrantDynamicPrivs(t *testing.T) {
tk.MustQuery("SELECT Grant_Priv FROM mysql.user WHERE `Host` = '%' AND `User` = 'dyn'").Check(testkit.Rows("Y"))
tk.MustQuery("SELECT WITH_GRANT_OPTION FROM mysql.global_grants WHERE `Host` = '%' AND `User` = 'dyn' AND Priv='CONNECTION_ADMIN'").Check(testkit.Rows("Y"))
}

func TestIssue38293(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
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"))
}

0 comments on commit 31f5579

Please sign in to comment.