How to speed up slow Slow Queries?

Discussion regarding Joomla! 3.x Performance issues.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
brettiUN
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Sat Mar 05, 2011 12:03 pm

How to speed up slow Slow Queries?

Post by brettiUN » Fri Apr 28, 2023 8:26 am

Hello,

my provider says, that "Slow Querys" are bad for the performance. I havn´t any idea, what I can change. Could somebody help me?

Here the Query:

SELECT a.id, a.title, a.alias, a.introtext, a.fulltext, a.checked_out, a.checked_out_time, a.catid, a.created, a.created_by, a.created_by_alias, CASE WHEN c.published = 2 AND a.state > 0 THEN 2 WHEN c.published != 1 THEN 0 ELSE a.state END as state,CASE WHEN a.modified = '0000-00-00 00:00:00' THEN a.created ELSE a.modified END as modified, a.modified_by, uam.name as modified_by_name,CASE WHEN a.publish_up = '0000-00-00 00:00:00' THEN a.created ELSE a.publish_up END as publish_up,a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, a.hits, a.xreference, a.featured, a.language, LENGTH(a.fulltext) AS readmore, a.ordering,c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias,c.published, c.published AS parents_published, c.lft,CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author,ua.email AS author_email,parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias,COALESCE(NULLIF(ROUND(v.rating_sum / v.rating_count, 0), 0), 0) AS rating,
COALESCE(NULLIF(v.rating_count, 0), 0) as rating_count
FROM kam_content AS a
LEFT JOIN kam_categories AS c ON c.id = a.catid
LEFT JOIN kam_users AS ua ON ua.id = a.created_by
LEFT JOIN kam_users AS uam ON uam.id = a.modified_by
LEFT JOIN kam_categories as parent ON parent.id = c.parent_id
LEFT JOIN kam_content_rating AS v ON a.id = v.content_id
WHERE a.access IN (1,1) AND c.access IN (1,1) AND c.published = 1 AND a.state = 1 AND a.catid IN (26,43,45,46,47,48,49,59,52,53,54,55,57,60,61,63) AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2023-04-27 14:41:22') AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2023-04-27 14:41:22')
ORDER BY a.created DESC LIMIT 5
SELECT COUNT
FROM kam_content AS a
LEFT JOIN kam_categories AS c ON c.id = a.catid
LEFT JOIN kam_users AS ua ON ua.id = a.created_by
LEFT JOIN kam_users AS uam ON uam.id = a.modified_by
LEFT JOIN kam_categories as parent ON parent.id = c.parent_id
LEFT JOIN kam_content_rating AS v ON a.id = v.content_id
WHERE a.access IN (1,1) AND c.access IN (1,1) AND c.published = 1 AND a.state = 1 AND (a.catid = 26 OR a.catid IN (
SELECT sub.id
FROM kam_categories as sub
INNER JOIN kam_categories as this ON sub.lft > this.lft AND sub.rgt < this.rgt
WHERE this.id = 26)) AND (a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2023-04-27 14:41:24') AND (a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2023-04-27 14:41:24')
Last edited by toivo on Fri Apr 28, 2023 8:49 am, edited 1 time in total.
Reason: mod note: moved from 3.x General Questions, retitled

User avatar
AMurray
Joomla! Exemplar
Joomla! Exemplar
Posts: 9799
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: How to speed up slow Slow Queries?

Post by AMurray » Wed May 03, 2023 12:39 am

What type of hosting infrastructure - shared or stand-alone/VPS?

If shared hosting, you're competing with perhaps dozens of other accounts on the same server, that might explain it given the server has to share resources - memory, CPU time and so forth between accounts.

But as to optimising that SQL code, I have no idea sorry.

How is this related to Joomla - in what context are you running this query?
Regards - A Murray
General Support Moderator


Locked

Return to “Performance - Joomla! 3.x”