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

if(ts >9999999999, ts/1000, ts) wrong #55837

Closed
database-on-line opened this issue Sep 4, 2024 · 4 comments · Fixed by #56158
Closed

if(ts >9999999999, ts/1000, ts) wrong #55837

database-on-line opened this issue Sep 4, 2024 · 4 comments · Fixed by #56158
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. report/community The community has encountered this bug. severity/critical sig/execution SIG execution type/bug The issue is confirmed as a bug. type/regression

Comments

@database-on-line
Copy link

database-on-line commented Sep 4, 2024

Bug Report

when if result have decimal,the compare result is wrong

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `articles_of_video_day` (
  `clicks_of_today` int(4) NOT NULL,
  `ts` bigint(4) NOT NULL,
  KEY `ts_index` (`ts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

insert into articles_of_video_day values(0,1725292800),(0,1725292800);

select from_unixtime( if(`ts` >9999999999, ts/1000, `ts`), '%Y-%m-%d %H:%i:%s') from articles_of_video_day;

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

+--------------------------------------------------------------------------+
| from_unixtime( if(`ts` >9999999999, ts/1000, `ts`), '%Y-%m-%d %H:%i:%s') |
+--------------------------------------------------------------------------+
| 2024-09-03 00:00:00                                                      |
| 2024-09-03 00:00:00                                                      |
+--------------------------------------------------------------------------+
2 rows in set (0.00 sec)

3. What did you see instead (Required)

MySQL [test]> select from_unixtime( if(`ts` >9999999999, ts/1000, `ts`), '%Y-%m-%d %H:%i:%s') from articles_of_video_day;
+--------------------------------------------------------------------------+
| from_unixtime( if(`ts` >9999999999, ts/1000, `ts`), '%Y-%m-%d %H:%i:%s') |
+--------------------------------------------------------------------------+
| 1970-01-02 11:46:39                                                      |
| 1970-01-02 11:46:39                                                      |
+--------------------------------------------------------------------------+
2 rows in set, 2 warnings (0.00 sec)

MySQL [test]> show warnings;
+---------+------+-------------------------------------------+
| Level   | Code | Message                                   |
+---------+------+-------------------------------------------+
| Warning | 1690 | DECIMAL value is out of range in '(9, 4)' |
| Warning | 1690 | DECIMAL value is out of range in '(9, 4)' |
+---------+------+-------------------------------------------+
2 rows in set (0.00 sec)

you can see the currect result by this(cast(ts/1000 as signed))

MySQL [test]> select from_unixtime( if(`ts` >9999999999, cast(ts/1000 as signed), `ts`), '%Y-%m-%d %H:%i:%s') from articles_of_video_day;
+------------------------------------------------------------------------------------------+
| from_unixtime( if(`ts` >9999999999, cast(ts/1000 as signed), `ts`), '%Y-%m-%d %H:%i:%s') |
+------------------------------------------------------------------------------------------+
| 2024-09-03 00:00:00                                                                      |
| 2024-09-03 00:00:00                                                                      |
+------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

v7.5.1,v8.1.1,
asktug url: https://asktug.com/t/topic/1031711/10

@database-on-line database-on-line added the type/bug The issue is confirmed as a bug. label Sep 4, 2024
@pcqz
Copy link

pcqz commented Sep 4, 2024

related to #46786

@pcqz
Copy link

pcqz commented Sep 4, 2024

/sig execution

@ti-chi-bot ti-chi-bot bot added the sig/execution SIG execution label Sep 4, 2024
@seiya-annie
Copy link

/report community

@ti-chi-bot ti-chi-bot bot added report/community The community has encountered this bug. affects-7.5 This bug affects the 7.5.x(LTS) versions. labels Sep 4, 2024
@jebter jebter added type/regression severity/critical affects-8.1 This bug affects the 8.1.x(LTS) versions. labels Sep 6, 2024
@windtalker
Copy link
Contributor

It seems the root cause of TiDB tries to add cast(issuedb.articles_of_video_day.ts, decimal(9, 4) BINARY) is in the create table statement, it use ts bigint(4), which I think TiDB will interpreter as the max ts's length is 4.
If I use the following statement to create table, it will get correct result

CREATE TABLE `articles_of_video_day` (
  `clicks_of_today` int NOT NULL,
  `ts` bigint NOT NULL,
  KEY `ts_index` (`ts`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. report/community The community has encountered this bug. severity/critical sig/execution SIG execution type/bug The issue is confirmed as a bug. type/regression
Projects
None yet
5 participants