pingcap / pingcap/tidb

`round` function on exact number produces different result from MySQL

Open
#53,891 3 comments 0 reactions 0 assignees View on GitHub
compatibility-mysql80 impact/wrong-result may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

### 1. Minimal reproduce step (Required)
```sql
select round(-717754013, 24);
```

### 2. What did you expect to see? (Required)
In MySQL:
```
mysql> select round(-717754013, 24);
+-----------------------+
| round(-717754013, 24) |
+-----------------------+
| -717754013 |
+-----------------------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)
But TiDB output `-717754012`. And TiDB produces correct result `-717754013` sometimes.
```
mysql> select round(-717754013, 24);
+-----------------------+
| round(-717754013, 24) |
+-----------------------+
| -717754012 |
+-----------------------+
1 row in set (0.00 sec)
```

### 4. What is your TiDB version? (Required)
```
Release Version: v8.2.0-alpha-292-g7629a0d
Edition: Community
Git Commit Hash: 7629a0d68595c4d11c25fc059208f3efd838c2c1
Git Branch: HEAD
UTC Build Time: 2024-06-04 03:27:25
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```
topology:

distributed.yaml:
```
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/tidb-deploy"
data_dir: "/tidb-data"

pd_servers:
- host: 10.0.2.31

tidb_servers:
- host: 10.0.2.21

tikv_servers:
- host: 10.0.2.11
- host: 10.0.2.12
- host: 10.0.2.13

monitoring_servers:
- host: 10.0.2.8

grafana_servers:
- host: 10.0.2.8

alertmanager_servers:
- host: 10.0.2.8

tiflash_servers:
- host: 10.0.2.32
```

### about us
We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in TiDB that may lead to database logic error.

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.