function `bit_count` result is Inconsistent with MySQL
- 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)
In TiDB, the result is `0`, but in MySQL is `13`:
```mysql
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
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)
Contributor guide
Assessment
This issue has not been assessed yet.