pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.34k stars 5.85k forks source link

comparing with `round()` in WHERE predicate may produce unexpected result #57586

Open r33s3n6 opened 1 day ago

r33s3n6 commented 1 day ago

1. Minimal reproduce step (Required)

create table t1 (c1 double);
insert into t1 (c1) values (-2147483646.5);

select  
  c1,
  round(c1),
  c1 > round(c1)
from 
  t1
where c1 > round(c1);

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

when the third column is 0, it should not appear: in TiDB with unistore:

mysql> select  
    ->   c1,
    ->   round(c1),
    ->   c1 > round(c1)
    -> from 
    ->   t1
    -> where c1 > round(c1);
Empty set (0.00 sec)

3. What did you see instead (Required)

in TiDB with TiKV

mysql> select  
    ->   c1,
    ->   round(c1),
    ->   c1 > round(c1)
    -> from 
    ->   t1
    -> where c1 > round(c1);
+---------------+-------------+----------------+
| c1            | round(c1)   | c1 > round(c1) |
+---------------+-------------+----------------+
| -2147483646.5 | -2147483646 |              0 |
+---------------+-------------+----------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

Release Version: v8.5.0-alpha-184-g1c059a1216
Edition: Community
Git Commit Hash: 1c059a1216db711e2cb56ea9f3d1ad8c23db6327
Git Branch: HEAD
UTC Build Time: 2024-11-21 04:56:22
GoVersion: go1.23.3
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"

tidb_servers:
  - host: 10.0.2.81

pd_servers:
  - host: 10.0.2.82

tikv_servers:
  - host: 10.0.2.83

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.