Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Tweeted twitter.com/StackDBAs/status/839448522185396225
Bumped by Community user
Bumped by Community user
deleted 246 characters in body
Source Link

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.

Slow database's EXPLAIN

Fast database's EXPLAIN

These are the screenshots of the profiling of the query on the slow and fast databaseunder certain conditions:

Slow database profiling Fast database profiling

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:

  1. DROP the table and copyimport it again from the old database.
  1. ALTER any of the following of that table: Collation or CHECKSUM or DELAY_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.

Slow database's EXPLAIN

Fast database's EXPLAIN

These are the screenshots of the profiling of the query on the slow and fast database:

Slow database profiling Fast database profiling

What can be the possible causes for this huge discrepancy and how can they be verified and fixed?

I just noticed something very strange. I had 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.

Slow database's EXPLAIN

Fast database's EXPLAIN

These are the screenshots of the profiling of the query on the slow and fast database:

Slow database profiling Fast database profiling

EDIT 2:

I have made a few more tests and was able to isolate the issue to one single table called products_description. When this table is copied from the original database to the copied database, the query always performs fast. However, if I perform any of these operations on this specific table, at any time: CHECK, OPTIMIZE, ANALYZE or REPAIR, the query suddenly slows down x10 times.

I am able to restore the performance only if I am then performing any of these operations:

  1. DROP the table and copy it again from the old database.
  1. ALTER any of the following of that table: Collation or CHECKSUM or DELAY_KEY_WRITE. Tested with the altered values 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, the 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, before performing any operation on it, 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 the SQL query that I am running and you should test with is:

I am having a strange issue with a slow query under certain conditions: I have made a few tests and was able to isolate the issue to one single table called products_description (all the tables are MyISAM). At first I noticed that when this table is new (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 forced no-caching when running the query to ensure the results are correct.

I am able to restore the performance only if I am then performing any of these operations on that table:

  1. DROP the table and import it again.
  1. ALTER any of the following of that table: Collation or CHECKSUM or DELAY_KEY_WRITE. It then runs fast with the altered value 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: Before performing any operation on the 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.

This is the SQL query that I am running and you should test with:

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.

Slow database's EXPLAIN

Fast database's EXPLAIN

These are the screenshots of the profiling of the query on the slow and fast database:

Slow database profiling Fast database profiling

What can be the possible causes for this huge discrepancy and how can they be verified and fixed?

edited title
Link

Possible causes that a MySQL/MariaDB query is slow inunder some table conditions

edited title
Link

Possible causes that a copied MySQL/MariaDB databasequery is faster than originalslow in some conditions

added 8 characters in body
Source Link
Loading
Source Link
Loading