title: MySQL GROUP BY performance issue
body: <p>This is the query I'm performing (without some Joins that are not relevant):</p>
  
  <pre><code>SELECT a.*, c.id
  FROM a
  LEFT OUTER JOIN b ON a.id = b.id_anunciante
  LEFT OUTER JOIN c ON c.id = b.id_rubro
  GROUP BY a.id
  </code></pre>
  
  <p>Each row of "a" is linked with 1 to 5 rows in "b".</p>
  
  <p>The problem is that GROUP BY has performance issues (it takes 10x or more using GROUP BY than not using it). I need to retrieve only one row of each member in "a".</p>
  
  <p>How can I make this faster?</p>
  
  <p>edit: I need to be able to filter by a.id AND/OR c.id. The resultset I should be getting is only 1 row per "valid" member of "a", meaning the rows that match the constraints. Rows that don't match the filters shouldn't be returned.
  In my original query, this would be done this way:</p>
  
  <pre><code>SELECT a.*, c.id
  FROM a
  LEFT OUTER JOIN b ON a.id = b.id_anunciante
  LEFT OUTER JOIN c ON c.id = b.id_rubro
  WHERE c.id = 1
  OR a.id = 1
  GROUP BY a.id
  </code></pre>
  
  <p>a.id, b.id_anunciante, b.id_rubro, c.id are all indexes.</p>