[MDEV-5723] mysqldump -uroot unusable for multi-database operations, checks all databases and tables when dumping a single DB Created: 2014-02-24 Updated: 2014-03-05 Resolved: 2014-03-05 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.36, 10.0.8 |
| Fix Version/s: | 5.5.37, 10.0.9 |
| Type: | Bug | Priority: | Major |
| Reporter: | Jan Ingvoldstad | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | information_schema, mysqldump, optimizer | ||
| Environment: |
Debian 7.4 (Wheezy), Linux mysql06 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux |
||
| Description |
|
When using mysqldump -uroot, this initiates a very, very resource intensive recursive check of every single database and table on the system. On a system with some 12k databases and 540k .frm files, this takes a long, long time. (The following output has substituted "censored" for the real username.) Using mysqldump -ucensored takes next to no time at all, and does not last for long enough that I can even see the query running. The issue does not appear to be present in MySQL 5.5.36 server as delivered by Oracle, but it occurs also when using mysqldump from that version, and therefore seems like it is in the server code, not the client code. Someone else have asked this as a question on serverfault.com also, so I'm not the only one experiencing the issue: http://serverfault.com/questions/574646/mariadb-10-0-slow-work-mysqldump Here is the relevant excerpt from SHOW FULL PROCESSLIST for my use case:
And here is some sample output from strace, showing what's going on:
|
| Comments |
| Comment by Elena Stepanova [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
Hi Jan, Thanks for the report. MySQL runs the same INFORMATION_SCHEMA query, but the query is almost instant on MySQL, while on MariaDB it takes considerable time. As a workaround, please try
It should be easier than creating a backup user for each schema that you want to dump. Alternatively, you can switch off semijoin in your server .cnf file, but you can get performance regression on some "normal" (non-INFORMATION_SCHEMA) queries. | ||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
Here is a test case to reproduce the issue (the query is taken from mysqldump as is, no changes):
Before/after timestamps: on MariaDB 5.5: on MariaDB 10.0: on MariaDB 10.0, semijoin=off: on MySQL 5.6 (default switch): EXPLAIN on 10.0 with semijoin=on:
EXPLAIN on 10.0 with semijoin=off:
| ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
If I change the query so that inner select calls FILES table "F2", then the EXPLAINs are: default @@optimizer_switch:
optimizer_switch='semijoin=off':
| ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
The query plans are different. The first apparent difference is "Scanned 1 database" vs "Scanned all databases" for table PARTITIONS. I don't see a reason why the first plan should have "Scanned all databases". The subquery looks like this: (SELECT DISTINCT TABLESPACE_NAME FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA IN ('db'))) and there is no reason for the optimizer to be unable to take advantage of TABLE_SCHEMA IN ('db'). | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
== Investigation == 1. The optimizer attaches TABLE_SCHEMA='db' to table PARTITIONS (everything ok so far) (gdb) p join->join_tab[1].bush_children.start[1].table->alias.Ptr But then Join Buffering code removes it: (gdb) wher Old: New: This is because TABLE_SCHEMA='db' is in cache_select->cond: The problem is that I_S optimization is done on tab->select_cond : (gdb) p dbug_print_item(cond) The bad call is here in do_fill_table(): bool res= table_list->schema_table->fill_table( | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-02-28 ] | ||||||||||||||||||||||||||||||||||||
|
Possible solutions:
| ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-03 ] | ||||||||||||||||||||||||||||||||||||
|
The problem that is described above (let's call it "Scanned all databases"-problem) is an unintended side effect of this fix in MariaDB 10.0: timour@askmonty.org-20131018084525-0fal318cbopywlkp, If we look at MariaDB 5.5, it doesn't have the "scanned all databases"-problem:
However, the query is still slower than in MySQL-5.6. | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-03 ] | ||||||||||||||||||||||||||||||||||||
|
MySQL-5.6 produces this EXPLAIN:
when I debug, I see that it doesn't even attempt to scan the PARTITIONS table. Besides that, I don't understand how they managed to get "Skip_open_table". | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-03 ] | ||||||||||||||||||||||||||||||||||||
|
Ok, this is not a MySQL 5.6 optimization, I've found it that it's their bug: http://bugs.mysql.com/bug.php?id=71914 . Most users of MySQL-5.6 and mysqldump will not be affected, because their database doesn't have anything that matches INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'UNDO LOG' or SELECT DISTINCT LOGFILE_GROUP_NAME FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE'. These are only used by NDB storage engine. | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-04 ] | ||||||||||||||||||||||||||||||||||||
|
Committed a patch that makes MariaDB 10.0 be as fast as MariaDB 5.5. It will not scan unneeded databases anymore. | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-04 ] | ||||||||||||||||||||||||||||||||||||
|
Did investigation of optimizer behavior: 1. Old optimizer (before semi-join subquery optimizations) 2. Semi-join optimizer, MariaDB 3. Semi-join optimizer, MySQL 5.6 | ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-04 ] | ||||||||||||||||||||||||||||||||||||
|
Fixing I_S tables to provide sane data to the optimizer is a big project. For now, we will:
| ||||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-03-05 ] | ||||||||||||||||||||||||||||||||||||
|
Fixed as described in the previous comment. frettled, thanks alot for taking time to report this issue. We really appreciate such input. | ||||||||||||||||||||||||||||||||||||
| Comment by Jan Ingvoldstad [ 2014-03-05 ] | ||||||||||||||||||||||||||||||||||||
|
And thank you very much, elenst and psergey, for the detailed analysis and, as far as I can tell from following the comments, exactly the correct fix for the problem! |