# Slow Queries - woher?

**URL:** <https://forum.shopware.com/t/slow-queries-woher/48455>\
**Category:** Programmierung\
**Created:** [24. September 2017 um 19:50 UTC](https://forum.shopware.com/t/slow-queries-woher/48455 "2017-09-24T19:50:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Misengo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/misengo/32/21446_2.png) [@Misengo](https://forum.shopware.com/u/Misengo)\
**Post date:** [24. September 2017 um 19:50 UTC](https://forum.shopware.com/t/slow-queries-woher/48455/1 "2017-09-24T19:50:33Z")

</div>

Ich habe eine Kategorie welche den Server immer wieder zum Absturz bringt (Oberkategorie) sobald Last auf den Server kommt und der Cache nicht aufgewärmt ist. Habe mir das ganze mal mit JMeter angeschaut (50 Req. innerhalb einer Sekunde) und alle anderen Kategorien brauchen 2-3 Sekunden und volle CPU Last. Nur diese eine (7000 Produkte (die anderen ca. 3500-4500) ) tickt aus und die CPU hängt sich ziemlich auf und brauch 60-70sek um von 100% Last runter zukommen (I7 Intel Quadcore @ 3.4GHZ).

Dazu das passende Slow Query was ich erhalte - interessant, dass mir die den max Preis ausgibt (min in der Kategorie ist 0.90€ und Max ist 3784€) - jemand eine Idee?

> # Time: 2017-09-24T19:22:42.769898Z
> 
> # User@Host: root[root] @ localhost &nbsp;Id: 12995
> 
> # Query\_time: 14.137540 &nbsp;Lock\_time: 0.005553 Rows\_sent: 1 &nbsp;Rows\_examined: 722803
> 
> SET timestamp=1506280962;  
> SELECT MIN(ROUND(IFNULL(customerPrice.price, defaultPrice.price) \* ((100 - IFNULL(priceGroup.discount, 0)) / 100) \* (( (CASE tax.id &nbsp;WHEN 1 THEN 19 &nbsp;WHEN 4 THEN 7 &nbsp;WHEN 5 THEN 2.5 &nbsp;WHEN 6 THEN 8 &nbsp;WHEN 7 THEN 0 END) + 100) / 100) \* 1, 2)) as cheapest\_price FROM s\_articles product INNER JOIN s\_articles\_details variant ON variant.id = product.main\_detail\_id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND variant.active = 1  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND product.active = 1 INNER JOIN s\_core\_tax tax ON tax.id = product.taxID INNER JOIN s\_articles\_categories\_ro productCategory3 ON productCategory3.articleID = product.id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AND productCategory3.categoryID IN (5406) LEFT JOIN s\_articles\_avoid\_customergroups avoidCustomerGroup ON avoidCustomerGroup.articleID = product.id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND avoidCustomerGroup.customerGroupId IN (53) INNER JOIN s\_articles\_details availableVariant ON availableVariant.articleID = product.id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND availableVariant.active = 1 &nbsp;LEFT JOIN s\_core\_pricegroups\_discounts priceGroup ON priceGroup.groupID = product.pricegroupID  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND priceGroup.discountstart = (SELECT MAX(discountstart) FROM s\_core\_pricegroups\_discounts subPriceGroup WHERE subPriceGroup.id = priceGroup.id AND subPriceGroup.customergroupID = ‚53‘)  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND priceGroup.customergroupID = ‚53‘  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND product.pricegroupActive = 1 INNER JOIN s\_articles\_prices defaultPrice ON defaultPrice.articledetailsID = availableVariant.id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND defaultPrice.pricegroup = ‚EK‘  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND IF(priceGroup.id IS NOT NULL, defaultPrice.from = 1, defaultPrice.to = ‚beliebig‘) LEFT JOIN s\_articles\_prices customerPrice ON customerPrice.articleID = product.id  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND customerPrice.pricegroup = ‚HP-EK‘  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND IF(priceGroup.id IS NOT NULL, customerPrice.from = 1, customerPrice.to = ‚beliebig‘)  
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AND availableVariant.id = customerPrice.articledetailsID INNER JOIN s\_articles\_attributes productAttribute ON productAttribute.articledetailsID = variant.id WHERE avoidCustomerGroup.articleID IS NULL GROUP BY product.id ORDER BY cheapest\_price DESC LIMIT 1 OFFSET 0;  
> &nbsp;

---

<div class="post-metadata">

**Author:** ![Misengo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/misengo/32/21446_2.png) [@Misengo](https://forum.shopware.com/u/Misengo)\
**Post date:** [24. September 2017 um 20:12 UTC](https://forum.shopware.com/t/slow-queries-woher/48455/2 "2017-09-24T20:12:40Z")

</div>

Die Frage ist auch warum so ein Query beim initialen Aufruf der Kategorie aufgerufen wird. Ist das die Standardsortierung?

&nbsp;

PS: Habe zum testen ALLE Plugins deaktiviert und nutze das Responsive Template.

&nbsp;

SW Version 5.2.22

---

<div class="post-metadata">

**Author:** ![SW5Nutzer](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@SW5Nutzer](https://forum.shopware.com/u/SW5Nutzer)\
**Post date:** [24. September 2017 um 21:02 UTC](https://forum.shopware.com/t/slow-queries-woher/48455/3 "2017-09-24T21:02:46Z")

</div>

Hatte ich auch mal, es hat auch noch zu jede Menge 500er errors in der Google Console geführt.

Ich habe im MySQL den optimizer\_search\_depth auf 0 gesetzt und das Problem war weg.

Der Datenbank war beim iterieren der Attribute und Filter völlig überlastet gewesen.

&nbsp;

Probier mal.

---

<div class="post-metadata">

**Author:** ![Misengo](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/misengo/32/21446_2.png) [@Misengo](https://forum.shopware.com/u/Misengo)\
**Post date:** [25. September 2017 um 07:57 UTC](https://forum.shopware.com/t/slow-queries-woher/48455/4 "2017-09-25T07:57:19Z")

</div>

> [@SW5Nutzer schrieb:](https://forum.shopware.com/profile/24118/SW5Nutzer "SW5Nutzer")
> 
> Hatte ich auch mal, es hat auch noch zu jede Menge 500er errors in der Google Console geführt.
> 
> Ich habe im MySQL den optimizer\_search\_depth auf 0 gesetzt und das Problem war weg.
> 
> Der Datenbank war beim iterieren der Attribute und Filter völlig überlastet gewesen.
> 
> &nbsp;
> 
> Probier mal.

&nbsp;

Damit hatten wir schonmal rumgespielt - allerdings wurden dann andere Queries langsamer. Bzw. die PLT ging hoch.

Hast du das nur für ein Query umgesetzt?&nbsp;
