简体   繁体   中英

Poor mariadb performance vs mysql

I heard that Mariadb has better performance than mysql, so I cloned a website with his whole database to compare difference between the 2.

Indeed whith cache everything seems faster, but I have very strange output when there is no cache, on some big request mariadb is far worse than mysql :

MariaDB> select SQL_NO_CACHE [...] ORDER BY FIELD LIMIT 0, 200;
Empty set (10.13 sec)

mysql> select SQL_NO_CACHE [...] ORDER BY FIELD LIMIT 0, 200;
Empty set (0.76 sec)

It's a huge difference, how is it possible ?

The full query look like that :

SELECT 
    SQL_NO_CACHE [...] 
FROM 
    table1
WHERE
    field1 = 'val1' and
    field2 = 'val2' and
    (field3='val3' or INSTR(field3, 'val3'))
ORDER BY field4 DESC LIMIT 0, 200;

Here is the explain of the request :

+----+-------------+----------+------+--------------------------+---------+---------+-------+--------+-----------------------------+
| id | select_type | table    | type | possible_keys            | key     | key_len | ref   | rows   | Extra                       |
+----+-------------+----------+------+--------------------------+---------+---------+-------+--------+-----------------------------+
|  1 | SIMPLE      | table1   | ref  | field1,field3            | field1  | 123     | const | 125832 | Using where; Using filesort |
+----+-------------+----------+------+--------------------------+---------+---------+-------+--------+-----------------------------+

In addition to getting the timing, run EXPLAIN in both environments, and compare. Maybe MariaDB is using a different index, or doing a full scan. Maybe InnoDB statistics aren't up to date... indicating to MariaDB optimizer that the table is empty when it's not.

With that big a difference, I'm inclined to consider that I/O could be a contributor.

Maybe the InnoDB buffer pool is much larger on the MySQL instance than it is on the Mariadb instance. (This isn't a definitive diagnosis. It's just something I would consider.

I'd look at the sizes of the InnoDB buffer cache, and the storage architecture, and verify they are the same on the two servers.

When comparing performance, I would run that same query multiple times on each instance, throw out the time for the first execution, and average the remaining times.

Saying "cloned with his whole database" makes us believe that everything about the database is the same, same storage engine, same indexes, same characterset and collation of character columns, equivalent database configuration, and so on. But maybe our belief isn't warranted.

It's hard to say whether it is a test-case-error, or there is that big a difference between the branches. I'll ramble on about some of the many possibilities (in addition to Spencer's):

Please provide SHOW CREATE TABLE .

Both servers need

INDEX(field1, field2, field4)

with 1 and 2 can be in either order; 4 needs to be last.

Are there any subqueries? That is one area where MySQL and MariaDB have diverged significantly.

The OR is a performance killer; would you like help in using UNION instead?

One of my Rules of Thumb is that caching makes a 10x difference. Those two timings are roughly 10x apart. Could it be that MySQL was working with a warm cache? The simple test is to run both timings twice and take the second one.

What versions of MySQL and MariaDB? Their Optimizers started making significant diversions at 5.6 / 10.0. I have seen big timing differences either way . (And it is not always easy to trace the Optimizer feature that helped.)

Are Virtual or Generated columns involved? That is another area of significant divergence. Or JSON? Did I already ask for SHOW CREATE TABLE ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM