unexpected string value change caused by changing MIN to MAX
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```SQL
DROP DATABASE IF EXISTS test;
CREATE DATABASE IF NOT EXISTS test;
USE test;
CREATE TABLE t3 (
c1 INT NOT NULL AUTO_INCREMENT,
c2 INT NOT NULL,
c3 INT NOT NULL,
c4 YEAR NOT NULL,
c5 TIME NULL,
c6 TINYINT NULL,
c7 SMALLINT NULL,
c8 MEDIUMINT NULL,
c9 BIGINT NULL,
c10 LONGTEXT NULL,
c11 VARCHAR(255) NULL,
c12 TINYTEXT NULL,
c13 TINYBLOB NULL,
c14 SET('x','y','z') NULL,
c15 TINYINT(1) NULL,
PRIMARY KEY (c1)
);
INSERT INTO t3 (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15) VALUES (8417, 9828, 4869, 2023, '2023-01-01 21:39:34', 14, 68, 41, 89, 'sample_e', 'sample_weZoLCxaYRuEbIZSAcw', 'sample_8eD325FzN79CIA1lx3hcxnIVFhKIlbppGhso8TzRvfqzVgovF4texBWt2e15D4TE8uXMELQHhSBEC2wHYIIOfKH8XCNMYbzkX06yuiY1u41mec1TesgBYKV3PW', X'D2A6D881052BECAA90E6BDA5DBAF542830D084', 'y,z', NULL);
INSERT INTO t3 (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15) VALUES (4922, 954, 4869, 2021, '2023-01-01 06:36:18', 19, 50, 55, 65, 'sample_N', 'sample_9aBiOKQWlD6V8bnMlAnngXZ1YieyzuAPe18BnchnfXv6jiQr7DaO7p8iNRIy3HRcpus3SXH95WlUixQOUStr548OLHbSdgpkqOTlSazJIaPLHIMFBW9KE3D', 'sample_UmiYLgxZvp53mPtZvonfQqC6O5HoEmaq7nUw0', X'ED8D8C70E98E9C434E5D0D4EE589A67BC392E182A6CE82C999D9BB54', 'y,x,z', NULL);
CREATE INDEX idx_t3_c3 ON t3 (c3);
SELECT 'sample_N' < 'sample_e';
SELECT xav56.c3 AS col_1, MIN(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
SELECT xav56.c3 AS col_1, MAX(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
```
### 2. What did you expect to see? (Required)
in tidb sample_N is greater than sample_e
but after changing MIN to MAX ,the value changes from sample_N to sample_e
```bash
mysql> SELECT 'sample_N' < 'sample_e';
+-------------------------+
| 'sample_N' < 'sample_e' |
+-------------------------+
| 0 |
+-------------------------+
1 row in set (0.00 sec)
mysql> SELECT xav56.c3 AS col_1, MIN(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
+-------+----------+
| col_1 | col_2 |
+-------+----------+
| 4869 | sample_N |
+-------+----------+
1 row in set (0.00 sec)
mysql> SELECT xav56.c3 AS col_1, MAX(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
+-------+----------+
| col_1 | col_2 |
+-------+----------+
| 4869 | sample_e |
+-------+----------+
1 row in set (0.01 sec)
```
### 3. What did you see instead (Required)
```
mysql> SELECT 'sample_N' < 'sample_e';
+-------------------------+
| 'sample_N' < 'sample_e' |
+-------------------------+
| 0 |
+-------------------------+
1 row in set (0.00 sec)
mysql> SELECT xav56.c3 AS col_1, MIN(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
+-------+----------+
| col_1 | col_2 |
+-------+----------+
| 4869 | sample_N |
+-------+----------+
1 row in set (0.00 sec)
mysql> SELECT xav56.c3 AS col_1, MAX(xav56.c10) AS col_2 FROM t3 AS xav56 WHERE xav56.c3 = 4869 GROUP BY xav56.c3;
+-------+----------+
| col_1 | col_2 |
+-------+----------+
| 4869 | sample_e |
+-------+----------+
1 row in set (0.01 sec)
```
### 4. What is your TiDB version? (Required)
```
mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.5.1
Edition: Community
Git Commit Hash: 7d16cc79e81bbf573124df3fd9351c26963f3e70
Git Branch: heads/refs/tags/v7.5.1
UTC Build Time: 2024-02-27 14:28:32
GoVersion: go1.21.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.