Bug #106560 slow DDL in mysql 8.0 as compare to 5.7 taking more time for checking permission
Submitted: 24 Feb 2022 14:51 Modified: 26 Feb 2022 7:14
Reporter: Aaditya Dubey Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:8.0.28 OS:Any
Assigned to: CPU Architecture:Any

[24 Feb 2022 14:51] Aaditya Dubey
Description:
regression on DDL statements with stage/sql/checking permissions seen very frequently in 8.0.28 where 5.7.37 shows it less frequently than 8.0!

We found out that there is regression for truncate/create operations and most of the time it goes to "checking permission" which actually slowing down the ddl operation in 8.0 in compare to 5.7

Please see the results from events_stages_summary_by_thread_by_event_name  table for 5.7 & 8.0 below:

mysql [localhost:5737] {msandbox} ((none)) > select version();
+-----------+
| version() |
+-----------+
| 5.7.37    |
+-----------+
1 row in set (0.00 sec)

mysql [localhost:5737] {msandbox} ((none)) > SELECT * FROM performance_schema.events_stages_summary_global_by_event_name where EVENT_NAME like "%checking permission%";
+--------------------------------+------------+----------------+----------------+----------------+----------------+
| EVENT_NAME                     | COUNT_STAR | SUM_TIMER_WAIT | MIN_TIMER_WAIT | AVG_TIMER_WAIT | MAX_TIMER_WAIT |
+--------------------------------+------------+----------------+----------------+----------------+----------------+
| stage/sql/checking permissions |      12014 |   426272795000 |         673000 |       35481000 |    23786915000 |
+--------------------------------+------------+----------------+----------------+----------------+----------------+
1 row in set (0.00 sec)

mysql [localhost:8028] {msandbox} ((none)) > select version();
+-----------+
| version() |
+-----------+
| 8.0.28    |
+-----------+
1 row in set (0.00 sec)

mysql [localhost:8028] {msandbox} ((none)) > SELECT * FROM performance_schema.events_stages_summary_global_by_event_name where EVENT_NAME like "%checking permission%";
+--------------------------------+------------+----------------+----------------+----------------+----------------+
| EVENT_NAME                     | COUNT_STAR | SUM_TIMER_WAIT | MIN_TIMER_WAIT | AVG_TIMER_WAIT | MAX_TIMER_WAIT |
+--------------------------------+------------+----------------+----------------+----------------+----------------+
| stage/sql/checking permissions |      15016 | 32297582601000 |        1287000 |     2150877000 |  3161270771000 |
+--------------------------------+------------+----------------+----------------+----------------+----------------+
1 row in set (0.00 sec) 

we can see the clear regression between 5.7 & 8.0    

How to repeat:
Please follow below steps to repro the issue:

1. prepare schema:

mysql -uroot -e "DROP DATABASE IF EXISTS test1; CREATE DATABASE test1"

mysql -uroot test1 -e "
DROP TABLE IF EXISTS parent;
CREATE TABLE parent (
id int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(10)
);"

for n in $(seq 3000); do
[ $(($n % 100)) -eq 0 ] && echo $n
mysql -uroot  test1 -e "
CREATE TABLE child$n (
id int(10) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
fk_field$n int(10) unsigned,
CONSTRAINT fk_$n FOREIGN KEY (fk_field$n) REFERENCES parent(id)
);"
done

#Truncate tables

echo "SET FOREIGN_KEY_CHECKS=0;" > truncate_test.sql
echo "SET UNIQUE_CHECKS=0;" >> truncate_test.sql

mysql -uroot  -A -BN information_schema -e "select concat('TRUNCATE test1.', table_name,';') from tables where table_schema = 'test1';" >> truncate_test.sql

time mysql -uroot  ttest < truncate_test.sql

2. please see the results by running below query:

SELECT * FROM performance_schema.events_stages_summary_global_by_event_name where EVENT_NAME like "%checking permission%";
[25 Feb 2022 14:02] MySQL Verification Team
Hi Mr. Dubey,

Thank you for your bug report.

However, general performance drop between 5.7 and 8.0, for single-threaded operation,  is very well known and documented. Your report is a duplicate of many of already verified reports, such as:

https://bugs.mysql.com/bug.php?id=90209

https://bugs.mysql.com/bug.php?id=85255 (you can't access this one)

https://bugs.mysql.com/bug.php?id=95684 (this is also a private bug)

https://bugs.mysql.com/bug.php?id=92979

and many , many others.

There are very good reasons for the performance degradation. DDL operations in 8.0 are all atomic, while 5.7 operations did not allow that. Next, 8.0 has been designed to provide much better performance in the multi-threaded loads, which is a real-life situation on more then 90 % installations of our server.

Hence, we recommend you to run your DDLs in many threads. That also means to dump your schemas with mysqlpump, instead of mysqldump.

Hence, your bug report is something that we are very well aware of and is reported so many times for 8.0.

Duplicate.
[26 Feb 2022 7:14] Aaditya Dubey
Thanks for the updates team!
[28 Feb 2022 14:01] MySQL Verification Team
Hi Mr. Dubey,

You are truly welcome .....