Skip to main content
2 of 6
added 191 characters in body

Phpkb Query Optimization

Running a phpkb CMS on a ubuntu lamp server. mysql - 5.5.28-0ubuntu0.12.04.3-log

The tables in this database are not large in fact I have not found one over 10k rows.

Every five min I get a 'copy to temp table' query that hangs out on the server and locks tables. It brings the site to a stand still. Mysql takes 100% of one of the four cores on the server sometimes over I assume taking resources from the other cores. It still hangs.

I have made a ram disk as suggested in other threads and still no performance gains. I'm starting to think it's just going to come down to query optimization for the one that hangs. This seems to be the query that kills it from show full processlist; I also have logged slow queries to the mysql logs and this is the one that shows up over and over.

# Query_time: 152.569759  Lock_time: 0.000075 Rows_sent: 1181 Rows_examined: 383893921
use newkbdb;
SET timestamp=1461243155;

SELECT 
  phpkb_articles.article_id AS article_id, 
  article_title, 
  article_content, 
  article_status, 
  article_date_time, 
  SUM(phpkb_article_visits.article_hits) AS article_hits 
FROM 
  phpkb_articles 
  LEFT OUTER JOIN phpkb_article_visits ON (phpkb_article_visits.article_id 
  =phpkb_articles.article_id), phpkb_relations 
WHERE  
  article_show='yes' 
  AND (phpkb_relations.article_id = phpkb_articles.article_id) 
  AND article_status IN ('featured','approved')   
  AND ( (article_expiry_date = '0000-00-00') OR (article_expiry_date <>    
  '0000-00-00' AND article_expiry_date >= now()) ) 
  AND category_id=221 GROUP BY (phpkb_articles.article_id) 
ORDER BY 
  FIELD(article_status,'featured','approved'), 
  article_title ASC;

Any suggestions or help appreciated I'm not a mysql dba this is just a unicorn site that some dept bought and now its become a huge dependency.

Thanks in advance.

UPDATE: enter image description here

enter image description here