MDEV-40234 String_copier::well_formed_copy inefficient for appending … - #5326
MDEV-40234 String_copier::well_formed_copy inefficient for appending …#5326grooverdan wants to merge 1 commit into
Conversation
|
Warning Gemini encountered an error creating the review. You can try again by commenting |
8b1c1b0 to
f934e1a
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces optimizations and safety checks to handle empty strings (zero-length inputs) more efficiently and avoid unnecessary character set conversions across several SQL files. However, the review identified critical issues where setting only the length of string structures (like LEX_CSTRING and LEX_STRING) to zero leaves their string pointers uninitialized, potentially causing server crashes in sql/sql_parse.cc and sql/sql_acl.cc. Additionally, in sql/item_strfunc.cc, the character set for empty strings should be set to the target collation rather than the source collation to prevent metadata mismatch errors.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…0 bytes
For all the copying in Field_{var}string::store, lets make a quick
path when we're copy 0 bytes.
This can occur on everything from a CREATE TABLE to just storing
an empty string.
THD::copy_fix contained a call to well_formed_copy however it
was always via copy_with_error. The callers of THD::copy_with_error
are:
* For COM_INIT_DB, an empty packet is an easy change database.
* Likewise in authentication with an empty database string it
doesn't require a complicated character set conversion.
A SQL character set converison doesn't require checks if the
string is empty. Changed Item_func_conv_charset::val_str to reflect
this. This needed an empty buffer of bytes per char as this
buffer could end up down at my_strcoll_ascii_4bytes_found in
a comparions against another MY_CS_MBMAXLEN bytes (mtr test
main.ctype_utf8mb4_uca_allkeys400).
A cast expression like "select cast(a as char(1)) from t1" where
a was empty needed to avoid the Item_char_typecast::copy in the
following line in the smae way.
Leave DBUG_ASSERT statements in THD::copy_fix and
String_copier::well_formed_copy for other implementers to find a
higher short cut when they hit this assertion.
…0 bytes
For all the copying in Field*str::store, lets make a quick path when we're copy 0 bytes in a compatible character set.