Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#38370
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
dveeden authored and ti-chi-bot committed Oct 11, 2022
1 parent ef7771e commit 76f366b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
15 changes: 15 additions & 0 deletions executor/revoke.go
Expand Up @@ -236,7 +236,22 @@ func (e *RevokeExec) revokeDBPriv(internalSession sessionctx.Context, priv *ast.
}
sqlexec.MustFormatSQL(sql, " WHERE User=%? AND Host=%? AND DB=%?", userName, host, dbName)

<<<<<<< HEAD
_, err = internalSession.(sqlexec.SQLExecutor).ExecuteInternal(context.Background(), sql.String())
=======
_, err = internalSession.(sqlexec.SQLExecutor).ExecuteInternal(ctx, sql.String())
if err != nil {
return err
}

sql = new(strings.Builder)
sqlexec.MustFormatSQL(sql, "DELETE FROM %n.%n WHERE User=%? AND Host=%? AND DB=%?", mysql.SystemDB, mysql.DBTable, userName, host, dbName)

for _, v := range append(mysql.AllDBPrivs, mysql.GrantPriv) {
sqlexec.MustFormatSQL(sql, " AND %n='N'", v.ColumnString())
}
_, err = internalSession.(sqlexec.SQLExecutor).ExecuteInternal(ctx, sql.String())
>>>>>>> 8c9f5cfb0c (executor: cleanup entries from mysql.db on revoke (#38370))
return err
}

Expand Down
8 changes: 7 additions & 1 deletion executor/revoke_test.go
Expand Up @@ -69,7 +69,13 @@ func (s *testSuite1) TestRevokeDBScope(c *C) {

tk.MustQuery(check).Check(testkit.Rows("Y"))
tk.MustExec(sql)
tk.MustQuery(check).Check(testkit.Rows("N"))
if v == mysql.AllDBPrivs[len(mysql.AllDBPrivs)-1] {
// When all privileges are set to 'N', then the record should be removed as well.
// https://github.com/pingcap/tidb/issues/38363
tk.MustQuery(check).Check(testkit.Rows())
} else {
tk.MustQuery(check).Check(testkit.Rows("N"))
}
}
}

Expand Down

0 comments on commit 76f366b

Please sign in to comment.