pingcap / pingcap/tidb

interval is truncated to wrong value

Open
#59,621 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)

```
SELECT SUBDATE(_utf8mb4'2024-01-01', INTERVAL X'01' DAY)
```

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

```
mysql> SELECT SUBDATE(_utf8mb4'2024-01-01', INTERVAL X'01' DAY);
+---------------------------------------------------+
| SUBDATE(_utf8mb4'2024-01-01', INTERVAL X'01' DAY) |
+---------------------------------------------------+
| 2023-12-31 |
+---------------------------------------------------+
1 row in set (0.00 sec)
```

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

```
mysql> SELECT SUBDATE(_utf8mb4'2024-01-01', INTERVAL X'01' DAY);
+---------------------------------------------------+
| SUBDATE(_utf8mb4'2024-01-01', INTERVAL X'01' DAY) |
+---------------------------------------------------+
| 2024-01-01 |
+---------------------------------------------------+
1 row in set, 1 warning (0.01 sec)
```

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

Contributor guide

Open the contributing guide

Research direction

Start by running the reported SUBDATE query in TiDB and compare its result and warning with the expected MySQL-style result. Trace the SQL date-interval handling until the X'01' DAY value is converted, then verify that the query returns 2023-12-31 without the incorrect truncation warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.