Optimize the group by statement

Optimize the group by statement

Because GROUP BY actually also performs sorting operations, and compared with ORDER BY, GROUP BY is mainly just a grouping operation after sorting.

Of course, if some other aggregation functions are used when grouping, then some aggregation function calculations are needed.

Therefore, in the implementation of GROUP BY, indexes can also be used just like ORDER BY.

If the query contains group by but the user wants to avoid the consumption of sorting results, you can execute order by null to prohibit sorting. as follows:




Guess you like

Origin blog.csdn.net/qq_39368007/article/details/114699384