I have a MySQL database with InnoDB tables summing up over 10 ten GB of data that I want to migrate from MySQL 5.5 to MySQL 5.7. And I have a query that looks a bit like:
I too faced slow query execution issue after migrating to mysql 5.7 and in my case, even setting session optimizer_switch to 'derived_merge=off'; didn't help.
Then, I followed this link: https://www.saotn.org/mysql-innodb-performance-improvement/ and the query's speed became normal.
To be specific my change was just setting these four parameters in my.ini as described in the link:
innodb_buffer_pool_size
innodb_buffer_pool_instances
innodb_write_io_threads
innodb_read_io_threads
As can be read in the comments, @wchiquito has suggested to look at the optimizer_switch
. In here I found that the switch derived_merge
could be set to off, to fix this new, and in this specific case undesired, behaviour.
set session optimizer_switch='derived_merge=off';
fixes the problem.
(This can also be done with set global ...
or be put in the my.cnf / my.ini)
Building and maintaining a "Summary Table" would make this query run much faster than even 1 second.
Such a table would probably include shop_id
, date
, and some count.
More on summary tables.