[MDEV-32013] Add Field::val_lex_string_strmake() Created: 2023-08-25 Updated: 2023-09-12 Resolved: 2023-08-25 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Character Sets |
| Fix Version/s: | 11.3.0 |
| Type: | Task | Priority: | Major |
| Reporter: | Alexander Barkov | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||
| Description |
|
As of 11.3.0, the server code uses two ways to put a Field::val_str() value to MEM_ROOT:
In many cases the value is further needed as a LEX_CSTRING, but both versions of get_field() are inconvenient and inefficient to initialize a LEX_CSTRING. The first version requires an strlen() call. This is an example from udf_init() in sql_udf.cc:
Notice safe_strlen() and strlen() calls. The second version of get_field() requires a String buffer for every LEX_CSTRING. This is an example from plugin_load() in sql_plugin.cc:
Notice two String buffers. Let's add a native method in Field which will overcome both problems:
It won't need neither strlen() calls nor String buffers. Also let's move this version of get_field():
as a static function to sql_help.cc, as it's only used in this file. This will help to avoid reincarnation of its calls around the code in the future and encorage the use of the new method Field::val_lex_string_strmake(). |
| Comments |
| Comment by Vicențiu Ciorbaru [ 2023-08-25 ] |
|
Suggest to not have the final strmake suffix. Just val_lex_string should suffice. |
| Comment by Alexander Barkov [ 2023-08-25 ] |
|
I think the suffix is needed to make it clear that it puts the trailing '\0', like strmake(), strmake_root(), strmake_buf() do. |
| Comment by Vicențiu Ciorbaru [ 2023-08-26 ] |
|
LEX_STRINGS should always be '\0' terminted, hence I don't think that is necessary |