Description:
According to the documentation found at "http://dev.mysql.com/doc/refman/5.0/en/hexadecimal-values.html", hexadecimal literals in the form 0xABCD are interpreted as strings by default, and numbers in numeric contexts.
According to the documentation found at "http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_char", the CHAR() function interprets each argument N as an integer.
Therefore, in "CHAR(0x41)", "0x41" should be interpreted as an integer. However, it seems that the database mis-handled it.
The problem is found to be more serious that almost all statements related to hexadecimal literals in the form 0xABCD are affected (See How To Repeat below).
"explain extended select 0x41 as ColA" produces strange result "select ColA AS `ColA`" in the explain message. Later statements also produce "???" in the explain message.
This bug may be related to bug #33198.
How to repeat:
mysql> explain extended select 65;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+-------------------+
| Level | Code | Message |
+-------+------+-------------------+
| Note | 1003 | select 65 AS `65` |
+-------+------+-------------------+
1 row in set (0.00 sec)
mysql> explain extended select 65 as ColA;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+---------------------+
| Level | Code | Message |
+-------+------+---------------------+
| Note | 1003 | select 65 AS `ColA` |
+-------+------+---------------------+
1 row in set (0.00 sec)
mysql> explain extended select 0x41;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+-----------------------+
| Level | Code | Message |
+-------+------+-----------------------+
| Note | 1003 | select 0x41 AS `0x41` |
+-------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain extended select 0x41 as ColA;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+-----------------------+
| Level | Code | Message |
+-------+------+-----------------------+
| Note | 1003 | select ColA AS `ColA` |
+-------+------+-----------------------+
1 row in set (0.00 sec)
mysql> explain extended select 0 + 0x41;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+--------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------+
| Note | 1003 | select (0 + ???) AS `0 + 0x41` |
+-------+------+--------------------------------+
1 row in set (0.00 sec)
mysql> explain extended select 0x41 + 0;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+--------------------------------+
| Level | Code | Message |
+-------+------+--------------------------------+
| Note | 1003 | select (??? + 0) AS `0x41 + 0` |
+-------+------+--------------------------------+
1 row in set (0.00 sec)
mysql> explain extended select cast(0x41 as unsigned);
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+----------------------------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------------------------+
| Note | 1003 | select cast(??? as unsigned) AS `cast(0x41 as unsigned)` |
+-------+------+----------------------------------------------------------+
1 row in set (0.00 sec)
mysql> explain extended select cast(0x41 as char);
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+---------------------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------------------+
| Note | 1003 | select cast(??? as char charset utf8) AS `cast(0x41 as char)` |
+-------+------+---------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> explain extended select char(0x41);
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+-------+------+----------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------+
| Note | 1003 | select char(???) AS `char(0x41)` |
+-------+------+----------------------------------+
1 row in set (0.00 sec)