parser: use identifier as user's resource group name (#40479)
* parser: use identifier as user's resource group name and also fix a drop resource group bug Signed-off-by: BornChanger <dawn_catcher@126.com> * executor: fix case Signed-off-by: BornChanger <dawn_catcher@126.com> * *: format parser.y Signed-off-by: BornChanger <dawn_catcher@126.com> * *: fix store function of resource group Signed-off-by: BornChanger <dawn_catcher@126.com> Signed-off-by: BornChanger <dawn_catcher@126.com> Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
This commit is contained in:
@ -128,6 +128,6 @@ func TestUserAttributes(t *testing.T) {
|
||||
rootTK.MustExec("create user usr1@'%' identified by 'passord'")
|
||||
rootTK.MustExec("alter user usr1 comment 'comment1'")
|
||||
rootTK.MustQuery("select user_attributes from mysql.user where user = 'usr1'").Check(testkit.Rows(`{"metadata": {"comment": "comment1"}, "resource_group": "default"}`))
|
||||
rootTK.MustExec("alter user usr1 resource group 'rg1'")
|
||||
rootTK.MustExec("alter user usr1 resource group rg1")
|
||||
rootTK.MustQuery("select user_attributes from mysql.user where user = 'usr1'").Check(testkit.Rows(`{"metadata": {"comment": "comment1"}, "resource_group": "rg1"}`))
|
||||
}
|
||||
|
||||
@ -1591,7 +1591,7 @@ type ResourceGroupNameOption struct {
|
||||
func (c *ResourceGroupNameOption) Restore(ctx *format.RestoreCtx) error {
|
||||
if c.Type == UserResourceGroupName {
|
||||
ctx.WriteKeyWord(" RESOURCE GROUP ")
|
||||
ctx.WriteString(c.Value)
|
||||
ctx.WriteName(c.Value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
14684
parser/parser.go
14684
parser/parser.go
File diff suppressed because it is too large
Load Diff
@ -905,6 +905,7 @@ import (
|
||||
DropDatabaseStmt "DROP DATABASE statement"
|
||||
DropImportStmt "DROP IMPORT statement"
|
||||
DropIndexStmt "DROP INDEX statement"
|
||||
DropResourceGroupStmt "DROP RESOURCE GROUP statement"
|
||||
DropStatisticsStmt "DROP STATISTICS statement"
|
||||
DropStatsStmt "DROP STATS statement"
|
||||
DropTableStmt "DROP TABLE statement"
|
||||
@ -11491,6 +11492,7 @@ Statement:
|
||||
| DropSequenceStmt
|
||||
| DropViewStmt
|
||||
| DropUserStmt
|
||||
| DropResourceGroupStmt
|
||||
| DropRoleStmt
|
||||
| DropStatisticsStmt
|
||||
| DropStatsStmt
|
||||
@ -13043,7 +13045,7 @@ ResourceGroupNameOption:
|
||||
{
|
||||
$$ = nil
|
||||
}
|
||||
| "RESOURCE" "GROUP" stringLit
|
||||
| "RESOURCE" "GROUP" ResourceGroupName
|
||||
{
|
||||
$$ = &ast.ResourceGroupNameOption{Type: ast.UserResourceGroupName, Value: $3}
|
||||
}
|
||||
@ -14204,8 +14206,8 @@ AlterResourceGroupStmt:
|
||||
}
|
||||
}
|
||||
|
||||
DropPolicyStmt:
|
||||
"DROP" "RESOURCE" "GROUP" IfExists PolicyName
|
||||
DropResourceGroupStmt:
|
||||
"DROP" "RESOURCE" "GROUP" IfExists ResourceGroupName
|
||||
{
|
||||
$$ = &ast.DropResourceGroupStmt{
|
||||
IfExists: $4.(bool),
|
||||
|
||||
@ -4527,10 +4527,10 @@ func TestPrivilege(t *testing.T) {
|
||||
{`CREATE USER 'root'@'localhost' IDENTIFIED BY 'new-password'`, true, "CREATE USER `root`@`localhost` IDENTIFIED BY 'new-password'"},
|
||||
{`CREATE USER 'root'@'localhost' IDENTIFIED BY PASSWORD 'hashstring'`, true, "CREATE USER `root`@`localhost` IDENTIFIED WITH 'mysql_native_password' AS 'hashstring'"},
|
||||
{`CREATE USER 'root'@'localhost' IDENTIFIED BY 'new-password', 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD 'hashstring'`, true, "CREATE USER `root`@`localhost` IDENTIFIED BY 'new-password', `root`@`127.0.0.1` IDENTIFIED WITH 'mysql_native_password' AS 'hashstring'"},
|
||||
{`CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'hashstring' RESOURCE GROUP 'rg1'`, true, "CREATE USER `root`@`127.0.0.1` IDENTIFIED BY 'hashstring' RESOURCE GROUP 'rg1'"},
|
||||
{`CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'hashstring' RESOURCE GROUP rg1`, true, "CREATE USER `root`@`127.0.0.1` IDENTIFIED BY 'hashstring' RESOURCE GROUP `rg1`"},
|
||||
{`ALTER USER IF EXISTS 'root'@'localhost' IDENTIFIED BY 'new-password'`, true, "ALTER USER IF EXISTS `root`@`localhost` IDENTIFIED BY 'new-password'"},
|
||||
{`ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password'`, true, "ALTER USER `root`@`localhost` IDENTIFIED BY 'new-password'"},
|
||||
{`ALTER USER 'root'@'localhost' RESOURCE GROUP 'rg2'`, true, "ALTER USER `root`@`localhost` RESOURCE GROUP 'rg2'"},
|
||||
{`ALTER USER 'root'@'localhost' RESOURCE GROUP rg2`, true, "ALTER USER `root`@`localhost` RESOURCE GROUP `rg2`"},
|
||||
{`ALTER USER 'root'@'localhost' IDENTIFIED BY PASSWORD 'hashstring'`, true, "ALTER USER `root`@`localhost` IDENTIFIED WITH 'mysql_native_password' AS 'hashstring'"},
|
||||
{`ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password', 'root'@'127.0.0.1' IDENTIFIED BY PASSWORD 'hashstring'`, true, "ALTER USER `root`@`localhost` IDENTIFIED BY 'new-password', `root`@`127.0.0.1` IDENTIFIED WITH 'mysql_native_password' AS 'hashstring'"},
|
||||
{`ALTER USER USER() IDENTIFIED BY 'new-password'`, true, "ALTER USER USER() IDENTIFIED BY 'new-password'"},
|
||||
|
||||
@ -515,7 +515,7 @@ func TestAlterUserStmt(t *testing.T) {
|
||||
tk.MustExec("GRANT RESTRICTED_USER_ADMIN ON *.* TO semuser1, semuser2, semuser3")
|
||||
tk.MustExec("GRANT SYSTEM_USER ON *.* to semuser3") // user is both restricted + has SYSTEM_USER (or super)
|
||||
|
||||
tk.MustExec(`ALTER USER 'semuser1' RESOURCE GROUP 'rg1'`)
|
||||
tk.MustExec(`ALTER USER 'semuser1' RESOURCE GROUP rg1`)
|
||||
tk.MustQuery(`SELECT User_attributes FROM mysql.user WHERE User = "semuser1"`).Check(testkit.Rows("{\"resource_group\": \"rg1\"}"))
|
||||
|
||||
tk.MustExec(`ALTER USER 'semuser1' COMMENT 'comment1'`)
|
||||
@ -1135,7 +1135,7 @@ func TestCreateDropUser(t *testing.T) {
|
||||
tk.MustQuery(`SELECT User_attributes FROM mysql.user WHERE User = "usr1"`).Check(testkit.Rows("{\"resource_group\": \"default\"}"))
|
||||
tk.MustExec(`DROP USER usr1`)
|
||||
|
||||
tk.MustExec(`CREATE USER usr1 RESOURCE GROUP 'rg1'`)
|
||||
tk.MustExec(`CREATE USER usr1 RESOURCE GROUP rg1`)
|
||||
tk.MustQuery(`SELECT User_attributes FROM mysql.user WHERE User = "usr1"`).Check(testkit.Rows("{\"resource_group\": \"rg1\"}"))
|
||||
tk.MustExec(`DROP USER usr1`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user