I just noticed something veryam having a strange. I had issue with a query that was running quite slow on my database (MariaDB 10.1).
When I copied the same exact database to a new database and ran the same query on that database, it took 10% of the time. Both databases are supposedly identical and on the same SSD drive array.
Note that I forced no caching, I made sure the original database is optimized repaired. What can be the possible causes for this huge discrepancy and how can they be verified and fixed?
EDIT: The databases are using the MyISAM engine.
Here are the EXPLAIN EXTENDED results. Seems like the optimizer is working differently on both tables, but that doesn't really explain why that happens, as the copied database is supposedly identical.
These are the screenshots of the profiling of the query on the slow and fast databaseunder certain conditions:
EDIT 2:
II have made a few more tests and was able to isolate the issue to one single table called products_description
(all the tables are MyISAM).
WhenAt first I noticed that when this table is copied from the original database to the copied databasenew (ie. just imported), the query always performs fast (~0.3s).
However, if I perform any of these operations on this specific table, at any time (even immediately after importing it):
CHECK
, OPTIMIZE
, ANALYZE
or REPAIR
, the query suddenly slows down x10 times (takes ~4.5s) and keeps staying always slow.
Note that I am ableforced no-caching when running the query to restoreensure the performance only if I am then performing any of these operations:results are correct.
I am able to restore the performance only if I am then performing any of these operations on that table:
DROP
the table and copyimport it again from the old database.
ALTER
any of the following of that table:Collation
orCHECKSUM
orDELAY_KEY_WRITE
. TestedIt then runs fast with the altered valuesvalue and when reverting back to the old value, the performance remains fast.
Even then, if I perform any of the CHECK
, OPTIMIZE
, ANALYZE
or REPAIR
operations on that table, the query speed drops until I do either 1) or 2)
One more thing I tested:
After I copied the table from the old db to the new, beforeBefore performing any operation on itthe table, I backed up the table's files (products_description.frm
, products_description.MYD
, products_description.MYI
), ran the query, it ran fast. Then I performed CHECK
on the table, ran the query, speed was x10 times slower, I copied the backed up files and overwrote the 3 files, ran the query again, slow speed again.
EDIT 3:
This is the SQL query that I am running and you should test with is:
Here are the EXPLAIN EXTENDED results. Seems like the optimizer is working differently on both tables, but that doesn't really explain why that happens, as the copied database is supposedly identical.
These are the screenshots of the profiling of the query on the slow and fast database:
What can be the possible causes for this huge discrepancy and how can they be verified and fixed?