Skip to content

Commit

Permalink
WL#14965: Redefine Primary Key on ACL tables.
Browse files Browse the repository at this point in the history
This WL helps improve performance of ACL DDLs, by changing the order of
columns defined in PRIMARY KEY(PK) for ACL tables.

Each time CREATE/DROP/RENAME USER is executed, server will perform a full table
scan on few ACL tables like mysql.db, mysql.tables_priv, mysql.columns_priv,
mysql.procs_priv. By redefining the order of PK in these tables, the execution
time of these sql statements is improved.

RB#27633
  • Loading branch information
Bharathy Satish committed Mar 17, 2022
1 parent 961f5a4 commit e6c82eb
Show file tree
Hide file tree
Showing 14 changed files with 6,842 additions and 6,743 deletions.
8 changes: 4 additions & 4 deletions mysql-test/r/system_mysql_db.result
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ db CREATE TABLE `db` (
`Execute_priv` enum('N','Y') COLLATE utf8_general_ci NOT NULL DEFAULT 'N',
`Event_priv` enum('N','Y') COLLATE utf8_general_ci NOT NULL DEFAULT 'N',
`Trigger_priv` enum('N','Y') COLLATE utf8_general_ci NOT NULL DEFAULT 'N',
PRIMARY KEY (`Host`,`Db`,`User`),
PRIMARY KEY (`Host`,`User`,`Db`),
KEY `User` (`User`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0 ROW_FORMAT=DYNAMIC COMMENT='Database privileges'
show create table user;
Expand Down Expand Up @@ -141,7 +141,7 @@ tables_priv CREATE TABLE `tables_priv` (
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Table_priv` set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci NOT NULL DEFAULT '',
`Column_priv` set('Select','Insert','Update','References') COLLATE utf8_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`),
PRIMARY KEY (`Host`,`User`,`Db`,`Table_name`),
KEY `Grantor` (`Grantor`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0 ROW_FORMAT=DYNAMIC COMMENT='Table privileges'
show create table columns_priv;
Expand All @@ -154,7 +154,7 @@ columns_priv CREATE TABLE `columns_priv` (
`Column_name` char(64) COLLATE utf8mb3_bin NOT NULL DEFAULT '',
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`Column_priv` set('Select','Insert','Update','References') COLLATE utf8_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`Host`,`Db`,`User`,`Table_name`,`Column_name`)
PRIMARY KEY (`Host`,`User`,`Db`,`Table_name`,`Column_name`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0 ROW_FORMAT=DYNAMIC COMMENT='Column privileges'
show create table procs_priv;
Table Create Table
Expand All @@ -167,7 +167,7 @@ procs_priv CREATE TABLE `procs_priv` (
`Grantor` varchar(288) COLLATE utf8mb3_bin NOT NULL DEFAULT '',
`Proc_priv` set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci NOT NULL DEFAULT '',
`Timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`Host`,`Db`,`User`,`Routine_name`,`Routine_type`),
PRIMARY KEY (`Host`,`User`,`Db`,`Routine_name`,`Routine_type`),
KEY `Grantor` (`Grantor`)
) /*!50100 TABLESPACE `mysql` */ ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0 ROW_FORMAT=DYNAMIC COMMENT='Procedure privileges'
show create table servers;
Expand Down
18 changes: 0 additions & 18 deletions mysql-test/r/transactional_acl_tables.result
Original file line number Diff line number Diff line change
Expand Up @@ -1169,24 +1169,6 @@ Error 3501 The ACL operation failed due to the following error from SE: errcode
SHOW GRANTS FOR u1@h;
ERROR 42000: There is no such grant defined for user 'u1' on host 'h'
SET debug="-d,wl7158_handle_grant_table_1";
SET debug="+d,wl7158_handle_grant_table_2";
CREATE USER u1@h;
ERROR HY000: The ACL operation failed due to the following error from SE: errcode 149 - Lock deadlock; Retry transaction
SHOW WARNINGS;
Level Code Message
Error 3501 The ACL operation failed due to the following error from SE: errcode 149 - Lock deadlock; Retry transaction
SHOW GRANTS FOR u1@h;
ERROR 42000: There is no such grant defined for user 'u1' on host 'h'
SET debug="-d,wl7158_handle_grant_table_2";
SET debug="+d,wl7158_handle_grant_table_3";
CREATE USER u1@h;
ERROR HY000: The ACL operation failed due to the following error from SE: errcode 149 - Lock deadlock; Retry transaction
SHOW WARNINGS;
Level Code Message
Error 3501 The ACL operation failed due to the following error from SE: errcode 149 - Lock deadlock; Retry transaction
SHOW GRANTS FOR u1@h;
ERROR 42000: There is no such grant defined for user 'u1' on host 'h'
SET debug="-d,wl7158_handle_grant_table_3";
CREATE USER u1@h;
SET debug="+d,wl7158_modify_grant_table_1";
rename user u1@h to u2@h;
Expand Down
91 changes: 91 additions & 0 deletions mysql-test/r/wl14965.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
CALL mtr.add_suppression("\\[Warning\\] .*MY-\\d+.* Cannot add field.*");
# restore mysql tables from 8.0.27
SHOW KEYS FROM mysql.db;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
db 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
db 0 PRIMARY 2 Db A 1 NULL NULL BTREE YES NULL
db 0 PRIMARY 3 User A 1 NULL NULL BTREE YES NULL
db 1 User 1 User A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.tables_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
tables_priv 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 2 Db A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 3 User A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 4 Table_name A 1 NULL NULL BTREE YES NULL
tables_priv 1 Grantor 1 Grantor A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.columns_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
columns_priv 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 2 Db A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 3 User A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 4 Table_name A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 5 Column_name A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.procs_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
procs_priv 0 PRIMARY 1 Host A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 2 Db A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 3 User A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 4 Routine_name A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 5 Routine_type A 0 NULL NULL BTREE YES NULL
procs_priv 1 Grantor 1 Grantor A 0 NULL NULL BTREE YES NULL
# Restart server without upgrade option
# restart
# Restart server with upgrade option
# restart:--upgrade=force
SHOW KEYS FROM mysql.db;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
db 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
db 0 PRIMARY 2 User A 1 NULL NULL BTREE YES NULL
db 0 PRIMARY 3 Db A 1 NULL NULL BTREE YES NULL
db 1 User 1 User A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.tables_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
tables_priv 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 2 User A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 3 Db A 1 NULL NULL BTREE YES NULL
tables_priv 0 PRIMARY 4 Table_name A 1 NULL NULL BTREE YES NULL
tables_priv 1 Grantor 1 Grantor A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.columns_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
columns_priv 0 PRIMARY 1 Host A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 2 User A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 3 Db A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 4 Table_name A 1 NULL NULL BTREE YES NULL
columns_priv 0 PRIMARY 5 Column_name A 1 NULL NULL BTREE YES NULL
SHOW KEYS FROM mysql.procs_priv;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Visible Expression
procs_priv 0 PRIMARY 1 Host A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 2 User A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 3 Db A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 4 Routine_name A 0 NULL NULL BTREE YES NULL
procs_priv 0 PRIMARY 5 Routine_type A 0 NULL NULL BTREE YES NULL
procs_priv 1 Grantor 1 Grantor A 0 NULL NULL BTREE YES NULL
CREATE USER wl14965_u2;
GRANT ALL ON test.* to wl14965_u2;
SHOW GRANTS FOR wl14965_u2;
Grants for wl14965_u2@%
GRANT USAGE ON *.* TO `wl14965_u2`@`%`
GRANT ALL PRIVILEGES ON `test`.* TO `wl14965_u2`@`%`
DROP USER wl14965_u2;
# ensure that key_len is 351 which includes length of host(255) + user(96)
EXPLAIN SELECT * FROM mysql.db WHERE host='' AND user='';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE db NULL ref PRIMARY,User PRIMARY 351 const,const # # NULL
Warnings:
Note 1003 /* select#1 */ select `mysql`.`db`.`Host` AS `Host`,`mysql`.`db`.`Db` AS `Db`,`mysql`.`db`.`User` AS `User`,`mysql`.`db`.`Select_priv` AS `Select_priv`,`mysql`.`db`.`Insert_priv` AS `Insert_priv`,`mysql`.`db`.`Update_priv` AS `Update_priv`,`mysql`.`db`.`Delete_priv` AS `Delete_priv`,`mysql`.`db`.`Create_priv` AS `Create_priv`,`mysql`.`db`.`Drop_priv` AS `Drop_priv`,`mysql`.`db`.`Grant_priv` AS `Grant_priv`,`mysql`.`db`.`References_priv` AS `References_priv`,`mysql`.`db`.`Index_priv` AS `Index_priv`,`mysql`.`db`.`Alter_priv` AS `Alter_priv`,`mysql`.`db`.`Create_tmp_table_priv` AS `Create_tmp_table_priv`,`mysql`.`db`.`Lock_tables_priv` AS `Lock_tables_priv`,`mysql`.`db`.`Create_view_priv` AS `Create_view_priv`,`mysql`.`db`.`Show_view_priv` AS `Show_view_priv`,`mysql`.`db`.`Create_routine_priv` AS `Create_routine_priv`,`mysql`.`db`.`Alter_routine_priv` AS `Alter_routine_priv`,`mysql`.`db`.`Execute_priv` AS `Execute_priv`,`mysql`.`db`.`Event_priv` AS `Event_priv`,`mysql`.`db`.`Trigger_priv` AS `Trigger_priv` from `mysql`.`db` where ((`mysql`.`db`.`User` = '') and (`mysql`.`db`.`Host` = ''))
EXPLAIN SELECT * FROM mysql.tables_priv WHERE host='' AND user='';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE tables_priv NULL ref PRIMARY PRIMARY 351 const,const # # NULL
Warnings:
Note 1003 /* select#1 */ select `mysql`.`tables_priv`.`Host` AS `Host`,`mysql`.`tables_priv`.`Db` AS `Db`,`mysql`.`tables_priv`.`User` AS `User`,`mysql`.`tables_priv`.`Table_name` AS `Table_name`,`mysql`.`tables_priv`.`Grantor` AS `Grantor`,`mysql`.`tables_priv`.`Timestamp` AS `Timestamp`,`mysql`.`tables_priv`.`Table_priv` AS `Table_priv`,`mysql`.`tables_priv`.`Column_priv` AS `Column_priv` from `mysql`.`tables_priv` where ((`mysql`.`tables_priv`.`User` = '') and (`mysql`.`tables_priv`.`Host` = ''))
EXPLAIN SELECT * FROM mysql.columns_priv WHERE host='' AND user='';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE columns_priv NULL ref PRIMARY PRIMARY 351 const,const # # NULL
Warnings:
Note 1003 /* select#1 */ select `mysql`.`columns_priv`.`Host` AS `Host`,`mysql`.`columns_priv`.`Db` AS `Db`,`mysql`.`columns_priv`.`User` AS `User`,`mysql`.`columns_priv`.`Table_name` AS `Table_name`,`mysql`.`columns_priv`.`Column_name` AS `Column_name`,`mysql`.`columns_priv`.`Timestamp` AS `Timestamp`,`mysql`.`columns_priv`.`Column_priv` AS `Column_priv` from `mysql`.`columns_priv` where ((`mysql`.`columns_priv`.`User` = '') and (`mysql`.`columns_priv`.`Host` = ''))
EXPLAIN SELECT * FROM mysql.procs_priv WHERE host='' AND user='';
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE procs_priv NULL ref PRIMARY PRIMARY 351 const,const # # NULL
Warnings:
Note 1003 /* select#1 */ select `mysql`.`procs_priv`.`Host` AS `Host`,`mysql`.`procs_priv`.`Db` AS `Db`,`mysql`.`procs_priv`.`User` AS `User`,`mysql`.`procs_priv`.`Routine_name` AS `Routine_name`,`mysql`.`procs_priv`.`Routine_type` AS `Routine_type`,`mysql`.`procs_priv`.`Grantor` AS `Grantor`,`mysql`.`procs_priv`.`Proc_priv` AS `Proc_priv`,`mysql`.`procs_priv`.`Timestamp` AS `Timestamp` from `mysql`.`procs_priv` where ((`mysql`.`procs_priv`.`User` = '') and (`mysql`.`procs_priv`.`Host` = ''))
DROP DATABASE wl14965;
40 changes: 20 additions & 20 deletions mysql-test/std_data/dd/sdi/innodb_sdi/mysql.json
Original file line number Diff line number Diff line change
Expand Up @@ -26761,17 +26761,17 @@
},
{
"ordinal_position": 2,
"length": 192,
"length": 96,
"order": 2,
"hidden": false,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 3,
"length": 96,
"length": 192,
"order": 2,
"hidden": false,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 4,
Expand Down Expand Up @@ -33880,17 +33880,17 @@
},
{
"ordinal_position": 2,
"length": 192,
"length": 96,
"order": 2,
"hidden": false,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 3,
"length": 96,
"length": 192,
"order": 2,
"hidden": false,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 4,
Expand Down Expand Up @@ -33979,14 +33979,14 @@
"length": 4294967295,
"order": 2,
"hidden": true,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 4,
"length": 4294967295,
"order": 2,
"hidden": true,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 5,
Expand Down Expand Up @@ -34428,17 +34428,17 @@
},
{
"ordinal_position": 2,
"length": 192,
"length": 96,
"order": 2,
"hidden": false,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 3,
"length": 96,
"length": 192,
"order": 2,
"hidden": false,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 4,
Expand Down Expand Up @@ -36650,17 +36650,17 @@
},
{
"ordinal_position": 2,
"length": 192,
"length": 96,
"order": 2,
"hidden": false,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 3,
"length": 96,
"length": 192,
"order": 2,
"hidden": false,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 4,
Expand Down Expand Up @@ -36749,14 +36749,14 @@
"length": 4294967295,
"order": 2,
"hidden": true,
"column_opx": 1
"column_opx": 2
},
{
"ordinal_position": 4,
"length": 4294967295,
"order": 2,
"hidden": true,
"column_opx": 2
"column_opx": 1
},
{
"ordinal_position": 5,
Expand Down
Loading

0 comments on commit e6c82eb

Please sign in to comment.