[MDEV-25704] Add RANDOM_BYTES function Created: 2021-05-17 Updated: 2023-08-07 Resolved: 2022-07-31 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | OTHER |
| Fix Version/s: | 10.10.1 |
| Type: | Task | Priority: | Minor |
| Reporter: | Ian Gilfillan | Assignee: | Sergei Golubchik |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Compatibility, Preview_10.10, beginner-friendly, compat56, compat80 | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||
| Description |
|
MySQL 5.6 added the RANDOM_BYTES function: https://dev.mysql.com/doc/refman/5.6/en/encryption-functions.html#function_random-bytes This is needed for compatibility purposes. |
| Comments |
| Comment by Daniel Black [ 2022-05-05 ] | ||
|
https://github.com/MariaDB/server/pull/2016 that serg looked over and I'm pretty sure every comment was addressed. I'll look at rebasing (10.9) and squashing commits once the release is over. | ||
| Comment by Daniel Black [ 2022-06-09 ] | ||
|
Pushed as preview-10.10- This is identical to the updated PR2016. | ||
| Comment by Sergei Golubchik [ 2022-06-18 ] | ||
|
It's in this branch: preview-10.10-misc. | ||
| Comment by Sergei Golubchik [ 2022-06-27 ] | ||
|
also in bb-10.10- | ||
| Comment by Elena Stepanova [ 2022-07-24 ] | ||
|
In my opinion, the feature as of bb-10.10- Note: The remark about NULL-ability of a resulting column upon CREATE TABLE .. SELECT RANDOM_BYTES(N), repeated twice in the pull request discussion, has not been addressed. I assume it was a conscious decision to keep it in line with existing functions, specifically REPEAT mentioned as a counter-argument. | ||
| Comment by Sergei Golubchik [ 2022-07-24 ] | ||
|
nikitamalyavin, let's revive this NULL-ability question. You wrote (I'll quote from the PR to move the discussion here):
Indeed, Item_func_repeat always is always nullable. Because, see Item_func_repeat::val_str() it returns NULL when length of the result is larger than the max_allowed_packet. That is, REPEAT() can return NULL when both arguments are not NULL. As far as I can see, RANDOM_BYTES(N) cannot return NULL when its argument is not NULL. | ||
| Comment by Nikita Malyavin [ 2022-07-25 ] | ||
|
serg I didn't know about that variable. Shouldn't RANDOM_BYTES do the same? | ||
| Comment by Sergei Golubchik [ 2022-07-25 ] | ||
|
N in RANDOM_BYTES(N) must be between 1 and 1024, so RANDOM_BYTES can never return an empty string or anything larger than max_allowed_packet (which, itself, cannot be less than 1024) | ||
| Comment by Nikita Malyavin [ 2022-07-25 ] | ||
|
Right... sorry, i didn't check Item_func_random_bytes::val_str before asking, only RAND_bytes function description, since I remembered something about the length restriction, but nothing was there. So, why "if (length > 1024) then NULL", and "if (length > max_allowed_packet) then NULL" should behave differently? EDIT: sorry, got the difference. One is empty, and anothe one is NULL. | ||
| Comment by Nikita Malyavin [ 2022-07-25 ] | ||
|
Ok, so now I remember my thoughts around sql_mode=EMPTY_STRING_IS_NULL. It is set in oracle mode, I guess it means that RANDOM_BYTES(1025) is NULL as well as empty in mysql (or is this mode about Oracle database, not mysql?) We can either stick with current behavior, but change fix_length_and_dec to:
or change it to return NULL, which is, maybe, more conformant with our style (i guess) | ||
| Comment by Sergei Golubchik [ 2022-07-25 ] | ||
|
I suggest:
of course, the function should stay nullable, if we do the above. | ||
| Comment by Daniel Black [ 2022-07-26 ] | ||
|
As suggested, I implemented this at the end of bb-10.10- | ||
| Comment by Elena Stepanova [ 2022-07-26 ] | ||
|
bb-10.10- | ||
| Comment by Daniel Black [ 2022-07-27 ] | ||
|
fixed most. Debug builds only of query_cache test failing because args[0]->can_eval_in_optimize() changes from false to true between Item_func_random_bytes::fix_length_and_dec and Item_func_random_bytes::val_str. This is due to args[0]->table->const_table becoming true. | ||
| Comment by Daniel Black [ 2022-07-27 ] | ||
|
Ok, buildbot happy again. serg, nikitamalyavin can I get a review on the last two commits on the bb-10.10- | ||
| Comment by Elena Stepanova [ 2022-07-29 ] | ||
|
I have no further objections against pushing bb-10.10- |