pingcap / pingcap/tidb

`DATE_SUB` gives wrong result for near zero date

Open
#59,789 0 comments 0 reactions 0 assignees View on GitHub
component/expression 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)

```
select DATE_SUB('1000-01-01', INTERVAL 1000 YEAR);
```

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

```
mysql> select DATE_SUB('1000-01-01', INTERVAL 1000 YEAR);
+--------------------------------------------+
| DATE_SUB('1000-01-01', INTERVAL 1000 YEAR) |
+--------------------------------------------+
| 0000-01-01 |
+--------------------------------------------+
1 row in set (0.06 sec)
```

### 3. What did you see instead (Required)

```
mysql> select DATE_SUB('1000-01-01', INTERVAL 1000 YEAR);
+--------------------------------------------+
| DATE_SUB('1000-01-01', INTERVAL 1000 YEAR) |
+--------------------------------------------+
| 0000-00-00 |
+--------------------------------------------+
1 row in set (0.00 sec)
```

### 4. What is your TiDB version? (Required)

Contributor guide

Open the contributing guide

Research direction

Start by running the reported DATE_SUB query and compare TiDB's result with the expected MySQL-compatible result. Search the Go implementation and tests for DATE_SUB or date interval subtraction; done means subtracting 1000 years from 1000-01-01 returns 0000-01-01 rather than 0000-00-00.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.