Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: refactor grouping function computation and update related tipb #44436

Merged
merged 6 commits into from
Jun 7, 2023

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Jun 6, 2023

What problem does this PR solve?

Issue Number: close #44437

related tiflash issue : pingcap/tiflash#7590

related tipb pr: pingcap/tipb#308

Problem Summary:

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:

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).

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

expression: refactor grouping function computation and update related tipb

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. labels Jun 6, 2023
@ti-chi-bot ti-chi-bot bot requested a review from mornyx June 6, 2023 07:08
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-linked-issue labels Jun 6, 2023
@AilinKid AilinKid requested review from xzhangxian1008 and elsa0520 and removed request for mornyx June 6, 2023 07:40
@guo-shaoge
Copy link
Collaborator

/approve

@ti-chi-bot ti-chi-bot bot added the approved label Jun 6, 2023
expression/builtin.go Show resolved Hide resolved
parser/ast/functions.go Show resolved Hide resolved
@xzhangxian1008
Copy link
Contributor

/LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

@xzhangxian1008: adding LGTM is restricted to approvers and reviewers in OWNERS files.

In response to this:

/LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

@AilinKid: you cannot LGTM your own PR.

In response to this:

/LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

@AilinKid: Please do not delete or edit you lgtm type comment!

In response to this:

/LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 7, 2023
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 7, 2023
@AilinKid
Copy link
Contributor Author

AilinKid commented Jun 7, 2023

/retest

1 similar comment
@AilinKid
Copy link
Contributor Author

AilinKid commented Jun 7, 2023

/retest

Signed-off-by: AilinKid <[email protected]>
Signed-off-by: AilinKid <[email protected]>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 7, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Jun 7, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: guo-shaoge, wshwsh12, XuHuaiyu, xuyifangreeneyes, xzhangxian1008

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [XuHuaiyu,guo-shaoge,wshwsh12,xuyifangreeneyes]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 7, 2023
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 7, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-06-07 06:16:58.058440332 +0000 UTC m=+71709.903074915: ☑️ agreed by xuyifangreeneyes.
  • 2023-06-07 08:06:40.459919067 +0000 UTC m=+78292.304553664: ☑️ agreed by wshwsh12.
  • 2023-06-07 09:25:30.056175764 +0000 UTC m=+83021.900810362: ✖️🔁 reset by AilinKid.
  • 2023-06-07 10:04:50.650058635 +0000 UTC m=+85382.494693234: ☑️ agreed by wshwsh12.
  • 2023-06-07 10:18:18.886247163 +0000 UTC m=+86190.730881761: ☑️ agreed by XuHuaiyu.

@AilinKid
Copy link
Contributor Author

AilinKid commented Jun 7, 2023

/merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expression support for grouping(a,b,c,...) with maximum of 64 parameters
7 participants