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

The subtime() function returns an incorrect result when using the date type #56861

Closed
apollodafoni opened this issue Oct 28, 2024 · 7 comments · Fixed by #57337
Closed

The subtime() function returns an incorrect result when using the date type #56861

apollodafoni opened this issue Oct 28, 2024 · 7 comments · Fixed by #57337
Assignees
Labels
affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. fuzz/comp Issues found by comp fuzz test. impact/wrong-result may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-8.1 severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@apollodafoni
Copy link

apollodafoni commented Oct 28, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table lrr_test(`COL1` date);
insert into lrr_test values('2024-11-01');
insert into lrr_test values('2020-11-01');
select col1,subtime(col1,'12:00:01.341300') from lrr_test;

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

Mysql:
+------------+---------------------------------+
| col1 | subtime(col1,'12:00:01.341300') |
+------------+---------------------------------+
| 2024-11-01 | 2024-10-31 11:59:58.658700 |
| 2020-11-01 | 2020-10-31 11:59:58.658700 |
+------------+---------------------------------+

3. What did you see instead (Required)

+------------+---------------------------------+
| col1 | subtime(col1,'12:00:01.341300') |
+------------+---------------------------------+
| 2024-11-01 | -12:00:01.341300 |
| 2020-11-01 | -12:00:01.341300 |
+------------+---------------------------------+

4. What is your TiDB version? (Required)

Release Version: v8.4.0
Edition: Community
Git Commit Hash: 2511e92
Git Branch: HEAD
UTC Build Time: 2024-10-27 16:16:04
GoVersion: go1.23.2
Race Enabled: false
Check Table Before Drop: false
Store: tikv

@apollodafoni apollodafoni added the type/bug The issue is confirmed as a bug. label Oct 28, 2024
@apollodafoni
Copy link
Author

/severity major
/impact wrong-result

@windtalker
Copy link
Contributor

windtalker commented Oct 28, 2024

Looks like in https://github.com/pingcap/tidb/blob/3c8f2f3517a4529b5162df69724df389a506aea3/pkg/expression/builtin_time.go#L4581-l4582
if the first argument is date type, it will be adjusted to duration type, not sure if it is on purpose or not. But since it's result is different from MySQL, I think we can treat it as a bug.

@apollodafoni apollodafoni changed the title The subtime() function returns an incorrect result when using the date type The subtime() function returns an incorrect result when using the date type Oct 28, 2024
@apollodafoni
Copy link
Author

/severity moderate

@apollodafoni
Copy link
Author

/remove-severity major

@jebter jebter added the sig/execution SIG execution label Oct 29, 2024
@xzhangxian1008
Copy link
Contributor

/assign

@apollodafoni
Copy link
Author

/label fuzz/comp

@ti-chi-bot ti-chi-bot bot added the fuzz/comp Issues found by comp fuzz test. label Nov 29, 2024
@apollodafoni
Copy link
Author

/label affects-7.5

@ti-chi-bot ti-chi-bot bot added affects-7.5 This bug affects the 7.5.x(LTS) versions. and removed may-affects-7.5 labels Dec 16, 2024
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.5 This bug affects the 8.5.x(LTS) versions. fuzz/comp Issues found by comp fuzz test. impact/wrong-result may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-8.1 severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
4 participants