[MDEV-29154] Excessive warnings upon a call to RANDOM_BYTES Created: 2022-07-22  Updated: 2022-07-31  Resolved: 2022-07-27

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: N/A
Fix Version/s: 10.10.1

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Daniel Black
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-25704 Add RANDOM_BYTES function Closed

 Description   

I am not setting it to critical 10.10v1 to avoid it blocking the release, but it would be good to look into this. Not only does it cause an untidy output with a long list of duplicate warnings, but also my concern is that it may indicate some redundancy in the way the function is executed.

bb-10.10-MDEV-25704 c33ed04b7e7

MariaDB [test]> select random_bytes(cast('x' as unsigned)+1);
+---------------------------------------+
| random_bytes(cast('x' as unsigned)+1) |
+---------------------------------------+
| �                                      |
+---------------------------------------+
1 row in set, 5 warnings (0.000 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+
5 rows in set (0.000 sec)

The CAST alone only produces one warning, as expected:

MariaDB [test]> select cast('x' as unsigned);
+-----------------------+
| cast('x' as unsigned) |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set, 1 warning (0.000 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+
1 row in set (0.000 sec)

If random_bytes is replaced by another function, no extra warnings are produced (although I didn't try all functions, so maybe random_bytes is not unique in this sense):

MariaDB [test]> select ceil(cast('x' as unsigned)+1);
+-------------------------------+
| ceil(cast('x' as unsigned)+1) |
+-------------------------------+
|                             1 |
+-------------------------------+
1 row in set, 1 warning (0.000 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+
1 row in set (0.000 sec)



 Comments   
Comment by Daniel Black [ 2022-07-23 ]

Have brought the 5 warnings back to a standard 2 consistent with sha2 and format that also call args[x]->val_int() in ::fix_length_and_dec and ::val_str.

MariaDB [test]> select sha2('bbbbb', cast('x' as unsigned)+224);
+----------------------------------------------------------+
| sha2('bbbbb', cast('x' as unsigned)+224)                 |
+----------------------------------------------------------+
| abd54ed96011c648e7e012dfef1a9f3174b70c86de55d0840f2a576d |
+----------------------------------------------------------+
1 row in set, 2 warnings (21.758 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+
2 rows in set (0.000 sec)
 
MariaDB [test]> select format(4, cast('x' as unsigned)+1);
+------------------------------------+
| format(4, cast('x' as unsigned)+1) |
+------------------------------------+
| 4.0                                |
+------------------------------------+
1 row in set, 2 warnings (5.392 sec)
 
MariaDB [test]> show warnings;
+---------+------+----------------------------------------+
| Level   | Code | Message                                |
+---------+------+----------------------------------------+
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
| Warning | 1292 | Truncated incorrect INTEGER value: 'x' |
+---------+------+----------------------------------------+
2 rows in set (0.000 sec)

Not a complete solution, but a little more palatable. I think I need a bit of advice how to avoid this in the Item hierarchy with caching or otherwise.

Comment by Daniel Black [ 2022-07-25 ]

nikitamalyavin, since you've been drawn back to the discussion here in MDEV-25704 can I get a review of the final fix at the end of the bb-10.10-MDEV-25704 branch.

elenst if that approach is ok, I guess the other sha2/format can get a similar fix.

Related to the original 5 warnings by putting function calls in MY_(MAX|MIN) there's other (git grep -A 1 'MY_M[AI][XN]') non-simple args used,

Attempting to solve at high level:

fails with too many type unsigned/signed comparison and variable length array warnings

diff --git a/include/my_global.h b/include/my_global.h
index 22968900b0a..774cdab4656 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -1112,8 +1112,13 @@ typedef struct { const char *dli_fname, dli_fbase; } Dl_info;
 #endif
 
 /* Define some useful general macros (should be done after all headers). */
+#ifdef __cplusplus
+#define MY_MAX(a, b)   std::max((a), (b))
+#define MY_MIN(a, b)   std::min((a), (b))
+#else
 #define MY_MAX(a, b)   ((a) > (b) ? (a) : (b))
 #define MY_MIN(a, b)   ((a) < (b) ? (a) : (b))
+#endif
 
 #define CMP_NUM(a,b)    (((a) < (b)) ? -1 : ((a) == (b)) ? 0 : 1)
 

Comment by Daniel Black [ 2022-07-27 ]

Fixed enough thanks serg.

Reducing double warnings generally should be its own task.

Generated at Thu Feb 08 10:06:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.