As the title suggests we are getting brutal perfomance migrating a server from 5.6 to 5.7.29. I have been tasked with migrating a few dozen Drupal sites from SUSE servers running 5.6 to Ubuntu runnning 5.7.29 which is a pain in itself, but for one specific site the DB is dying. The site uses taxonomy to categorize content and it does create some overhead, but I have run several tests on different servers we are running in both production and staging as well as Docker.
On 5.7 queries take about 100 times longer or around 10-15 seconds depending on the machine, whilst the 5.6 system takes between 80-120 ms. I know the query is ugly and could definitely be improved, but it is not really an option and outside the scope of the task. It's a CMS and I'm wondering if there is a way to force MySQL to use a specific query optimization technique. Also, this is just one of many queries that are crippling on this site and they are all related to the taxonomies.
I can create fresh containers from docker for either image, import a dump and I get the same behavior.
docker run -p 127.0.0.1:3306:3306/tcp --name mysql5.6 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.6
docker run -p 127.0.0.1:3307:3306/tcp --name mysql5.7 -e MYSQL_ROOT_PASSWORD=password -d mysql:5.7
Anyone, first of all, knows why it is behaving like this and are there any server or table wide solutions?
Explain Visuals + Table + Indexes
Query
SELECT DISTINCT node.nid AS nid, node.title AS node_title, node.created AS node_created,
ttdn.name AS ttdn_name, ttdn.vid AS ttdn_vid,
ttdn.tid AS ttdn_tid, ttdn_tv.machine_name AS ttdn_tv_machine_name,
node.sticky AS node_sticky,
'node' AS field_data_field_top_image_node_entity_type,
'node' AS field_data_field_summary_node_entity_type,
'node' AS field_data_body_node_entity_type,
'node' AS field_data_field_tags_node_entity_type
FROM node
LEFT JOIN (
SELECT td.*, tn.nid AS nid
FROM taxonomy_term_data td
LEFT JOIN taxonomy_vocabulary tv ON td.vid = tv.vid
LEFT JOIN taxonomy_index tn ON tn.tid = td.tid
WHERE (tv.machine_name IN ('news_categories'))
AND (td.tid IN ('10', '21','23', '24', '25', '26', '27', '28',
'31', '32', '33'/*.. some data removed for brevity*/))) ttdn
ON node.nid = taxonomy_term_data_node.nid
LEFT JOIN taxonomy_vocabulary ttdn_tv ON ttdn.vid = ttdn_tv.vid
WHERE (((node.status = '1')
AND (node.type IN ('news_feed', 'www_news_releases_feed', 'article', 'www_rru_in_the_media_feed')) ))
AND ( EXISTS (
SELECT na.nid AS nid
FROM node_access na
WHERE (( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '1')
AND (na.realm = 'taxonomy_access_role') ))AND (na.grant_view >= '1')
AND (node.nid = na.nid) ))
ORDER BY node_sticky DESC, node_created DESC LIMIT 1 OFFSET 0
set optimizer_switch="derived_merge=off";