Hi,
I have a problem when searching with cyrillic (utf8) words. The problem results in MySql server crash.
And the crash results in infinte loop in the browser and practically 100% CPU usage and ... >:(
The query sent to the server looks like:
SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon,
GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, GROUP_CONCAT( DISTINCT ntv.value SEPARATOR ", " )
AS tv_value FROM `modx_site_content` sc LEFT JOIN( SELECT DISTINCT tv.id, tv.value, tv.contentid
FROM `modx_site_tmplvar_contentvalues` tv WHERE (((tv.value LIKE ’%тест%’))) ) AS ntv
ON sc.id = ntv.contentid WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0)
AND (sc.type=’document’) AND (sc.privateweb=0))
GROUP BY sc.id HAVING (((sc.pagetitle LIKE ’%тест%’)
OR (sc.longtitle LIKE ’%тест%’)
OR (sc.description LIKE ’%тест%’)
OR (sc.alias LIKE ’%тест%’)
OR (sc.introtext LIKE ’%тест%’)
OR (sc.menutitle LIKE ’%тест%’)
OR (sc.content LIKE ’%тест%’)
OR (tv_value LIKE ’%тест%’)))
ORDER BY sc.publishedon,sc.pagetitle;
The server crashes with:
ERROR 2013 (HY000): Lost connection to MySQL server during query
(The server is 5.0.58 on Centos 5)
The same query with latin search like:
SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon,
GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, GROUP_CONCAT( DISTINCT ntv.value SEPARATOR ", " )
AS tv_value FROM `modx_site_content` sc LEFT JOIN( SELECT DISTINCT tv.id, tv.value, tv.contentid
FROM `modx_site_tmplvar_contentvalues` tv WHERE (((tv.value LIKE ’%test%’))) ) AS ntv
ON sc.id = ntv.contentid WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0)
AND (sc.type=’document’) AND (sc.privateweb=0))
GROUP BY sc.id HAVING (((sc.pagetitle LIKE ’%test%’)
OR (sc.longtitle LIKE ’%test%’)
OR (sc.description LIKE ’%test%’)
OR (sc.alias LIKE ’%test%’)
OR (sc.introtext LIKE ’%test%’)
OR (sc.menutitle LIKE ’%test%’)
OR (sc.content LIKE ’%test%’)
OR (tv_value LIKE ’%test%’)))
ORDER BY sc.publishedon,sc.pagetitle;
goes just fine.
After a long search for what could cause the problem I found that following change fixes it:
SELECT sc.id, sc.pagetitle, sc.longtitle, sc.description, sc.alias, sc.introtext, sc.menutitle, sc.content, sc.publishedon,
GROUP_CONCAT( DISTINCT CAST(ntv.id AS CHAR) SEPARATOR "," ) AS tv_id, GROUP_CONCAT( DISTINCT CAST(ntv.value AS CHAR) SEPARATOR ", " )
AS tv_value FROM `modx_site_content` sc LEFT JOIN( SELECT DISTINCT tv.id, tv.value, tv.contentid
FROM `modx_site_tmplvar_contentvalues` tv WHERE (((tv.value LIKE ’%тест%’))) ) AS ntv
ON sc.id = ntv.contentid WHERE ((sc.published=1) AND (sc.searchable=1) AND (sc.deleted=0)
AND (sc.type=’document’) AND (sc.privateweb=0))
GROUP BY sc.id HAVING (((sc.pagetitle LIKE ’%тест%’)
OR (sc.longtitle LIKE ’%тест%’)
OR (sc.description LIKE ’%тест%’)
OR (sc.alias LIKE ’%тест%’)
OR (sc.introtext LIKE ’%тест%’)
OR (sc.menutitle LIKE ’%тест%’)
OR (sc.content LIKE ’%тест%’)
OR (tv_value LIKE ’%тест%’)))
ORDER BY sc.publishedon,sc.pagetitle;
And changing accordingly search.class.inc.php the search is working fine.
I don’t know what exactly is causing the problem, I think it is related to tv_value LIKE... and the text and char types and utf8. May be there is more precise solution, but I hope my findings will help to resolve this issue.
Regards