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

greatest() sql function uses connection collation and not collation of columns #31789

Closed
morgo opened this issue Jan 18, 2022 · 1 comment · Fixed by #31806
Closed

greatest() sql function uses connection collation and not collation of columns #31789

morgo opened this issue Jan 18, 2022 · 1 comment · Fixed by #31806
Assignees
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@morgo
Copy link
Contributor

morgo commented Jan 18, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Enable the new collation framework first. Then use the following test case:

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 (
    id INT NOT NULL PRIMARY KEY auto_increment,
  `col_91` char(47) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
  `col_92` int(10) unsigned DEFAULT '2478966067',
  `col_97` char(32) COLLATE utf8mb4_bin NOT NULL
) collate utf8mb4_general_ci;

INSERT INTO `t2` VALUES 
(17,'UUtJeaV',497551109,'snRXXCZHBPW');

SET names utf8mb4 collate utf8mb4_bin;
-- correct:
SELECT
 id,
 greatest( col_92 , col_91 , col_97 ) as expr1
FROM t2 
ORDER BY id;

SET names utf8mb4 collate utf8mb4_general_ci;
-- uses collation from connection and not columns (incorrect)
SELECT
 id,
 greatest( col_92 , col_91 , col_97 ) as expr1
FROM t2 
ORDER BY id;

2. What did you expect to see? (Required)

mysql [localhost:8027] {msandbox} (test) > SELECT
    ->  id,
    ->  greatest( col_92 , col_91 , col_97 ) as expr1
    -> FROM t2 
    -> ORDER BY id;
+----+-------------+
| id | expr1       |
+----+-------------+
| 17 | snRXXCZHBPW |
+----+-------------+
1 row in set (0.00 sec)

mysql [localhost:8027] {msandbox} (test) > 
mysql [localhost:8027] {msandbox} (test) > SET names utf8mb4 collate utf8mb4_general_ci;
Query OK, 0 rows affected (0.00 sec)

mysql [localhost:8027] {msandbox} (test) > -- uses collation from connection and not columns (incorrect)
mysql [localhost:8027] {msandbox} (test) > SELECT
    ->  id,
    ->  greatest( col_92 , col_91 , col_97 ) as expr1
    -> FROM t2 
    -> ORDER BY id;
+----+-------------+
| id | expr1       |
+----+-------------+
| 17 | snRXXCZHBPW |
+----+-------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

tidb> -- correct:
tidb> SELECT
    ->  id,
    ->  greatest( col_92 , col_91 , col_97 ) as expr1
    -> FROM t2 
    -> ORDER BY id;
+----+-------------+
| id | expr1       |
+----+-------------+
| 17 | snRXXCZHBPW |
+----+-------------+
1 row in set (0.00 sec)

tidb> 
tidb> SET names utf8mb4 collate utf8mb4_general_ci;
Query OK, 0 rows affected (0.00 sec)

tidb> -- uses collation from connection and not columns (incorrect)
tidb> SELECT
    ->  id,
    ->  greatest( col_92 , col_91 , col_97 ) as expr1
    -> FROM t2 
    -> ORDER BY id;
+----+---------+
| id | expr1   |
+----+---------+
| 17 | UUtJeaV |
+----+---------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

tidb> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v5.5.0-alpha-136-g50704075a
Edition: Community
Git Commit Hash: 50704075afa7c0e3f2aa1fc9a66f440884a8f3fe
Git Branch: master
UTC Build Time: 2022-01-18 00:29:17
GoVersion: go1.16.9
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)
@morgo morgo added the type/bug The issue is confirmed as a bug. label Jan 18, 2022
@xiongjiwei xiongjiwei self-assigned this Jan 19, 2022
@aytrack aytrack added sig/sql-infra SIG: SQL Infra affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. severity/critical labels Jan 19, 2022
@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants