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.41k stars 4.87k forks source link

There is a logical error when the time field is used as the subtrahend. #28906

Open LingweiKuang opened 6 hours ago

LingweiKuang commented 6 hours ago

Bug Description

When there are multiple records (more than one) in the table, there is a logical error in the SELECT statement when the time field is used as the subtrahend. The abstract expression sequence is: (CONSTANT - time) > CONSTANT

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, 0);
INSERT INTO t1(time, c1) VALUES (1641024000001, 1);

# query 1
SELECT CAST(time AS BIGINT) FROM t1 WHERE (1 - time) > 0;

Expected Behavior

Query 1 returned result set: empty set

Actual behaviour

Query 1 returned result set: 1 and 0

Environment

Additional Context

Hello, TDengine team. When there is more than one record in the table, and the time field is used as the subtrahend in a predicate expression, the expression logic evaluates to FALSE, but all data can still be retrieved.

LingweiKuang commented 6 hours ago

There is a logical error when the time field is used as the subtrahend