pingcap / pingcap/tidb

`FORMAT_BYTES` is not compatible with MySQL

Open
#59,455 1 comment 0 reactions 0 assignees View on GitHub
component/expression severity/moderate sig/execution type/bug
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)

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

```
mysql> SELECT FORMAT_BYTES(1023.999999999);
+------------------------------+
| FORMAT_BYTES(1023.999999999) |
+------------------------------+
| 1023 bytes |
+------------------------------+
1 row in set (0.01 sec)

mysql> SELECT FORMAT_BYTES(b'11111111');
+---------------------------+
| FORMAT_BYTES(b'11111111') |
+---------------------------+
| 255 bytes |
+---------------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES('');
+------------------+
| FORMAT_BYTES('') |
+------------------+
| 0 bytes |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES(CHAR(52));
+------------------------+
| FORMAT_BYTES(CHAR(52)) |
+------------------------+
| 4 bytes |
+------------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES(JSON_EXTRACT('{"x": 512}','$.x'));
+------------------------------------------------+
| FORMAT_BYTES(JSON_EXTRACT('{"x": 512}','$.x')) |
+------------------------------------------------+
| 512 bytes |
+------------------------------------------------+
1 row in set (0.01 sec)
```

It has two issues:

1. The handling of float is different.
2. The result should LPAD with spaces (I guess).

### 3. What did you see instead (Required)

```
mysql> SELECT FORMAT_BYTES(0);
+-----------------+
| FORMAT_BYTES(0) |
+-----------------+
| 0 bytes |
+-----------------+
1 row in set (0.01 sec)

mysql> SELECT FORMAT_BYTES(1023.999999999);
+------------------------------+
| FORMAT_BYTES(1023.999999999) |
+------------------------------+
| 1024 bytes |
+------------------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES(b'11111111');
+---------------------------+
| FORMAT_BYTES(b'11111111') |
+---------------------------+
| 255 bytes |
+---------------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES('');
+------------------+
| FORMAT_BYTES('') |
+------------------+
| 0 bytes |
+------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES(CHAR(52));
+------------------------+
| FORMAT_BYTES(CHAR(52)) |
+------------------------+
| 4 bytes |
+------------------------+
1 row in set (0.00 sec)

mysql> SELECT FORMAT_BYTES(JSON_EXTRACT('{"x": 512}','$.x'));
+------------------------------------------------+
| FORMAT_BYTES(JSON_EXTRACT('{"x": 512}','$.x')) |
+------------------------------------------------+
| 512 bytes |
+------------------------------------------------+
1 row in set (0.01 sec)
```

### 4. What is your TiDB version? (Required)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.