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: fix wrong behavior for max/min on ENUM/SET column (#19552) #19869

Merged
merged 4 commits into from
Sep 8, 2020

Conversation

ti-srebot
Copy link
Contributor

cherry-pick #19552 to release-4.0


What problem does this PR solve?

Issue Number: close #13961

Problem Summary:
max/min produces wrong result on ENUM & SET column.

What is changed and how it works?

What's Changed:
Fix max/min implementation for ENUM/SET type.

How it Works:
Add max/min implementation for ENUM/SET type.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
    No.
  • Need to cherry-pick to the release branch
    No.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)
create table t3(id int, en enum('b', 'a'));
insert into t3 values (1, 'a'), (1, 'b');

mysql root@127.0.0.1:test> select max(en) from t3 group by id; 
                           select max(en) from t3; 
                                                                                                                                                                                                             
+---------+
| max(en) |
+---------+
| a       |
+---------+
1 row in set
Time: 0.014s

+---------+
| max(en) |
+---------+
| a       |
+---------+
1 row in set
Time: 0.013s
mysql root@127.0.0.1:test>                                                                                                                                                                                   
mysql root@127.0.0.1:test> select min(en) from t3 group by id; 
                           select min(en) from t3; 
                                                                                                                                                                                                             
+---------+
| min(en) |
+---------+
| b       |
+---------+
1 row in set
Time: 0.014s

+---------+
| min(en) |
+---------+
| b       |
+---------+
1 row in set
Time: 0.013s
create table t4(id int, f set('a', 'b', 'c'));
insert into t4 values(1, 'a'), (2, 'b'), (1, 'a,b,c');

mysql [email protected]:test> select max(f) from t4; 
                           select max(f) from t4 group by id; 
                                                                                                                                                                                                             
+--------+
| max(f) |
+--------+
| a,b,c  |
+--------+
1 row in set
Time: 0.014s

+--------+
| max(f) |
+--------+
| a,b,c  |
| b      |
+--------+
2 rows in set
Time: 0.013s

mysql [email protected]:test> select min(f) from t4; 
                           select min(f) from t4 group by id; 
                                                                                                                                                                                                             
+--------+
| min(f) |
+--------+
| a      |
+--------+
1 row in set
Time: 0.015s

+--------+
| min(f) |
+--------+
| a      |
| b      |
+--------+
2 rows in set
Time: 0.014s

Side effects

  • MySQL Compatibility
    MySQL produce MIN/MAX result on string value of ENUM/SET column, rather than index value. Which is in-consist with manual, and considered as a known issue.

In MIN(), MAX(), and other aggregate functions, MySQL currently compares ENUM and SET columns by their string value rather than by the string's relative position in the set.

Release note

  • Fix wrong behavior for max/min on ENUM/SET column.

@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot ti-srebot added contribution This PR is from a community contributor. type/4.0-cherry-pick labels Sep 8, 2020
@ti-srebot ti-srebot added this to the v4.0.6 milestone Sep 8, 2020
@ti-srebot ti-srebot self-assigned this Sep 8, 2020
@qw4990 qw4990 closed this Sep 8, 2020
@qw4990 qw4990 reopened this Sep 8, 2020
Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 8, 2020
@qw4990
Copy link
Contributor

qw4990 commented Sep 8, 2020

/run-all-tests

Copy link
Contributor

@SunRunAway SunRunAway left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 8, 2020
@SunRunAway
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Sep 8, 2020
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@ti-srebot merge failed.

@qw4990
Copy link
Contributor

qw4990 commented Sep 8, 2020

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/4.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants