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

Insert rounds DATETIME/TIMESTAMP fractions instead of truncating #56432

Closed
mjonss opened this issue Oct 1, 2024 · 4 comments
Closed

Insert rounds DATETIME/TIMESTAMP fractions instead of truncating #56432

mjonss opened this issue Oct 1, 2024 · 4 comments
Labels
type/bug The issue is confirmed as a bug.

Comments

@mjonss
Copy link
Contributor

mjonss commented Oct 1, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (dt datetime, dt6 datetime(6), ts timestamp, ts6 timestamp(6));
insert into t values (now(6), now(6), now(6), now(6));
select sleep(0.5);
insert into t values (now(6), now(6), now(6), now(6));
insert into t values (now(), now(), now(), now());
select sleep(0.5);
insert into t values (now(), now(), now(), now());
select * from t;

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

FSP to be truncated

3. What did you see instead (Required)

FSP was rounded, causing issues like inserting '2022-12-31 23:59:59.501011' into a DATETIME or TIMESTAMP column results in '2023-01-01 00:00:00'.

+---------------------+----------------------------+---------------------+----------------------------+
| dt                  | dt6                        | ts                  | ts6                        |
+---------------------+----------------------------+---------------------+----------------------------+
| 2024-10-01 17:04:39 | 2024-10-01 17:04:38.596766 | 2024-10-01 17:04:39 | 2024-10-01 17:04:38.596766 | <= Rounded UP dt and ts!
| 2024-10-01 17:04:39 | 2024-10-01 17:04:39.106945 | 2024-10-01 17:04:39 | 2024-10-01 17:04:39.106945 |
| 2024-10-01 17:04:39 | 2024-10-01 17:04:39.000000 | 2024-10-01 17:04:39 | 2024-10-01 17:04:39.000000 |
| 2024-10-01 17:04:39 | 2024-10-01 17:04:39.000000 | 2024-10-01 17:04:39 | 2024-10-01 17:04:39.000000 | <= NOW() does truncate!
+---------------------+----------------------------+---------------------+----------------------------+

4. What is your TiDB version? (Required)

tidb_version(): Release Version: v8.3.0
Edition: Community
Git Commit Hash: 1a0c3ac3292fff7742faa0c00a662ccb66ba40db
Git Branch: HEAD
UTC Build Time: 2024-08-20 10:23:00
GoVersion: go1.21.10
Race Enabled: false
Check Table Before Drop: false
Store: tikv
@mjonss mjonss added the type/bug The issue is confirmed as a bug. label Oct 1, 2024
@mjonss
Copy link
Contributor Author

mjonss commented Oct 1, 2024

Also reported for MySQL, so at least we are MySQL compatible...

@mjonss
Copy link
Contributor Author

mjonss commented Oct 1, 2024

I think it is as intended :( and accordingly to MySQL Manual even in the SQL standard:
https://dev.mysql.com/doc/refman/8.0/en/fractional-seconds.html

@dveeden
Copy link
Contributor

dveeden commented Oct 3, 2024

@mjonss does that mean we can close this issue?

@mjonss
Copy link
Contributor Author

mjonss commented Oct 3, 2024

Yes, closing this, with a reference to #29406.

@mjonss mjonss closed this as completed Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants