Hi there.
I hope someone can shed some light on this.
I have a fairly high end Cloud server which runs several modx sites.
Every so often, the server grinds to a bit of a halt, and when I raise a ticket with the support team they say:
The MySQL service in the server is having a very increased CPU resource consumption, and this accounts for the high load values.
He then refers to several samples queries which they say are causing problems:
| 321208 | database_name | localhost | database_name | Query | 3495 | statistics | SELECT COUNT(DISTINCT `modResource`.`id`) FROM `modx_site_content` AS `modResource` WHERE ( ( modResource.parent IN (137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,169,171,172,173,174,176,177,179,182,189,190,191,192,178,194,195,199,201,187,210,211) AND `modResource`.`deleted` = '0' AND `modResource`.`published` = '1' AND `modResource`.`isfolder` = '0' ) AND ( (EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '%marketing or (1' AND tv.name = 'blogTags' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) OR EXISTS (SELECT 1 FROM `modx_site_tmplvars` tv WHERE tv.name = 'blogTags' AND tv.default_text LIKE '%marketing or (1' AND tv.id NOT IN (SELECT tmplvarid FROM `modx_site_tmplvar_contentvalues` WHERE contentid = modResource.id)) ) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '2)=(select*from(select name_const(CHAR(113' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '118' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '120' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '118' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '74' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '115' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '102' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '99' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '122)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '1)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE 'name_const(CHAR(113' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '118' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '120' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '118' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '74' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '115' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '102' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '99' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '122)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '1))a) -- and 1=1%' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) ) ) | 0.000 |
and
| 321216 | database_name | localhost | database_name | Query | 3493 | statistics | SELECT COUNT(DISTINCT `modResource`.`id`) FROM `modx_site_content` AS `modResource` WHERE ( ( modResource.parent IN (137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,169,171,172,173,174,176,177,179,182,189,190,191,192,178,194,195,199,201,187,210,211) AND `modResource`.`deleted` = '0' AND `modResource`.`published` = '1' AND `modResource`.`isfolder` = '0' ) AND ( (EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '%marketing or (1' AND tv.name = 'blogTags' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) OR EXISTS (SELECT 1 FROM `modx_site_tmplvars` tv WHERE tv.name = 'blogTags' AND tv.default_text LIKE '%marketing or (1' AND tv.id NOT IN (SELECT tmplvarid FROM `modx_site_tmplvar_contentvalues` WHERE contentid = modResource.id)) ) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '2)=(select*from(select name_const(CHAR(119' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '67' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '98' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '105' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '109' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '121' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '108' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '80' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '119' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '88' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '114)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '1)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE 'name_const(CHAR(119' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '67' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '98' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '105' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '109' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '121' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '108' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '80' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '119' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '88' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '114)' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) AND EXISTS (SELECT 1 FROM `modx_site_tmplvar_contentvalues` tvr JOIN `modx_site_tmplvars` tv ON tvr.value LIKE '1))a) -- and 1=1%' AND tv.id = tvr.tmplvarid WHERE tvr.contentid = modResource.id) ) ) | 0.000 |
Then he goes on to say:
Please note that all these "select" queries are very resource intensive and can slow down your operations to a great extent. I would suggest you to check the database table structures and these "select queries" to make sure that the indexes you have in your DB tables correspond to the select operations which you're trying to run. When select/order_by/group_by/join operations are performed on tables with incorrect indexes, MySQL will be forced to create a new temporary table, copy data into it and perform these sorting operations on a temporary table. Such operations might take significant amount of CPU and Disk I/O bandwidth and can dramatically reduce performance of your sites!
I'm just not sure where to go with this?
Does anyone have any advice?
It's happened on two occasions on two separate sites/databases now.
Thanks in advance
Andy