taosdata / TDengine

High-performance, scalable time-series database designed for Industrial IoT (IIoT) scenarios
https://tdengine.com
GNU Affero General Public License v3.0
23.42k stars 4.87k forks source link

A logical error occurs when performing arithmetic operations on the BIGINT type. #28884

Open LingweiKuang opened 3 days ago

LingweiKuang commented 3 days ago

Bug Description

Loss of Precision in Arithmetic Operations on BIGINT Data Type.

To Reproduce

Assume that we execute the following statement under a database named testdb.

DROP TABLE IF EXISTS t1;
CREATE TABLE t1(time TIMESTAMP, c1 BIGINT);
INSERT INTO t1(time, c1) VALUES (1641024000000, 9000000000000000000);

# query 1
SELECT c1 FROM t1 WHERE 9000000000000000001 <= c1;

# query 2
SELECT c1 FROM t1 WHERE 9000000000000000001 <= c1 + CAST(0 as BIGINT);

Expected Behavior

Query 1 returned result set: empty set

Query 2 returned result set: empty set

Actual behaviour

Query 1 returned result set: empty set

Query 2 returned result set: 9000000000000000000

Environment

Additional Context

Hello, TDengine team. I found that arithmetic operations on the BIGINT type fail to meet the precision requirement of 2^63-1 supported by the BIGINT type, which might be a logical error.

LingweiKuang commented 3 days ago

A logical error occurs when performing arithmetic operations on the BIGINT type