Bug #110040 query bin() function by order by desc return incorrect result set
Submitted: 13 Feb 2023 8:28 Modified: 13 Feb 2023 14:00
Reporter: hel le Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.22+ OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, functions

[13 Feb 2023 8:28] hel le
Description:
Result set of select BIN(id),1,id from t1 order by 1,2 desc does not incorrect.
----------------------------------------------------------------------------------
mysql> \s
--------------
/home/mjxue/install/mysql/sql/bin/mysql  Ver 8.0.31 for Linux on x86_64 (Source distribution)

Connection id:		9
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.31-debug Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/home/mjxue/install/mysql/data/mysql.sock
Binary data as:		Hexadecimal
Uptime:			1 min 12 sec

Threads: 2  Questions: 8  Slow queries: 0  Opens: 345  Flush tables: 3  Open tables: 37  Queries per second avg: 0.111
--------------

mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed
mysql> create table t1 (id bigint);
Query OK, 0 rows affected (0.06 sec)

mysql> insert into t1 values(177151194), (177151195);
Query OK, 2 rows affected (0.02 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select BIN(id),1,id from t1 order by 1,2 desc; 
+------------------------------+---+-----------+
| BIN(id)                      | 1 | id        |
+------------------------------+---+-----------+
| 1010100011110001110011011010 | 1 | 177151194 |
| 1010100011110001110011011011 | 1 | 177151195 |
+------------------------------+---+-----------+
2 rows in set (0.00 sec)

The results in the first column are not output in descending order.

How to repeat:
As description.

Suggested fix:
No.
[13 Feb 2023 14:00] MySQL Verification Team
Hi Mr. le,

Thank you very much for your bug report.

However, it is not a bug.

Ordering integers is always the same, regardless if you use binary or octal or decimal or hexadecimal representation. As you can see for yourself, both binary and decimal representation are correctly sorted.

Not a bug.