Just porting some code from OracleDB into MariaDB and been converting some OracleDB expressions (like SYSDATE - ? / 1440
) to MariaDB notation (this seems to fit fine: NOW() - interval 60 * ? second
).
Stumbled upon what I suspect to be either a known-bug or a documented-behavior (please help), while debugging the following misbehaving expression (basically comparing the duration of 2 historical "locks")
WHERE (a.expirationDt - a.acquisitionDt) > (b.expirationDt - b.acquisitionDt)
In OracleDB - this expression worked consistently/reliably. In MariaDB - it appears to depend on if the subtracted timestamps belong to same minute (then the subtraction results in correct amount of seconds) or if those are from two different minutes (then subtraction results seem to be padded/rounded up to a nearest minute), thus producing counter-intuitive results.
Here's a little demo (basically using now()
and "20 sec ago"):
root@localhost> maria "select now(), now() - interval 60 * 1/3 second, now() - interval 60000000 * 1/3 microsecond, now() - (now() - interval 60 * 1/3 second), now() - (now() - interval 60000000 * 1/3 microsecond), TIMESTAMPDIFF( second, now() - interval 60 * 1/3 second, now()) from dual"
2020-02-03 13:51:59.0
2020-02-03 13:51:39.0
2020-02-03 13:51:39.0
20.0000
20.000000
20
root@localhost> maria "select now(), now() - interval 60 * 1/3 second, now() - interval 60000000 * 1/3 microsecond, now() - (now() - interval 60 * 1/3 second), now() - (now() - interval 60000000 * 1/3 microsecond), TIMESTAMPDIFF( second, now() - interval 60 * 1/3 second, now()) from dual"
2020-02-03 13:52:02.0
2020-02-03 13:51:42.0
2020-02-03 13:51:42.0
60.0000
60.000000
20
I know that TIMESTAMPDIFF
looks fine and can rewrite the SQL accordingly (just need to make sure how to properly work with sub-second precision, given "20.4 sec > 20.2 sec" will return false
once rounded to 1-sec precision).
My main question - do I have something wrong in my MariaDB setup? Or is it a known bug in particular MariaDB versions? Or is it by design?