[MDEV-27168] Non-deterministic results of datetime operation Created: 2021-12-04  Updated: 2021-12-14  Resolved: 2021-12-13

Status: Closed
Project: MariaDB Server
Component/s: Temporal Types
Affects Version/s: None
Fix Version/s: N/A

Type: Bug Priority: Blocker
Reporter: Tadas Balaišis Assignee: Sergei Golubchik
Resolution: Not a Bug Votes: 0
Labels: None

Attachments: Text File maria non deterministic.txt    

 Description   

I get different results from the same query executed (10.6.4-MariaDB) subsequently. I tried with HeidiSQL (11.3.0.6344) and MySQL Client (MariaDB 10.5 (x64)). Please check the file attached. Can you give an explanation?



 Comments   
Comment by Tadas Balaišis [ 2021-12-05 ]

I was hoping to get the same output like I get with

SELECT seq, TIMESTAMPDIFF(SECOND,NOW(),(NOW() + INTERVAL seq SECOND)) df FROM seq_1_to_60

Comment by Sergei Golubchik [ 2021-12-13 ]

your "timestamp - timestamp" does not do what you think it does. Try:

SELECT seq, (NOW() + INTERVAL seq second) - NOW() df, now() + interval seq second, now(), cast(now() + interval seq second as unsigned), cast(now() as unsigned) FROM seq_1_to_60

you can see that the second column is the difference between values in two last columns.

Comment by Tadas Balaišis [ 2021-12-14 ]

Well thank you for explanation. Anyway the numeric expression of datetime subtraction is still non-deterministic, therefore it's useless. For several samples I decided that this is number of seconds between. But that is not true. So I had to rewrite my views queries to use timestampdiff function. And I guess I'm not the last person to get into this trap.

Generated at Thu Feb 08 09:50:51 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.