Bug #113430 | Query slowness in Delete query with many child table | ||
---|---|---|---|
Submitted: | 14 Dec 2023 23:06 | Modified: | 22 Dec 2023 14:00 |
Reporter: | TAMILMARAN C | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server | Severity: | S3 (Non-critical) |
Version: | 8.0.34 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[14 Dec 2023 23:06]
TAMILMARAN C
[15 Dec 2023 13:33]
MySQL Verification Team
Hi MR. C, Thank you very much for your bug report. However, we do not see what is a bug that you are reporting. Deleting from the parent table that has 10.000 child tables in 3 seconds is very fast, indeed. You claim that 5.7 is much faster ....... What are the times there ????
[17 Dec 2023 14:02]
TAMILMARAN C
In 5.7 took 1ms alone. mysql> delete from parent_table_2 where id =1; Query OK, 0 rows affected (0.01 sec) mysql> explain delete from parent_table_2 where id =1; +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ | 1 | DELETE | parent_table_2 | NULL | range | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | Using where | +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ 1 row in set (0.00 sec) By the way there is no rows in parent_table_2. That is an empty table. In Mysql 8, even explain query itself taking more time. mysql> delete from parent_table_2 where id =1; Query OK, 0 rows affected (3.18 sec) mysql> explain delete from parent_table_2 where id =1; +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ | id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ | 1 | DELETE | parent_table_2 | NULL | range | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | Using where | +----+-------------+----------------+------------+-------+---------------+---------+---------+-------+------+----------+-------------+ 1 row in set, 1 warning (3.90 sec)
[18 Dec 2023 11:32]
MySQL Verification Team
Hi Mr. C, That is expected behaviour, since 8.0 has many additional checks added, since it has so many more features. Can you reproduce the same slowness with 10 or 100 child tables ?????
[22 Dec 2023 14:00]
TAMILMARAN C
We increased table_definition_cache to 10K, After that we didn't face the issue. Still we ran perf and took flamegraph for the query in mysql and went through slow processing functions. 1. sql_base.open_and_process_routine When CUD query is fired to Parent, MySQL requires SW lock for all its child. In this work item - https://dev.MySQL.com/worklog/task/?id=6049, MySQL team has mentioned they are not intended to open all the child tables. Just needed to acquire SW lock for the child. But when we checked the code, all the child table is opened and its respective info is stored in def cache(table share). 2. sql_base.get_table_share Also, in our test case, a parent table with 4K child table explain delete query took 21sec. In this get_table_share alone took 20.84sec. And inside this get_table_share, read histogram contributes around 10-11sec(50%), we haven’t created any histogram but still 8.0 tries to load histogram statistics in table_share. So when we commented this read_histogram method we were able to gain 50% faster execution speed. Is there any possible ways to fix/handle this in better way?
[22 Dec 2023 14:00]
TAMILMARAN C
Flamegraph
Attachment: Screenshot 2023-12-21 at 10.55.40 PM.png (image/png, text), 852.82 KiB.
[8 Jan 2024 10:23]
MySQL Verification Team
Hi Mr. C, Thank you for the information provided. You wrote that when you increased table_definition_cache to 10K, the slowness disappeared. That means that your report is not a bug , but it was just a misconfiguration. Next, regarding locking the table, you can not lock a table unless it is open. Last, regarding histograms, there are so many installations with many tables using histograms, so we can not just comment out that part of the code. Checking for histograms will take the same time as attempting to load them. If there were histograms, that part of the code would have taken significantly longer time. Histograms are a new feature and they can not be just removed.