mysql cpu overload

Permalink
When monitoring my sql process, it's constantly hitting >100%
It seems to be related to this query.
Any suggestions?
Thanks.

select p1.cID, pt.ctHandle from Pages p1 left join Pages p2 on (p1.cPointerID = p2.cID) left join PageTypes pt on (pt.ctID = (if (p2.cID is null, p1.ctID, p2.ctID))) left join PagePaths on (PagePaths.cID = p1.cID and PagePaths.ppIsCanonical = 1) left join PageSearchIndex psi on (psi.cID = if(p2.cID is null, p1.cID, p2.cID)) inner join CollectionVersions cv on (cv.cID = if(p2.cID is null, p1.cID, p2.cID) and cvID = (select cvID from CollectionVersions where cvIsApproved = 1 and cID = cv.cID)) inner join Collections c on (c.cID = if(p2.cID is null, p1.cID, p2.cID)) left join CollectionSearchIndexAttributes on (CollectionSearchIndexAttributes.cID = if (p2.cID is null, p1.cID, p2.cID)) where 1=1 and (p1.cParentID in ('320','-1')) and cvIsApproved = '1' and (p1.cIsTemplate = 0 or p2.cIsTemplate = 0) and ((select count(cID) from PagePermissions pp1 where pp1.cID = if(p2.cID is null, p1.cInheritPermissionsFromCID, p2.cInheritPermissionsFromCID) and
((pp1.cgPermissions like 'r%' and cv.cvIsApproved = 1) or (pp1.cgPermissions like '%rv%')) and (
(pp1.gID in (1) or pp1.uID = -1)
and
(pp1.cgStartDate is null or pp1.cgStartDate <= '2011-12-22 19:19:09')
and
(pp1.cgEndDate is null or pp1.cgEndDate >= '2011-12-22 19:19:09')
)) > 0 or (p1.cPointerExternalLink !='' AND p1.cPointerExternalLink IS NOT NULL )) and (p1.cID not in (5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,55,75,76,77,78,79,80,81,82,83,183,184,185,186,187,213,223,321,322,323,324,325,326,327,328,329,330,379,380,381,382,383,427) or p2.cID not in (5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,47,48,49,50,51,52,53,54,55,75,76,77,78,79,80,81,82,83,183,184,185,186,187,213,223,321,322,323,324,325,326,327,328,329,330,379,380,381,382,383,427))

maartenfb
 
fastcrash replied on at Permalink Reply
fastcrash
maartenfb, where is this query come from? its sure really quite complecated query, if it come from core can we make it more simple?

and how you can echo this query?

thanks
maartenfb replied on at Permalink Reply
maartenfb
It's a core query, but when running it from a sql tool it executes fast..
I think the lag is caused by what I've posted here:
http://www.concrete5.org/community/forums/installation/require_once...

Thanks for replying anyway.