Skip to content

TIMESTAMPADD does not return correct data type when parameter is DateTime type #39213

Open
@birdstorm

Description

Enhancement

This issue is found during #38003

TIMESTAMPADD should return different DataTypes according to the DataType of its parameters.

e.g.,
MySQL behavior:

mysql> create view v(result) as select timestampadd(second,1.1,cast('1995-01-05 06:32:20.859724' as datetime)) as result;
Query OK, 0 rows affected (0.01 sec)

mysql> desc v;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| result | datetime(1) | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
1 row in set (0.01 sec)

mysql> select * from v;
+-----------------------+
| result                |
+-----------------------+
| 1995-01-05 06:32:22.1 |
+-----------------------+
1 row in set (0.00 sec)

TiDB behavior:

mysql> create view v(result) as select timestampadd(second,1.1,cast('1995-01-05 06:32:20.859724' as datetime)) as result;
Query OK, 0 rows affected (0.12 sec)

mysql> desc v;
+--------+-------------+------+------+---------+-------+
| Field  | Type        | Null | Key  | Default | Extra |
+--------+-------------+------+------+---------+-------+
| result | varchar(19) | NO   |      | NULL    |       |
+--------+-------------+------+------+---------+-------+
1 row in set (0.01 sec)

mysql> select * from v;
+---------------------+
| result              |
+---------------------+
| 1995-01-05 06:32:22 |
+---------------------+
1 row in set (0.00 sec)

When using TIMESTAMPADD, TiDB always casts the parameter into String, and always returns a String result. This is not efficient and in-compatible with MySQL behavior.

Metadata

Assignees

No one assigned

    Labels

    affects-5.0This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.affects-5.3This bug affects 5.3.x versions.affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.0affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.2affects-6.3affects-6.4affects-6.5This bug affects the 6.5.x(LTS) versions.affects-6.6affects-7.0affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.may-affects-4.0This bug maybe affects 4.0.x versions.severity/majorsig/executionSIG executiontype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions