Bug #116307 handling of fsp > 255 is incorrect
Submitted: 7 Oct 5:54 Modified: 7 Oct 6:42
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Errors Severity:S2 (Serious)
Version:9.0.1 OS:Any
Assigned to: CPU Architecture:Any
Tags: fsp

[7 Oct 5:54] Daniël van Eeden
Description:
The fsp as used in `NOW(fsp)` should be between 0 and 6.

For fsp values between 7 and 255 the correct error is shown.

For fsp values between 256 and 262 the values is incorrectly accepted and handled like values between 0 and 6.

For fsp values of 263 and up the error message contains an incorrect precision number.

How to repeat:
sql> SELECT NOW(255);
ERROR: 1426 (42000): Too-big precision 255 specified for 'now'. Maximum is 6.

sql> SELECT NOW(256);
+---------------------+
| NOW(256)            |
+---------------------+
| 2024-10-07 07:49:23 |
+---------------------+
1 row in set (0.0004 sec)

sql> SELECT NOW(262);
+----------------------------+
| NOW(262)                   |
+----------------------------+
| 2024-10-07 07:49:42.668660 |
+----------------------------+
1 row in set (0.0004 sec)

sql> SELECT NOW(263);
ERROR: 1426 (42000): Too-big precision 7 specified for 'now'. Maximum is 6.

sql> SELECT NOW(999);
ERROR: 1426 (42000): Too-big precision 231 specified for 'now'. Maximum is 6.

sql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 9.0.1     |
+-----------+
1 row in set (0.0005 sec)

Suggested fix:
- Make sure to reject incorrect fsp numbers
- Make sure to use the correct precision for error messages for fsp numbers of >262
[7 Oct 6:06] Daniël van Eeden
$ (for n in {1..1000}; do echo -en "$n: "; echo "SELECT NOW($n)" | mysql -Nu root 2>&1; done) | grep -v 'Too-big precision'
1: 2024-10-07 08:05:57.1
2: 2024-10-07 08:05:57.17
3: 2024-10-07 08:05:57.181
4: 2024-10-07 08:05:57.1864
5: 2024-10-07 08:05:57.19196
6: 2024-10-07 08:05:57.198036
256: 2024-10-07 08:05:58
257: 2024-10-07 08:05:58.4
258: 2024-10-07 08:05:58.48
259: 2024-10-07 08:05:58.487
260: 2024-10-07 08:05:58.4927
261: 2024-10-07 08:05:58.49918
262: 2024-10-07 08:05:58.505731
512: 2024-10-07 08:05:59
513: 2024-10-07 08:05:59.7
514: 2024-10-07 08:05:59.73
515: 2024-10-07 08:05:59.744
516: 2024-10-07 08:05:59.7498
517: 2024-10-07 08:05:59.75391
518: 2024-10-07 08:05:59.757951
768: 2024-10-07 08:06:01
769: 2024-10-07 08:06:01.0
770: 2024-10-07 08:06:01.01
771: 2024-10-07 08:06:01.024
772: 2024-10-07 08:06:01.0285
773: 2024-10-07 08:06:01.03447
774: 2024-10-07 08:06:01.039853
[7 Oct 6:42] MySQL Verification Team
Hello Daniël,

Thank you for the report and feedback.

regards,
Umesh