query extremely slow after migration to mysql 5.7

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.