Skip to content

MDEV-40234 String_copier::well_formed_copy inefficient for appending … - #5326

Open
grooverdan wants to merge 1 commit into
MariaDB:10.11from
grooverdan:MDEV-40234
Open

MDEV-40234 String_copier::well_formed_copy inefficient for appending …#5326
grooverdan wants to merge 1 commit into
MariaDB:10.11from
grooverdan:MDEV-40234

Conversation

@grooverdan

Copy link
Copy Markdown
Member

…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.

@grooverdan
grooverdan requested a review from abarkov July 2, 2026 05:11
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@gkodinov gkodinov added the MariaDB Foundation Pull requests created by MariaDB Foundation label Jul 2, 2026
@grooverdan
grooverdan force-pushed the MDEV-40234 branch 3 times, most recently from 8b1c1b0 to f934e1a Compare July 9, 2026 01:07
@grooverdan

Copy link
Copy Markdown
Member Author

/gemini review
/copilot review
/robotchicken review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sql/sql_parse.cc Outdated
Comment thread sql/item_strfunc.cc
Comment thread sql/sql_acl.cc Outdated
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

3 participants