[MDEV-6189] A query plan not optimized Created: 2014-04-30 Updated: 2014-08-12 Due: 2014-05-30 Resolved: 2014-08-12 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 10.0.10 |
| Fix Version/s: | 10.0.13 |
| Type: | Bug | Priority: | Major |
| Reporter: | james wang | Assignee: | Sergei Petrunia |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Production |
||
| Attachments: |
|
| Description |
|
Table structure:
Query:
MariaDB plan:
MySQL plan:
Ie. MySQL is much more quicker than MariaDB in this query. BTW, does the query optimizer have some sort of heuristic and can learn? |
| Comments |
| Comment by Elena Stepanova [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
Hi, Are you running both servers on the identical data? I am not getting the same plans, but of course it heavily depends on the actual data. Would you be able to upload the data dump to our ftp (ftp.askmonty.org/private)? Thanks. | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
Yes, almost identical as both servers are slaves of the same master. shall attach or ftp "show variables" result soon. Can not upload data - it is a few hundred GB. also it is not allowed by the company. show table status like 'c' (same in both in MariaDB 10.0.11 and Percona 5.6): | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
MariaDB 10.0.11 variables | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
Pecona 5.6 variables | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
there are 24 indexes in the table and index_type all BTREE "ANALYZE TABLE" is not allowed as they are production servers Very true about: query plan depends on data - has MariaDB any learning capability (heuristic) please? E.g. when it tried index and see it is too big, try range then. Percona took less than 1 seconds to execute this query. MariaDB took 2 hours and the query was timed out (no result). | |||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
No, the current versions don't have it. We have the task MDEV-350 for self-tuning optimizer, I suppose it's close to what you are looking for. It is currently targeted for the next GA (10.1).
How can there be 24 indexes? You quoted SHOW CREATE TABLE before, there are 3 indexes with 4 columns total participating in them. Is your production table different from the description above? It's rather unfortunate that you never run ANALYZE TABLE... It could happen that optimizer on MariaDB instance was given very bad estimates for the InnoDB table, and thus chooses a bad plan. | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
Yes, I simplied the table structure for you guys to replicate the issue. It actually has 24 indexes. | |||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
But did you actually see the same problem on the simplified table – both different plans and essentially different execution time? In other words, we need consistent data, everything from the same table, without assumptions that it will be the same on the simplified one:
Thanks! | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-04-30 ] | |||||||||||||||||||||||||||||||||||
|
Emailed you details. Thanks | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-06-12 ] | |||||||||||||||||||||||||||||||||||
|
Any update please? 1). if no much data in table c MariaDB has the same query type as Percona 5.6 Hope this assists a little bit more. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-18 ] | |||||||||||||||||||||||||||||||||||
Currently not, neither MariaDB's, nor MySQL's. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-18 ] | |||||||||||||||||||||||||||||||||||
|
Analysis: So, the query plans are:
Both are using PRIMARY key. It is defined as
so using this key allows to satisfy the "ORDER BY cid LIMIT 300" by reading the first 300 rows. I'm wondering why does MariaDB use "index" when "range" access is possible. I'll investigate now. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-18 ] | |||||||||||||||||||||||||||||||||||
|
On a second thought, I don't understand how MySQL could use "range" access over the PRIMARY key. The WHERE clause has no conditions on the `cid` column, it is not possible to construct a range access on PRIMARY key. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-18 ] | |||||||||||||||||||||||||||||||||||
This seems like something with cost calculations in test_if_skip_sort_order(). I am not sure what exactly this is (I can't repeat on a dataset I've generated). It would be nice to have a dataset taht demonstrates the problem. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-19 ] | |||||||||||||||||||||||||||||||||||
|
Experiences from working with the dataset: Right after loading the data, I was getting the same query plan on both MySQL 5.6 and MariaDB:
Execution time depends a lot on whether it runs on "hot" or "cold" buffer pool. It is around 0.03 sec on my laptop. Increments for relevant Handler_xxx counters:
| |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-19 ] | |||||||||||||||||||||||||||||||||||
|
Trying to see what other plans are possible. Adding IGNORE INDEX(PRIMARY) gets this:
The query produces these increments:
and runs in around 0.09 sec (Hot buffer pool) on my laptop. | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-19 ] | |||||||||||||||||||||||||||||||||||
|
On MySQL 5.6, IGNORE INDEX(PRIMARY) has a similar effect:
| |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-19 ] | |||||||||||||||||||||||||||||||||||
|
Debugging how it is optimized. index statistics is not involved in the cost calculations (that is, ANALYZE TABLE, innodb_stats_persistent, etc - all these won't affect this). | |||||||||||||||||||||||||||||||||||
| Comment by Sergei Petrunia [ 2014-06-19 ] | |||||||||||||||||||||||||||||||||||
|
I have to conclude I'm unable to repeat. James, could you try with the test dataset - is it possible to repeatably get the query to run slow (i.e. it runs slow every time, not just the first time you run it)? If yes, could you please provide 1. Ouput of EXPLAIN that is run when the query ran slow. ? | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-06-30 ] | |||||||||||||||||||||||||||||||||||
|
This issue is indeed hard to replicate. If I choose less days in datetime, I had
-----
----- As far as why Percona also had index query type, it was perhaps because that the data set is not large enough. If there are 800M records in the table, Percona query type is always range (while MariaDB uses index) | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-07-01 ] | |||||||||||||||||||||||||||||||||||
|
deleted in-correct comments - 10.0.12 does not fix my issue yet. | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-07-24 ] | |||||||||||||||||||||||||||||||||||
|
I have still not managed to replicated this issue yet either. It only happens when the index file becomes huge. So far, I tried upto 30 millions records in the table but failed to replicate the issue. The live databases has 800 million records | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-08-08 ] | |||||||||||||||||||||||||||||||||||
|
Hi Sergei, I have just updated the table structure. Is it possible for you for generate some pseudo data (please use c/c++ - quickest way in looping about 3 times quicker than java and 20 times quicker than php) and fill the table with hundred millions of records so as to replicate this issue please? I can not send you the table as it contain company real commercial data. Also, the table is a few GB and I have no means to transfer the file to you. Thanks a lot in advance | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-08-11 ] | |||||||||||||||||||||||||||||||||||
|
Hi Sergei, We downloaded the 10.0.12 from yum.mariadb.org last Friday. Our issue seams gone. Great. Shall keep you informed. Thanks | |||||||||||||||||||||||||||||||||||
| Comment by james wang [ 2014-08-12 ] | |||||||||||||||||||||||||||||||||||
|
Please close this ticket |