summaryrefslogtreecommitdiff
path: root/sql/sql_show.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2020-09-03 20:27:12 +0300
committerSergei Golubchik <serg@mariadb.org>2021-05-19 22:54:11 +0200
commit949d10bea27050970bf04aeaac4217e24997ce95 (patch)
tree4b1278de9d03ef2f858e4d12551d430c94eceaff /sql/sql_show.cc
parenta206658b985fe5e18fb5692fdb3698dad5aca70a (diff)
downloadmariadb-git-949d10bea27050970bf04aeaac4217e24997ce95.tar.gz
Don't reset StringBuffers in loops when not needed
- Moved out creating StringBuffers in loops and instead create them outside and just reset the buffer if it was not allocated (to avoid a possible malloc/free for every entry) Other things related to set_buffer_if_not_allocated() - Changed Valuebuffer to not call set_buffer_if_not_allocated() when it is created. - Fixed geometry functions to reset string length before calling String::reserve(). This is because one should not access length() of an undefined. - Added Item_func_conv_charset::save_in_field() as the item is using str_value to store cached values, which conflicts with Item::save_str_in_field(). - Changed Item_proc_string to not store the string value in sql_string as this clashes with Item::save_str_in_field(). - Locally store value of full_name_cstring() in analyse::end_of_records() as Item::save_str_in_field() may overwrite it. - Marked some strings as set_thread_specific() - Added String::free_buffer() to be used internally in String functions to just free the buffer but not reset other String values. - Fixed uses_buffer_owned_by() to check for allocated length instead of strlength, which could be marked MEM_UNDEFINED().
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r--sql/sql_show.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index bd73220310f..8e7e042264b 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2410,6 +2410,7 @@ int show_create_table_ex(THD *thd, TABLE_LIST *table_list,
/* Add table level check constraints */
if (share->table_check_constraints)
{
+ StringBuffer<MAX_FIELD_WIDTH> str(&my_charset_utf8mb4_general_ci);
for (uint i= share->field_check_constraints;
i < share->table_check_constraints ; i++)
{
@@ -2418,7 +2419,8 @@ int show_create_table_ex(THD *thd, TABLE_LIST *table_list,
if (share->period.constr_name.streq(check->name))
continue;
- StringBuffer<MAX_FIELD_WIDTH> str(&my_charset_utf8mb4_general_ci);
+ str.set_buffer_if_not_allocated(&my_charset_utf8mb4_general_ci);
+ str.length(0); // Print appends to str
check->print(&str);
packet->append(STRING_WITH_LEN(",\n "));
@@ -3036,14 +3038,16 @@ int select_result_text_buffer::append_row(List<Item> &items, bool send_names)
rows.push_back(row, thd->mem_root))
return true;
+ StringBuffer<32> buf;
+
while ((item= it++))
{
DBUG_ASSERT(column < n_columns);
- StringBuffer<32> buf;
const char *data_ptr;
char *ptr;
size_t data_len;
+ buf.set_buffer_if_not_allocated(&my_charset_bin);
if (send_names)
{
DBUG_ASSERT(strlen(item->name.str) == item->name.length);