Jump to content

Very Poor Perfomance On Sql Querys [Solved]


Toni Mármol

Recommended Posts

My setup:

 

PrestaShop Version 1.6.1.4
PHP Version 5.6.18 (OK)
MySQL Version 10.1.11-MariaDB (OK)
Memory Limit 128M
Max Execution Time 30s
Smarty Cache enabled
Smarty Compilation never recompile
 
Dedicated server with no load.
 
With the db profiling activated:
 
Query
SELECT SQL_NO_CACHE a.`id_product`, b.`name` AS `name`, `reference`, a.`price` AS `price`, sa.`active` AS `active`
, shop.`name` AS `shopname`, a.`id_shop_default`, image_shop.`id_image` AS `id_image`, cl.`name` AS `name_category`, sa.`price`, 0 AS `price_final`, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` AS `sav_quantity`, sa.`active`, IF(sav.`quantity`<=0, 1, 0) AS `badge_danger`
FROM `ps13_product` a 
LEFT JOIN `ps13_product_lang` b ON (b.`id_product` = a.`id_product` AND b.`id_lang` = 3 AND b.`id_shop` = 1)
LEFT JOIN `ps13_stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
AND sav.id_shop = 1  AND sav.id_shop_group = 0 )  JOIN `ps13_product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default)
LEFT JOIN `ps13_category_lang` cl ON (sa.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
LEFT JOIN `ps13_shop` shop ON (shop.id_shop = a.id_shop_default)
LEFT JOIN `ps13_image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = a.id_shop_default)
LEFT JOIN `ps13_image` i ON (i.`id_image` = image_shop.`id_image`)
LEFT JOIN `ps13_product_download` pd ON (pd.`id_product` = a.`id_product`) 
WHERE 1  
ORDER BY a.`id_product` desc  LIMIT 0, 50
 
Time (ms)
26294.2
 
Rows
20528640
 
Filesort
Yes
 
Location
/classes/controller/AdminController.php:3207
 
 
 
I get 5351 products on the table.
 
 
Tried the same query directly in phpMyAdmin and the time is 24.6610 sec (24661 ms). 
 
 
 
 
 
I have another slow query. The same query, but with the COUNT(*):
 
SELECT SQL_NO_CACHE COUNT(*) AS `ps13_product` 
FROM `ps13_product` a 
LEFT JOIN `ps13_product_lang` b ON (b.`id_product` = a.`id_product` AND b.`id_lang` = 3 AND b.`id_shop` = 1)
LEFT JOIN `ps13_stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
AND sav.id_shop = 1  AND sav.id_shop_group = 0 )  JOIN `ps13_product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default)
LEFT JOIN `ps13_category_lang` cl ON (sa.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
LEFT JOIN `ps13_shop` shop ON (shop.id_shop = a.id_shop_default)
LEFT JOIN `ps13_image_shop` image_shop ON (image_shop.`id_product` = a.`id_product` AND image_shop.`cover` = 1 AND image_shop.id_shop = a.id_shop_default)
LEFT JOIN `ps13_image` i ON (i.`id_image` = image_shop.`id_image`)
LEFT JOIN `ps13_product_download` pd ON (pd.`id_product` = a.`id_product`) 
WHERE 1 LIMIT 1
 
25 sec query.
 
 
 
 
All the other querys are so fast, under 10ms.
 
 
 
 
Do you have any idea because that query is so slow please? I can't work with the products (add, modify) at the backoffice.
 

 

Edited by Toni Mármol (see edit history)
Link to comment
Share on other sites

I don't know how I get that big number. So strange...

 

Here are the numbers of the all tables involved:

 

ps13_product => 5356 rows
ps13_product_lang => 21424 rows
ps13_stock_available => 5351 rows
ps13_product_shop => 5356 rows
ps13_category_lang => 768 rows
ps13_shop => 1 row
ps13_image_shop => 7747 rows
ps13_image => 7747 rows
ps13_product_download => 1 row
Edited by Toni Mármol (see edit history)
Link to comment
Share on other sites

Wow... I've just found the problem.

 

I have some missing UNIQUE keys in 3 tables involved. I think it was due to a bad past update or something.

 

But now it goes like a rocket again:

 

Load Time 843 ms - OK... for a shared hosting
Querying Time 259 ms
Queries 561
Memory Peak Usage 40.1 Mb
Included Files 176 files - 4.28 Mb
PrestaShop Cache - Mb
Global vars 1.63 Mb
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...