2016-05-20 12 views
0

Ich habe die folgende Abfrage, die mehr als 20 Sekunden (20138ms) dauert, um die Ergebnisse zurückzugeben.Verbindung Tabellen dauert sehr lange symfony 2.7

$locale = 'en'; // test 

$query = $this->getEntityManager()->createQuery(' 
     SELECT 
     product.id, product.productnr, ProductGrp.productgrp' . $locale . ', Criteria.criteria'.$locale.' 
     FROM 
      Productbundle:product product 
     JOIN 
      Productbundle:Criteria Criteria WITH Criteria.criteriaid = product.criteriaid 
     JOIN 
      Productbundle:ProductGrp ProductGrp WITH ProductGrp.partgrpid = product.partgrpid 
     WHERE 
      product.productnr =:productnr 
     ') 
     ->setMaxResults(1) 
     ->setParameter('productnr', $productnr) 
     ->getResult(); 

wenn ich die Abfrage von "runnable Abfrage" lief es dauerte etwa 20 Sekunden (20,7809) in phpMyAdmin.

runnable query:

SELECT o0_.id AS id0, o0_.productnr AS productnr1, o1_.productgrpen AS productgrpen2, o2_.criteriaen AS criteriaen3 
FROM product o0_ 
INNER JOIN Criteria o2_ ON (o2_.criteriaid = o0_.criteriaid) 
INNER JOIN ProductGrp o1_ ON (o1_.partgrpid = o0_.partgrpid) 
WHERE o0_.productnr = 'ABC1234' 
LIMIT 1; 

Jedoch, wenn ich den folgenden Code in phpMyAdmin lief dauert es weniger als 2 Sekunden die Ergebnisse

SELECT product.id, product.productnr,ProductGrp.productgrpen ,Criteria.criteriaen 
FROM `product` 
INNER JOIN ProductGrp ON ProductGrp.partgrpid = product.partgrpid 
INNER JOIN Criteria ON Criteria.criteriaid = product.criteriaid 
Where productnr = 'ABC1234' 
LIMIT 1 

Tischgroesse

------------------------------- 
|Product | over 5mill rows | 
------------------------------- 
|ProductGrp | over 200 rows | 
------------------------------- 
|Criteria | over 600 rows | 
------------------------------- 

Symfony Version zurückkehren : 2,7

+0

Können Sie beide Abfragen (EXPLAIN) (http://dev.mysql.com/doc/refman/5.7/en/explain.html) und teilen Sie das Ergebnis mit uns? – xabbuh

+0

Versuchen Sie auch, phpadmin mit SQL_NO_CACHE auszuführen (http://dev.mysql.com/doc/refman/5.7/en/query-cache-in-select.html) – ScayTrase

Antwort

0

Indizes obwohl nicht aufgeführt ist, würde ich die folgenden

table  indexed on 
Product (productnr, id, criteriaid, partgrpid) 
Criteria (criteriaid) -- would expect as primary key 
ProductGrp (partgrpid) -- also would expect 

auch vorschlagen, wie viele "locale" string Version Spalten haben Sie/support.

Verwandte Themen