It's possible to improve the performance of the GROUP BY function by carefully ordering a list of fields within the GROUP BY in an order of high cardinality.

SQL Example

 

good

SELECT GROUP BY uid, gender

bad

SELECT GROUP BY gender, uid

Or, use numbers instead of strings for the GROUP BY column, because numbers require less memory and are faster to compare than strings.

  • No labels