title: How to speed up my MySQL query?
body: <p>I have this mysql query on a Database with 2700 records:</p>
  
  <pre><code>SELECT  
       inventura.Meno,
       inventura.DOD,
       inventura.IDproluc,
       inventura.IDbuxus,
       inventura.SM,
       inventura.cena,
       inventura.PocetBA,
       inventura.RezervacieBA,
       inventura.SkladBA,
       inventura.ShopBA,
       SUM(CASE WHEN objednavky.miesto = 'BA' OR objednavky.miesto = 'POST' THEN objednavky.ks ELSE 0 END) as cakajuciba,
       inventura.PocetBB,
       inventura.RezervacieBB,
       SUM(CASE WHEN objednavky.miesto = 'BB' THEN objednavky.ks ELSE 0 END) as cakajucibb 
  
       FROM inventura         
  
       LEFT JOIN objednavky
       ON (inventura.IDproluc=objednavky.hra) AND (objednavky.vybavene='0')         
  
       WHERE (true) // normally a condition goes here, this is when nothing is being searched for
       GROUP BY inventura.IDproluc
       ORDER BY inventura.meno ASC 
  </code></pre>
  
  <p>The problem is it takes roughly 30-50 seconds to recieve the results, which is, I believe, far too long.</p>
  
  <p>This query is used to search for a phrase in the collumn 'Meno', but if the search box is left empty, it displays whole table.</p>
  
  <p>It needs to show the whole table, so displaying x rows is not an option.</p>
  
  <p><strong>Could anybody please help me with some ideas how to speed it up?</strong></p>
  
  <p>I have googled for some time but was unable to find something that would help me.</p>
  
  <p><br /><br />
  <strong>More info:</strong></p>
  
  <p>The database is Mysql 5.1,</p>
  
  <p>PHP version 5.4</p>
  
  <p>Function that pulls the data - <code>$result = mysql_query($sql)</code> (it's an older code, when I wrote it mysql functions were not deprecated yet)</p>
  
  <p>The function pulls the data and then stores it to a multi-array to be later processed. (the processing itself takes nearly no time)</p>
  
  <hr>
  
  <p>Edit:
  result of EXPLAIN:</p>
  
  <pre><code>id  select_type   table      type    possible_keys  key key_len ref rows    Extra
  1   SIMPLE        inventura  ALL                                    2699    Using temporary; Using filesort
  1   SIMPLE        objednavky ALL                                    2264
  </code></pre>