Skip to content

Commit

Permalink
Merge branch 'master' into support_database_placement_option_
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoxugang authored Oct 7, 2021
2 parents 8b70a24 + 6eb02fb commit c3d6792
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059
github.com/pingcap/kvproto v0.0.0-20210806074406-317f69fb54b4
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354
github.com/pingcap/parser v0.0.0-20210923132047-19e7f91ed500
github.com/pingcap/parser v0.0.0-20211004012448-687005894c4e
github.com/pingcap/sysutil v0.0.0-20210730114356-fcd8a63f68c5
github.com/pingcap/tidb-tools v5.0.3+incompatible
github.com/pingcap/tipb v0.0.0-20210802080519-94b831c6db55
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,8 @@ github.com/pingcap/log v0.0.0-20210625125904-98ed8e2eb1c7/go.mod h1:8AanEdAHATuR
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 h1:SvWCbCPh1YeHd9yQLksvJYAgft6wLTY1aNG81tpyscQ=
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354/go.mod h1:DWQW5jICDR7UJh4HtxXSM20Churx4CQL0fwL/SoOSA4=
github.com/pingcap/parser v0.0.0-20210525032559-c37778aff307/go.mod h1:xZC8I7bug4GJ5KtHhgAikjTfU4kBv1Sbo3Pf1MZ6lVw=
github.com/pingcap/parser v0.0.0-20210923132047-19e7f91ed500 h1:xe2A/2r15+ahyAVrlindm08M3guhQdv++Mmu29nNXoY=
github.com/pingcap/parser v0.0.0-20210923132047-19e7f91ed500/go.mod h1:+xcMiiZzdIktT/Nqdfm81dkECJ2EPuoAYywd57py4Pk=
github.com/pingcap/parser v0.0.0-20211004012448-687005894c4e h1:dPMDpj+7ng9qEWoT3n6qjpB1ohz79uTLVM6ILW+ZMT0=
github.com/pingcap/parser v0.0.0-20211004012448-687005894c4e/go.mod h1:+xcMiiZzdIktT/Nqdfm81dkECJ2EPuoAYywd57py4Pk=
github.com/pingcap/sysutil v0.0.0-20200206130906-2bfa6dc40bcd/go.mod h1:EB/852NMQ+aRKioCpToQ94Wl7fktV+FNnxf3CX/TTXI=
github.com/pingcap/sysutil v0.0.0-20210315073920-cc0985d983a3/go.mod h1:tckvA041UWP+NqYzrJ3fMgC/Hw9wnmQ/tUkp/JaHly8=
github.com/pingcap/sysutil v0.0.0-20210730114356-fcd8a63f68c5 h1:7rvAtZe/ZUzOKzgriNPQoBNvleJXBk4z7L3Z47+tS98=
Expand Down
2 changes: 2 additions & 0 deletions planner/core/logical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ func (s *testPlanSuite) TestVisitInfo(c *C) {
{mysql.GrantPriv, "test", "", "", nil, false, "", false},
{mysql.ReferencesPriv, "test", "", "", nil, false, "", false},
{mysql.LockTablesPriv, "test", "", "", nil, false, "", false},
{mysql.CreateTMPTablePriv, "test", "", "", nil, false, "", false},
{mysql.AlterPriv, "test", "", "", nil, false, "", false},
{mysql.ExecutePriv, "test", "", "", nil, false, "", false},
{mysql.IndexPriv, "test", "", "", nil, false, "", false},
Expand Down Expand Up @@ -1142,6 +1143,7 @@ func (s *testPlanSuite) TestVisitInfo(c *C) {
{mysql.GrantPriv, "test", "", "", nil, false, "", false},
{mysql.ReferencesPriv, "test", "", "", nil, false, "", false},
{mysql.LockTablesPriv, "test", "", "", nil, false, "", false},
{mysql.CreateTMPTablePriv, "test", "", "", nil, false, "", false},
{mysql.AlterPriv, "test", "", "", nil, false, "", false},
{mysql.ExecutePriv, "test", "", "", nil, false, "", false},
{mysql.IndexPriv, "test", "", "", nil, false, "", false},
Expand Down
2 changes: 1 addition & 1 deletion privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const globalDBVisible = mysql.CreatePriv | mysql.SelectPriv | mysql.InsertPriv |
const (
sqlLoadRoleGraph = "SELECT HIGH_PRIORITY FROM_USER, FROM_HOST, TO_USER, TO_HOST FROM mysql.role_edges"
sqlLoadGlobalPrivTable = "SELECT HIGH_PRIORITY Host,User,Priv FROM mysql.global_priv"
sqlLoadDBTable = "SELECT HIGH_PRIORITY Host,DB,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,Index_priv,References_priv,Lock_tables_priv,Alter_priv,Execute_priv,Create_view_priv,Show_view_priv FROM mysql.db ORDER BY host, db, user"
sqlLoadDBTable = "SELECT HIGH_PRIORITY Host,DB,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,Index_priv,References_priv,Lock_tables_priv,Create_tmp_table_priv,Alter_priv,Execute_priv,Create_view_priv,Show_view_priv FROM mysql.db ORDER BY host, db, user"
sqlLoadTablePrivTable = "SELECT HIGH_PRIORITY Host,DB,User,Table_name,Grantor,Timestamp,Table_priv,Column_priv FROM mysql.tables_priv"
sqlLoadColumnsPrivTable = "SELECT HIGH_PRIORITY Host,DB,User,Table_name,Column_name,Timestamp,Column_priv FROM mysql.columns_priv"
sqlLoadDefaultRoles = "SELECT HIGH_PRIORITY HOST, USER, DEFAULT_ROLE_HOST, DEFAULT_ROLE_USER FROM mysql.default_roles"
Expand Down
24 changes: 24 additions & 0 deletions privilege/privileges/privileges_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2492,3 +2492,27 @@ func TestDBNameCaseSensitivityInTableLevel(t *testing.T) {
mustExec(t, se, "CREATE USER test_user")
mustExec(t, se, "grant select on metrics_schema.up to test_user;")
}

func TestGrantCreateTmpTables(t *testing.T) {
t.Parallel()
store, clean := newStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("CREATE DATABASE create_tmp_table_db")
tk.MustExec("USE create_tmp_table_db")
tk.MustExec("CREATE USER u1")
tk.MustExec("CREATE TABLE create_tmp_table_table (a int)")
tk.MustExec("GRANT CREATE TEMPORARY TABLES on create_tmp_table_db.* to u1")
tk.MustExec("GRANT CREATE TEMPORARY TABLES on *.* to u1")
// Must set a session user to avoid null pointer dereferencing
tk.Session().Auth(&auth.UserIdentity{
Username: "root",
Hostname: "localhost",
}, nil, nil)
tk.MustQuery("SHOW GRANTS FOR u1").Check(testkit.Rows(
`GRANT CREATE TEMPORARY TABLES ON *.* TO 'u1'@'%'`,
`GRANT CREATE TEMPORARY TABLES ON create_tmp_table_db.* TO 'u1'@'%'`))
tk.MustExec("DROP USER u1")
tk.MustExec("DROP DATABASE create_tmp_table_db")
}
16 changes: 13 additions & 3 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const (
Grantor CHAR(77),
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Table_priv SET('Select','Insert','Update','Delete','Create','Drop','Grant','Index','Alter','Create View','Show View','Trigger','References'),
Column_priv SET('Select','Insert','Update'),
Column_priv SET('Select','Insert','Update','References'),
PRIMARY KEY (Host, DB, User, Table_name));`
// CreateColumnPrivTable is the SQL statement creates column scope privilege table in system db.
CreateColumnPrivTable = `CREATE TABLE IF NOT EXISTS mysql.columns_priv(
Expand All @@ -142,7 +142,7 @@ const (
Table_name CHAR(64),
Column_name CHAR(64),
Timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
Column_priv SET('Select','Insert','Update'),
Column_priv SET('Select','Insert','Update','References'),
PRIMARY KEY (Host, DB, User, Table_name, Column_name));`
// CreateGlobalVariablesTable is the SQL statement creates global variable table in system db.
// TODO: MySQL puts GLOBAL_VARIABLES table in INFORMATION_SCHEMA db.
Expand Down Expand Up @@ -513,11 +513,13 @@ const (
version74 = 74
// version75 update mysql.*.host from char(60) to char(255)
version75 = 75
// version76 update mysql.columns_priv from SET('Select','Insert','Update') to SET('Select','Insert','Update','References')
version76 = 76
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version75
var currentBootstrapVersion int64 = version76

var (
bootstrapVersion = []func(Session, int64){
Expand Down Expand Up @@ -596,6 +598,7 @@ var (
upgradeToVer73,
upgradeToVer74,
upgradeToVer75,
upgradeToVer76,
}
)

Expand Down Expand Up @@ -1571,6 +1574,13 @@ func upgradeToVer75(s Session, ver int64) {
doReentrantDDL(s, "ALTER TABLE mysql.columns_priv MODIFY COLUMN Host CHAR(255)")
}

func upgradeToVer76(s Session, ver int64) {
if ver >= version76 {
return
}
doReentrantDDL(s, "ALTER TABLE mysql.columns_priv MODIFY COLUMN Column_priv SET('Select','Insert','Update','References')")
}

func writeOOMAction(s Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down
18 changes: 18 additions & 0 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,3 +845,21 @@ func (s *testBootstrapSuite) TestForIssue23387(c *C) {
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "GRANT USAGE ON *.* TO 'quatest'@'%'")
}

func (s *testBootstrapSuite) TestReferencesPrivOnCol(c *C) {
defer testleak.AfterTest(c)()
store, dom := newStoreWithBootstrap(c, s.dbName)
defer store.Close()
defer dom.Close()
se := newSession(c, store, s.dbName)

defer func() {
mustExecSQL(c, se, "drop user if exists issue28531")
mustExecSQL(c, se, "drop table if exists t1")
}()

mustExecSQL(c, se, "create user if not exists issue28531")
mustExecSQL(c, se, "drop table if exists t1")
mustExecSQL(c, se, "create table t1 (a int)")
mustExecSQL(c, se, "GRANT select (a), update (a),insert(a), references(a) on t1 to issue28531")
}

0 comments on commit c3d6792

Please sign in to comment.