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

executor: group_concat aggr panic when session.group_concat_max_len is small #23131

Merged
merged 5 commits into from
Mar 11, 2021

Conversation

guo-shaoge
Copy link
Collaborator

Signed-off-by: guo-shaoge shaoge1994@163.com

What problem does this PR solve?

Issue Number: close #23129

Problem Summary:

drop table if exists t1;
create table t1(cid int, sname varchar(100));
insert into t1 values(1, 'Bob'), (1, 'Alice');
insert into t1 values(3, 'Ace');
set @@group_concat_max_len=5;
select group_concat(sname order by sname) from t1 group by cid;

What is changed and how it works?

What's Changed: when concat all strings from a group(AppendFinalResult2Chunk), we add the last separator to result, and then truncate to sesssion.group_concat_max_len. But we forgot to check if the concated string is shorter than sesssion.group_concat_max_len. So program panic.

PS: Another compatible bug found when fixing this bug, but it's not critical. Will fix in another issue.

Related changes

  • Need to cherry-pick to the release branch

Check List

Tests

  • Integration test: Add test in aggregate_test.go::TestGroupConcatAggr()

Side effects: no

Release note

  • group_concat aggr panic when session.group_concat_max_len is small.

Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge guo-shaoge requested a review from a team as a code owner March 5, 2021 06:51
@guo-shaoge guo-shaoge requested review from XuHuaiyu and removed request for a team March 5, 2021 06:51
@ti-chi-bot ti-chi-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 5, 2021
@github-actions github-actions bot added the sig/execution SIG execution label Mar 5, 2021
@guo-shaoge
Copy link
Collaborator Author

guo-shaoge commented Mar 5, 2021

Another compatible bug found(Same case as this PR.)

mysql 8.0:

Server version: 8.0.23 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set @@group_concat_max_len=5;
Query OK, 0 rows affected (0.00 sec)

mysql> select group_concat(sname order by sname) from t1 group by cid;
+------------------------------------+
| group_concat(sname order by sname) |
+------------------------------------+
| Alice                              |
| Ace                                |
+------------------------------------+
2 rows in set, 1 warning (0.00 sec)

TiDB master:

mysql> set @@group_concat_max_len=5;
Query OK, 0 rows affected (0.00 sec)

mysql> select group_concat(sname order by sname) from t1 group by cid;
+------------------------------------+
| group_concat(sname order by sname) |
+------------------------------------+
| Alice                              |
| Ace,                               |
+------------------------------------+
2 rows in set, 1 warning (0.01 sec)

The result of TiDB has an extra comma.Not critical, will fix in another issue.

Actually, we should add "truncated" flag for each group instead of use one flag for all groups. For each group, if got truncated flag, we add the last separator. Otherwise, donot add.

@guo-shaoge
Copy link
Collaborator Author

@XuHuaiyu

@ichn-hu ichn-hu mentioned this pull request Mar 5, 2021
@XuHuaiyu XuHuaiyu added the type/bugfix This PR fixes a bug. label Mar 8, 2021
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Mar 8, 2021

Have you tested the case in #23129?

@guo-shaoge
Copy link
Collaborator Author

Have you tested the case in #23129?

Yes. The case is OK.

Signed-off-by: guo-shaoge <shaoge1994@163.com>
Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge guo-shaoge requested a review from a team as a code owner March 8, 2021 04:41
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 8, 2021
@guo-shaoge guo-shaoge force-pushed the issue-23129_group_concat_panic branch from 9b8be35 to 48463a5 Compare March 8, 2021 04:51
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 8, 2021
@XuHuaiyu XuHuaiyu changed the title executor: group_concat aggr panic when session.group_concat_max_len is small. executor: group_concat aggr panic when session.group_concat_max_len is small Mar 8, 2021
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refine the release note to describe what you fixed in this commit, not the phenomenon of the bug.

@@ -280,6 +280,10 @@ type topNRows struct {
currSize uint64
limitSize uint64
sepSize uint64
// If (separator, row) pair is poped from heap, we need to append separator in concat()
// In the following example, (sep2, str3) pair is poped, but partial sep2 need to be appended.
// eg: "str1 sep1 str2 sep2 str3" -> "str1 sep1 str2 se"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. sep1 --> sep
  2. sep2 --> sep
  3. what's the group_concat_length of this example

@@ -280,6 +280,10 @@ type topNRows struct {
currSize uint64
limitSize uint64
sepSize uint64
// If (separator, row) pair is poped from heap, we need to append separator in concat()
// In the following example, (sep2, str3) pair is poped, but partial sep2 need to be appended.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(sep2, str3) --> (sep, str3)
partial sep2 --> part of the second sep

@XuHuaiyu XuHuaiyu requested a review from lzmhhh123 March 8, 2021 09:49
Signed-off-by: guo-shaoge <shaoge1994@163.com>
@guo-shaoge guo-shaoge force-pushed the issue-23129_group_concat_panic branch from 41eef30 to b10f031 Compare March 9, 2021 01:57
@guo-shaoge guo-shaoge requested a review from XuHuaiyu March 9, 2021 08:04
@guo-shaoge
Copy link
Collaborator Author

@lzmhhh123 @XuHuaiyu PTAL

@XuHuaiyu
Copy link
Contributor

/LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Mar 10, 2021
@wshwsh12
Copy link
Contributor

/lgtm

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • XuHuaiyu
  • wshwsh12

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by writing /lgtm in a comment.
Reviewer can cancel approval by writing /lgtm cancel in a comment.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Mar 11, 2021
@wshwsh12
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: b10f031

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 11, 2021
@wshwsh12
Copy link
Contributor

/rebuild

@wshwsh12
Copy link
Contributor

/run-tics-test

@ti-chi-bot ti-chi-bot merged commit b298b86 into pingcap:master Mar 11, 2021
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Mar 11, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #23257

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution size/M Denotes a PR that changes 30-99 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

group_concat panic when @@group_concat_max_limit is small
5 participants