pingcap / tidb

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

When the maximum value of the `time` type is exceeded, the returned result is confusing #56865

Open apollodafoni opened 2 weeks ago

apollodafoni commented 2 weeks ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table lrr_test(`COL1` time DEFAULT NULL);
insert into lrr_test values('838:59:59');
select col1,adddate(col1, interval 10 hour_minute) from lrr_test where adddate(col1, interval 10 hour_minute) is null;

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

Mysql: +-----------+----------------------------------------+ | col1 | adddate(col1, interval 10 hour_minute) | +-----------+----------------------------------------+ | 838:59:59 | NULL | +-----------+----------------------------------------+

3. What did you see instead (Required)

Since adddate(col1, interval 10 hour_minute) returns 839:09:59, why can it be returned in theisnull judgment?

mysql> select col1,adddate(col1, interval 10 hour_minute) from lrr_test where adddate(col1, interval 10 hour_minute) is null; +-----------+----------------------------------------+ | col1 | adddate(col1, interval 10 hour_minute) | +-----------+----------------------------------------+ | 838:59:59 | 839:09:59 | +-----------+----------------------------------------+ 1 row in set, 1 warning (0.66 sec)

mysql> show warnings; +---------+------+-------------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------------------------+ | Warning | 1690 | evaluation failed: Duration value is out of range in '(838:59:59 - 00:10:00)' | +---------+------+-------------------------------------------------------------------------------+ 1 row in set (0.03 sec)

4. What is your TiDB version? (Required)

Release Version: v8.4.0 Edition: Community Git Commit Hash: 2511e928966110964414e6bbb630a565a9870a52 Git Branch: HEAD UTC Build Time: 2024-10-27 16:16:04 GoVersion: go1.23.2 Race Enabled: false Check Table Before Drop: false Store: tikv

apollodafoni commented 2 weeks ago

/severity minor

windtalker commented 2 weeks ago

isnull returns true because the selection is pushed down to tikv, and tikv return null, but TiDB does not return null for adddate(col1, interval 10 hour_minute) I think this is because in TiDB, it does not check if the duration is overflow during the execution. For example: https://github.com/pingcap/tidb/blob/390de884f4e3088a0bf828fe883627c5436542be/pkg/types/time.go#L1321-L1333