title: group_concat performance issue in MySQL
body: <p>I added a <code>group_concat</code> to a query and killed the performance. The explain plans are identical before and after I added it, so I'm confused as to how to optimize this.</p>
  
  <p>Here is a simplified version of the query:</p>
  
  <pre><code>SELECT @curRow := @curRow + 1 AS row_number,
  docID,
  docTypeID,
  CASE WHEN COUNT(1) &gt; 1
       THEN group_concat( makeID )
       -- THEN 'multiple makes found'
       ELSE MIN(makeID)
  END AS makeID,
  MIN(desc) AS desc
  FROM simplified_mysql_table,
  (SELECT @curRow := 0) r
  GROUP BY docID, docTypeID,
  CASE WHEN docTypeID = 1
       THEN 0
       ELSE row_number
  END;
  </code></pre>
  
  <p>Note the <code>CASE</code> statement in the <code>SELECT</code>. The <code>group_concat</code> kills performance. If I comment that line and just output 'multiple makes found' it executes very quickly. Any idea what is causing this?</p>