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

Stability and Compatibility issue on SELECT MICROSECOND(CURRENT_TIMESTAMP(6))=MICROSECOND(UTC_TIMESTAMP(6)) #31938

Open
espresso98 opened this issue Jan 25, 2022 · 1 comment · May be fixed by #56431
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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@espresso98
Copy link
Collaborator

espresso98 commented Jan 25, 2022

Bug Report

1. Minimal reproduce step (Required)

SELECT MICROSECOND(CURRENT_TIMESTAMP(6))=MICROSECOND(UTC_TIMESTAMP(6));

2. What did you expect to see?

mysql> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

mysql> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

mysql> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

mysql> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

3. What did you see instead

tidb> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                0 |
+------------------------------------------------------------------+

tidb> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

tidb> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                0 |
+------------------------------------------------------------------+

tidb> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+

4. What is your TiDB version?

tidb_version(): Release Version: v5.5.0-alpha-154-gc589ee547
Edition: Community
Git Commit Hash: c589ee5471e05430f7f888190780a27fddb9ce7a
Git Branch: master
UTC Build Time: 2022-01-19 21:56:30
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 25, 2022
@morgo
Copy link
Contributor

morgo commented Jan 25, 2022

In MySQL this is stable because these functions use the sysvar TIMESTAMP which is cached for statement context duration. TiDB partially supports this:

tidb> SET timestamp=UNIX_TIMESTAMP('2021-01-01 01:01:01.000010');
Query OK, 0 rows affected (0.00 sec)

tidb> select current_timestamp(6), utc_timestamp(6);
+----------------------------+----------------------------+
| current_timestamp(6)       | utc_timestamp(6)           |
+----------------------------+----------------------------+
| 2021-01-01 01:01:01.000010 | 2021-01-01 08:01:01.000010 |
+----------------------------+----------------------------+
1 row in set (0.00 sec)

tidb> SELECT MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6));
+------------------------------------------------------------------+
| MICROSECOND(CURRENT_TIMESTAMP(6))= MICROSECOND(UTC_TIMESTAMP(6)) |
+------------------------------------------------------------------+
|                                                                1 |
+------------------------------------------------------------------+
1 row in set (0.00 sec)

But It looks when the variable is not set, it's not caching for statement context correctly.

@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 5.4.x versions. labels Feb 8, 2022
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 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/major 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.

6 participants