pingcap / pingcap/tidb

Inconsistent comparison of timestampadd results on different platforms

Open
#51,440 0 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
```sql
drop table if exists t1;
CREATE TABLE `t1` (
`COL1` time DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into t1 values ('722:40:40');
select timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") from t1;
select timestampadd(hour, 1, '722:40:40') > timestampadd(hour, 1, "270:01:19");
```

### 2. What did you expect to see? (Required)
not sure, maybe need compatiable with mysql
### 3. What did you see instead (Required)
this sql always return `NULL` on different platforms
```sql
[11:18:24]TiDB root:test> select timestampadd(hour, 1, '722:40:40') > timestampadd(hour, 1, "270:01:19");
+-------------------------------------------------------------------------+
| timestampadd(hour, 1, '722:40:40') > timestampadd(hour, 1, "270:01:19") |
+-------------------------------------------------------------------------+
| |
+-------------------------------------------------------------------------+
1 row in set
Time: 0.003s
```
but for query from tables, it's return different result
```sql
# ➭ uname -a
# Linux hchwang 4.18.0-477.15.1.el8_8.x86_64 #1 SMP Wed Jun 28 15:04:18 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
mysql> select timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") from t1;
+------------------------------------------------------------------+
| timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") |
+------------------------------------------------------------------+
| NULL |
+------------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-----------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------+
| Warning | 1292 | Incorrect time value: '{2024 3 31 2 40 40 0}' |
+---------+------+-----------------------------------------------+
1 row in set (0.00 sec)

# [root@tc-tidb-5 /]# uname -a
# Linux tc-tidb-5 5.19.6-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Aug 29 10:06:03 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux
mysql> select timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") from t1;
+------------------------------------------------------------------+
| timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") |
+------------------------------------------------------------------+
| 1 |
+------------------------------------------------------------------+

# ➜ tidb git:(master) ✗ uname -a
# Darwin aytrackdeMacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:28:23 PDT 2022; root:xnu-8020.141.5~2/RELEASE_ARM64_T6000 arm64
[11:23:39]TiDB root:test> select timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") from t1;
+------------------------------------------------------------------+
| timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") |
+------------------------------------------------------------------+
| 1 |
+------------------------------------------------------------------+
1 row in set
```
for mysql8.2.0
```sql
[11:24:57]MySQL root:test> select timestampadd(hour, 1, '722:40:40') > timestampadd(hour, 1, "270:01:19");
+-------------------------------------------------------------------------+
| timestampadd(hour, 1, '722:40:40') > timestampadd(hour, 1, "270:01:19") |
+-------------------------------------------------------------------------+
| |
+-------------------------------------------------------------------------+
1 row in set
Time: 0.007s
[11:25:11]MySQL root:test> select timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") from t1;
+------------------------------------------------------------------+
| timestampadd(hour, 1, col1) > timestampadd(hour, 1, "270:01:19") |
+------------------------------------------------------------------+
| 1 |
+------------------------------------------------------------------+
1 row in set
```
### 4. What is your TiDB version? (Required)
```sql
[11:25:45]TiDB root:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------+
| Release Version: v8.0.0-alpha-357-g1d24b1caf2 |
| Edition: Community |
| Git Commit Hash: 1d24b1caf2f616de1946b5d66fcd51b173655daf |
| Git Branch: HEAD |
| UTC Build Time: 2024-03-01 02:49:23 |
| GoVersion: go1.21.6 |
| Race Enabled: false |
| Check Table Before Drop: false |
| Store: tikv |
+-----------------------------------------------------------+
1 row in set
Time: 0.004s
```

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.