Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cast real as datetime is not compatible with tidb/mysql #3832

Closed
SeaRise opened this issue Jan 10, 2022 · 2 comments
Closed

cast real as datetime is not compatible with tidb/mysql #3832

SeaRise opened this issue Jan 10, 2022 · 2 comments
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 component/compute severity/major type/bug The issue is confirmed as a bug.

Comments

@SeaRise
Copy link
Contributor

SeaRise commented Jan 10, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)



use test;

drop table test.t;
create table test.t(a float, b double);
insert into test.t values (0, 0);
insert into test.t values (111.0, 111.0);
insert into test.t values (111.1, 111.1);
insert into test.t values (202102, 20210201);
insert into test.t values (202102.1, 20210201.1);

alter table test.t set tiflash replica 1;

// tiflash
set tidb_enforce_mpp=1; set tidb_isolation_read_engines='tiflash';
select a, cast(a as datetime), b, cast(b as datetime) from t;

// tidb
set tidb_enforce_mpp=0; set tidb_isolation_read_engines='tikv';
select a, cast(a as datetime), b, cast(b as datetime) from t;

// mysql
// execute in mysql
select a, cast(a as datetime), b, cast(b as datetime) from t;

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

-- mysql/tidb/tiflash
+-------------+---------------------+-------------------------+---------------------+
| a           | cast(a as datetime) | b                       | cast(b as datetime) |
+-------------+---------------------+-------------------------+---------------------+
|           0 | NULL                |                       0 | NULL                |
|  3.40282e38 | NULL                |  1.7976931348623157e308 | NULL                |
| 1.17549e-38 | NULL                | 2.2250738585072014e-308 | NULL                |
|         111 | 2000-01-11 00:00:00 |                     111 | 2000-01-11 00:00:00 |
|       111.1 | 2000-01-11 00:00:00 |                   111.1 | 2000-01-11 00:00:00 |
|      202102 | NULL                |                20210201 | 2021-02-01 00:00:00 |
|      202102 | NULL                |              20210201.1 | 2021-02-01 00:00:00 |
+-------------+---------------------+-------------------------+---------------------+

3. What did you see instead (Required)

-- mysql
+-------------+---------------------+-------------------------+---------------------+
|           0 | NULL                |                       0 | NULL                |
|  3.40282e38 | NULL                |  1.7976931348623157e308 | NULL                |
| 1.17549e-38 | NULL                | 2.2250738585072014e-308 | NULL                |
|         111 | 2000-01-11 00:00:00 |                     111 | 2000-01-11 00:00:00 |
|       111.1 | 2000-01-11 00:00:00 |                   111.1 | 2000-01-11 00:00:00 |
|      202102 | NULL                |                20210201 | 2021-02-01 00:00:00 |
|      202102 | NULL                |              20210201.1 | 2021-02-01 00:00:00 |
+-------------+---------------------+-------------------------+---------------------+

-- tidb
+-------------+---------------------+-------------------------+---------------------+
| a           | cast(a as datetime) | b                       | cast(b as datetime) |
+-------------+---------------------+-------------------------+---------------------+
|           0 | 0000-00-00 00:00:00 |                       0 | 0000-00-00 00:00:00 |
|         111 | NULL                |                     111 | NULL                |
|       111.1 | NULL                |                   111.1 | NULL                |
|      202102 | NULL                |                20210201 | 2021-02-01 00:00:00 |
|    202102.1 | NULL                |              20210201.1 | 2021-02-01 01:00:00 |
+-------------+---------------------+-------------------------+---------------------+

-- tiflash
+------------+---------------------+-------------------------+---------------------+
| a          | cast(a as datetime) | b                       | cast(b as datetime) |
+------------+---------------------+-------------------------+---------------------+
|          0 | NULL                |                       0 | NULL                |
|        111 | NULL                |                     111 | NULL                |
|      111.1 | NULL                |                   111.1 | NULL                |
|     202102 | 2021-08-02 00:00:00 |                20210201 | 2021-02-01 00:00:00 |
|   202102.1 | 2021-08-02 09:37:05 |              20210201.1 | 2021-02-01 01:00:00 |
+------------+---------------------+-------------------------+---------------------+

4. What is your TiFlash version? (Required)

master

@SeaRise SeaRise added the type/bug The issue is confirmed as a bug. label Jan 10, 2022
@ilovesoup
Copy link
Contributor

ilovesoup commented Jan 11, 2022

related to #3779 pingcap/tidb#31156

@jebter jebter added the affects-5.4 This bug affects the 5.4.x(LTS) versions. label Jan 18, 2022
@VelocityLight VelocityLight added the affects-6.1 This bug affects the 6.1.x(LTS) versions. label May 20, 2022
@VelocityLight VelocityLight added the affects-6.5 This bug affects the 6.5.x(LTS) versions. label Dec 2, 2022
@gengliqi
Copy link
Contributor

gengliqi commented Mar 3, 2023

In current master.
The result is:

-- mysql 8.0
+--------+---------------------+------------+---------------------+
| a      | cast(a as datetime) | b          | cast(b as datetime) |
+--------+---------------------+------------+---------------------+
|      0 | NULL                |          0 | NULL                |
|    111 | 2000-01-11 00:00:00 |        111 | 2000-01-11 00:00:00 |
|  111.1 | 2000-01-11 00:00:00 |      111.1 | 2000-01-11 00:00:00 |
| 202102 | NULL                |   20210201 | 2021-02-01 00:00:00 |
| 202102 | NULL                | 20210201.1 | 2021-02-01 00:00:00 |
+--------+---------------------+------------+---------------------+

-- tidb(tikv)
+----------+---------------------+------------+---------------------+
| a        | cast(a as datetime) | b          | cast(b as datetime) |
+----------+---------------------+------------+---------------------+
|        0 | 0000-00-00 00:00:00 |          0 | 0000-00-00 00:00:00 |
|      111 | 2000-01-11 00:00:00 |        111 | 2000-01-11 00:00:00 |
|    111.1 | 2000-01-11 00:00:00 |      111.1 | 2000-01-11 00:00:00 |
|   202102 | NULL                |   20210201 | 2021-02-01 00:00:00 |
| 202102.1 | NULL                | 20210201.1 | 2021-02-01 00:00:00 |
+----------+---------------------+------------+---------------------+

-- tidb(tiflash)
+----------+---------------------+------------+---------------------+
| a        | cast(a as datetime) | b          | cast(b as datetime) |
+----------+---------------------+------------+---------------------+
|        0 | 0000-00-00 00:00:00 |          0 | 0000-00-00 00:00:00 |
|      111 | 2000-01-11 00:00:00 |        111 | 2000-01-11 00:00:00 |
|    111.1 | 2000-01-11 00:00:00 |      111.1 | 2000-01-11 00:00:00 |
|   202102 | NULL                |   20210201 | 2021-02-01 00:00:00 |
| 202102.1 | NULL                | 20210201.1 | 2021-02-01 00:00:00 |
+----------+---------------------+------------+---------------------+

I think the only issue left is cast(0.0 as datetime) is NULL or 0000-00-00 00:00:00.
And it's related to NO_ZERO_DATE sql_mode, which had an old issue in TiDB repo pingcap/tidb#10485.
I think we can close this issue for now.

@gengliqi gengliqi closed this as completed Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-6.6 component/compute severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants