dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Ordering by the primary key changes the order of results incorrectly

Open elianddb opened this issue 4 months ago • 0 comments

Tests added in dolthub/go-mysql-server#3204.

MySQL

mysql> SELECT pk, cast(pk as signed) FROM test_cast ORDER BY pk;
+-----------------+--------------------+
| pk              | cast(pk as signed) |
+-----------------+--------------------+
|   3 12 4        |                  3 |
| -3.1234         |                 -3 |
| -3.1a           |                 -3 |
| -5+8            |                 -5 |
| +3.1234         |                  3 |
| 11-5            |                 11 |
| 1a1             |                  1 |
| 2,345           |                  2 |
| 3. 12 4         |                  3 |
| 3.2 12 4        |                  3 |
| 4,12            |                  4 |
| 5.932887e+07    |                  5 |
| 5.932887e+07abc |                  5 |
| 5.932887e7      |                  5 |
| 5.932887e7abc   |                  5 |
| a1a1            |                  0 |
+-----------------+--------------------+
16 rows in set, 16 warnings (0.009 sec)

Dolt

9812/main*> SELECT pk, cast(pk as signed) FROM test_cast ORDER BY pk;
+-----------------+--------------------+
| pk              | cast(pk as signed) |
+-----------------+--------------------+
|   3 12 4        | 3                  |
| +3.1234         | 3                  |
| -3.1234         | -3                 |
| -3.1a           | -3                 |
| -5+8            | -5                 |
| 11-5            | 11                 |
| 1a1             | 1                  |
| 2,345           | 2                  |
| 3. 12 4         | 3                  |
| 3.2 12 4        | 3                  |
| 4,12            | 4                  |
| 5.932887e+07    | 5                  |
| 5.932887e+07abc | 5                  |
| 5.932887e7      | 5                  |
| 5.932887e7abc   | 5                  |
| a1a1            | 0                  |
+-----------------+--------------------+
16 rows in set (0.00 sec)

elianddb avatar Sep 12 '25 20:09 elianddb