pingcap / pingcap/tidb

the CAST (0 AS DATE) return a datetime value

Open
#66,324 2 comments 0 reactions 0 assignees View on GitHub
contribution 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)

```
DROP DATABASE IF EXISTS test;
CREATE DATABASE IF NOT EXISTS test;
SET GLOBAL sort_buffer_size = 64 * 1024 * 1024;
SET GLOBAL read_rnd_buffer_size = 8 * 1024 * 1024;
USE test;
CREATE TABLE t1 (
c1 INT NULL
);

INSERT INTO t1 (c1) VALUES (85);

SELECT DISTINCT CAST(subq.variance_785 AS DATE) AS col_1_5 FROM (SELECT VARIANCE(s993.c1) AS variance_785 FROM t1 AS s993) AS subq;
SELECT DISTINCT CAST(CAST(subq.variance_785 AS DATE) AS DATE) AS col_1_5 FROM (SELECT VARIANCE(s993.c1) AS variance_785 FROM t1 AS s993) AS subq;

```
### 2. What did you expect to see? (Required)
the col_1_5's value should be `0000-00-00` instead of `0000-00-00 00:00:00`

### 3. What did you see instead (Required)
```
mysql> SELECT DISTINCT CAST(subq.variance_785 AS DATE) AS col_1_5 FROM (SELECT VARIANCE(s993.c1) AS variance_785 FROM t1 AS s993) AS subq;
+---------------------+
| col_1_5 |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.00 sec)
mysql> SELECT VARIANCE(s993.c1) AS variance_785 FROM t1 AS s993;
+--------------+
| variance_785 |
+--------------+
| 0 |
+--------------+
1 row in set (0.01 sec)
```

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

```
mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.5.1
Edition: Community
Git Commit Hash: 7d16cc79e81bbf573124df3fd9351c26963f3e70
Git Branch: heads/refs/tags/v7.5.1
UTC Build Time: 2024-02-27 14:28:32
GoVersion: go1.21.6
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```

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.