You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add one more dimension for grouping marks maintenance.
ideas come from MySQL's support for grouping(a,b,c,...) with maximum of 64 parameters.
mysql> select grouping(a,b), grouping(a), grouping(b) from t group by a, b with rollup;
+---------------+-------------+-------------+
| grouping(a,b) | grouping(a) | grouping(b) |
+---------------+-------------+-------------+
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 3 | 1 | 1 |
+---------------+-------------+-------------+
5 rows in set (0.00 sec)
mysql> select grouping(b,a), grouping(a), grouping(b) from t group by a, b with rollup;
+---------------+-------------+-------------+
| grouping(b,a) | grouping(a) | grouping(b) |
+---------------+-------------+-------------+
| 0 | 0 | 0 |
| 2 | 0 | 1 |
| 0 | 0 | 0 |
| 2 | 0 | 1 |
| 3 | 1 | 1 |
+---------------+-------------+-------------+
5 rows in set (0.00 sec)
Notice the result difference of grouping(a,b) and grouping(b,a)!
mysql reference
As seen here, if GROUPING (a,b) returns 3, it means that NULL in column “a” and NULL in column “b” for that row is produce by a ROLLUP operation. If result is 1, NULL in column “b” alone is a result of ROLLUP operation. https://dev.mysql.com/blog-archive/mysql-8-0-grouping-function/
when evaluating the grouping function's value, the formula is:
the left shift size is exactly according to their listed position in the grouping function.
so we should maintain all the grouping marks (for every single col) down, and add one more round computation for the left shift plus if the len(groupingMarks) is greater than 1 (means multi col args in grouping function).
The text was updated successfully, but these errors were encountered:
Enhancement
add one more dimension for grouping marks maintenance.
ideas come from MySQL's support for grouping(a,b,c,...) with maximum of 64 parameters.
Notice the result difference of grouping(a,b) and grouping(b,a)!
mysql reference
As seen here, if GROUPING (a,b) returns 3, it means that NULL in column “a” and NULL in column “b” for that row is produce by a ROLLUP operation. If result is 1, NULL in column “b” alone is a result of ROLLUP operation.
https://dev.mysql.com/blog-archive/mysql-8-0-grouping-function/
when evaluating the grouping function's value, the formula is:
grouping(a,b,c) = grouping(a)<<2 + grouping(b)<<1 << grouping(c)
the left shift size is exactly according to their listed position in the grouping function.
so we should maintain all the grouping marks (for every single col) down, and add one more round computation for the left shift plus if the len(groupingMarks) is greater than 1 (means multi col args in grouping function).
The text was updated successfully, but these errors were encountered: