Is there a performance difference when grouping by different data types? For instance, if I group by INT, will I get better performance than if I group by varchar?
Int comparisons are faster than varchar comparisons, for the simple fact that ints take up much less space than varchars. This holds true both for unindexed and indexed access. The fastest way to go is an indexed int column.
Integer is for numbers, and varchar is for numbers, letters and other characters (Short text). So for age you can use a int type, for genders you can use the enum() type if there are only two options. Varchar is text and integer is number.
GROUP BY performs better if you keep the number of grouping columns small. Avoid grouping redundant columns by using set functions. When you're grouping joined tables, reduce before you expand. You can make a join happen late by replacing it with a set operator.
The GROUP BY clause restricts the rows of the result; only one row appears for each distinct value in the grouping column or columns.
I would say GROUP BY INT is faster, as only 4 bytes are checked verses n bytes in a varchar field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With