pingcap / pingcap/tidb

The data_sub() function returns incorrect results when using extreme values

Open
#56,863 6 comments 0 reactions 0 assignees View on GitHub
fuzz/comp impact/wrong-result severity/minor 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)

```
create table lrr_test(`COL1` datetime DEFAULT NULL);
insert into lrr_test values('0001-01-01 00:00:00');
select col1, date_sub(col1, interval 10 month) from lrr_test;
```

### 2. What did you expect to see? (Required)
Mysql:
+---------------------+-----------------------------------+
| col1 | date_sub(col1, interval 10 month) |
+---------------------+-----------------------------------+
| 0001-01-01 00:00:00 | 0000-03-01 00:00:00 |
+---------------------+-----------------------------------+

### 3. What did you see instead (Required)
+---------------------+-----------------------------------+
| col1 | date_sub(col1, interval 10 month) |
+---------------------+-----------------------------------+
| 0001-01-01 00:00:00 | 0000-00-00 00:00:00 |
+---------------------+-----------------------------------+

### 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

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.