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

function bit_count result is Inconsistent with MySQL #44621

Open
fzzf678 opened this issue Jun 13, 2023 · 3 comments
Open

function bit_count result is Inconsistent with MySQL #44621

fzzf678 opened this issue Jun 13, 2023 · 3 comments
Labels
affects-7.5 affects-8.1 compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 severity/major sig/execution SIG execution type/bug This issue is a bug.

Comments

@fzzf678
Copy link
Contributor

fzzf678 commented Jun 13, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

In TiDB, the result is 0, but in MySQL is 13:

mysql> set @a = b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001';
Query OK, 0 rows affected (0.00 sec)

mysql> select bit_count(@a);
+---------------+
| bit_count(@a) |
+---------------+
|             0 |
+---------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+---------------------------------------------------+
| Level   | Code | Message                                           |
+---------+------+---------------------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: '"@��@  '   |
+---------+------+---------------------------------------------------+
1 row in set (0.01 sec)

mysql> select tidb_version();
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                            |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: None
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

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

In MySQL:

mysql> set @a = b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001';
Query OK, 0 rows affected (0.00 sec)

mysql> select bit_count(@a);
+---------------+
| bit_count(@a) |
+---------------+
|            13 |
+---------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.31    |
+-----------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

@fzzf678 fzzf678 added the type/bug This issue is a bug. label Jun 13, 2023
@fzzf678
Copy link
Contributor Author

fzzf678 commented Jun 13, 2023

With out user define var, the results are also different
tidb:

mysql> select bit_count(b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001');
+-----------------------------------------------------------------------------------------------------------+
| bit_count(b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001') |
+-----------------------------------------------------------------------------------------------------------+
|                                                                                                        64 |
+-----------------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------------------+
| Level   | Code | Message                                                        |
+---------+------+----------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect BINARY value: '0x052210408080401002002001' |
+---------+------+----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql:

mysql> select bit_count(b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001');
+-----------------------------------------------------------------------------------------------------------+
| bit_count(b'1010010001000010000010000001000000010000000010000000001000000000010000000000010000000000001') |
+-----------------------------------------------------------------------------------------------------------+
|                                                                                                         0 |
+-----------------------------------------------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-----------------------------------------------------------------+
| Level   | Code | Message                                                         |
+---------+------+-----------------------------------------------------------------+
| Warning | 1292 | Truncated incorrect BINARY value: 'x'052210408080401002002001'' |
+---------+------+-----------------------------------------------------------------+
1 row in set (0.01 sec)

@ti-chi-bot ti-chi-bot bot added may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 labels Jun 14, 2023
@Defined2014
Copy link
Contributor

The result of TiDB is same as MySQL 5.7
And from mysql manual, the bit_count function has different result between 5.7 and 8.0

https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#bit-operations-5-7

@Defined2014 Defined2014 added the compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) label Jun 15, 2023
@bb7133
Copy link
Member

bb7133 commented Apr 15, 2024

Ref #30637

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 affects-8.1 compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 severity/major sig/execution SIG execution type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants