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

DATE_ADD function into VARCHAR column returns inconsistent results in fractional portion #31799

Closed
espresso98 opened this issue Jan 19, 2022 · 1 comment · Fixed by #35009
Closed
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. 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. severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@espresso98
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step

SET @@time_zone='+00:00';
SET @@timestamp=1000000000;
DROP TABLE IF EXISTS t1; 
CREATE TABLE t1 (a VARCHAR(32));
INSERT INTO t1 VALUES(DATE_ADD(CAST('2001-01-01 00:00:00' AS DATETIME), INTERVAL 1 SECOND));
INSERT INTO t1 VALUES(DATE_ADD(CAST('2001-01-01 00:00:00' AS DATETIME(6)), INTERVAL 1 SECOND));
INSERT INTO t1 VALUES(DATE_ADD(CAST('2001-01-01 00:00:00' AS DATETIME), INTERVAL 1.1 SECOND));
INSERT INTO t1 VALUES(DATE_ADD(CAST('2001-01-01 00:00:00' AS DATETIME(6)), INTERVAL 1.1 SECOND));
INSERT INTO t1 VALUES(DATE_ADD(CAST('00:00:00' AS TIME), INTERVAL 1.1 SECOND));
SELECT * FROM t1;
DROP TABLE t1;
SET @@timestamp=default;
SET @@time_zone=default;

2. What did you expect to see?

mysql> SELECT * FROM t1;
+----------------------------+
| a                          |
+----------------------------+
| 2001-01-01 00:00:01        |
| 2001-01-01 00:00:01.000000 |
| 2001-01-01 00:00:01.1      |
| 2001-01-01 00:00:01.100000 |
| 00:00:01.1                 |
+----------------------------+

3. What did you see instead

tidb> SELECT * FROM t1;
+----------------------------+
| a                          |
+----------------------------+
| 2001-01-01 00:00:01        |
| 2001-01-01 00:00:01        |
| 2001-01-01 00:00:01.100000 |
| 2001-01-01 00:00:01.100000 |
| 00:00:01                   |
+----------------------------+

4. What is your TiDB version?

tidb_version(): Release Version: v5.5.0-alpha-105-gaabd4e04d
Edition: Community
Git Commit Hash: aabd4e04d994eb91663abaa80865daec4cf970a6
Git Branch: master
UTC Build Time: 2022-01-13 05:36:36
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@espresso98 espresso98 added the type/bug The issue is confirmed as a bug. label Jan 19, 2022
@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. labels Jan 19, 2022
@zanmato1984
Copy link
Contributor

zanmato1984 commented May 14, 2022

There are two categories of problems in your reported cases:

  1. Precision loss for the fifth row.
  2. Precision mismatch between TiDB and MySQL, but not actual loss.

To differentiate these two categories, I'm opening issue #34659 to focus on the precision loss, and keeping this one to track the precision mismatch. Also adjusting the severity accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. 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. severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants