Keyword

Slow SQL in itemlist

  • Amir Bukhari
  • Amir Bukhari's Avatar Topic Author
  • Offline
  • New Member
More
8 years 11 months ago #148353 by Amir Bukhari
Slow SQL in itemlist was created by Amir Bukhari
for my front page i use the category menu item from K2.
the following SQL got executed and it take more than 11 sec
SELECT i.*, c.name as categoryname,c.id as categoryid, c.alias as categoryalias, c.params as categoryparams 
  FROM t0nbl_k2_items as i RIGHT JOIN t0nbl_k2_categories AS c 
  ON c.id = i.catid 
  WHERE i.published = 1 
  AND i.access IN(1,1,5) 
  AND i.trash = 0 
  AND c.published = 1 
  AND c.access IN(1,1,5) 
  AND c.trash = 0 
  AND c.language IN ('ar-AA','*') 
  AND i.language IN ('ar-AA','*') 
  AND ( i.publish_up = '0000-00-00 00:00:00' OR i.publish_up <= '2015-10-14 07:10:28' ) 
  AND ( i.publish_down = '0000-00-00 00:00:00' OR i.publish_down >= '2015-10-14 07:10:28' ) 
  ORDER BY i.id DESC 
  LIMIT 0, 14 

and here is the stacktrace from the debuger
JROOT/components/com_k2/models/itemlist.php:357
JROOT/components/com_k2/views/itemlist/view.html.php:376
JROOT/libraries/legacy/controller/legacy.php:693
JROOT/components/com_k2/controllers/controller.php:20
JROOT/components/com_k2/controllers/itemlist.php:49
JROOT/libraries/legacy/controller/legacy.php:730
JROOT/components/com_k2/k2.php:63
JROOT/libraries/cms/component/helper.php:352
JROOT/libraries/cms/component/helper.php:332
JROOT/libraries/cms/application/site.php:191
JROOT/libraries/cms/application/site.php:237
JROOT/libraries/cms/application/cms.php:251
JROOT/index.php:40

any advice how optimize this.

more info:
it seams none of the indexes are used because for c table it use "Using where; Using temporary, filesort" and for i "Using where"

Please Log in or Create an account to join the conversation.

More
8 years 11 months ago #148410 by Lefteris
Replied by Lefteris on topic Slow SQL in itemlist
Hi,

If you try to use EXPLAIN on this query you will see that indexes are used.

SQL queries optimization is a hard process which requires deep knowledge about MySQL internals.

For your case you can simply create an index on all fields of #__k2_items table involved in that query ( id, published, access, trash, language, publish_up, publish_down) .

Note that this will cover the part of the query related with the #__k2_items table.

Also make sure that you have enabled Joomla! caching as well as the "System - Cache" plugin in order to speed up your site.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum