diff options
author | Monty <monty@mariadb.org> | 2020-08-12 20:29:55 +0300 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2021-05-19 22:27:48 +0200 |
commit | b6ff139aa3457949a5bff10070f5b0e9ac0b43d7 (patch) | |
tree | 952135f7f7a7d7bcb446a2ce28f5c8f2de46e205 /sql/ha_partition.cc | |
parent | b3bc02f923f6002e6a5bd6446b80575292e1b0c7 (diff) | |
download | mariadb-git-b6ff139aa3457949a5bff10070f5b0e9ac0b43d7.tar.gz |
Reduce usage of strlen()
Changes:
- To detect automatic strlen() I removed the methods in String that
uses 'const char *' without a length:
- String::append(const char*)
- Binary_string(const char *str)
- String(const char *str, CHARSET_INFO *cs)
- append_for_single_quote(const char *)
All usage of append(const char*) is changed to either use
String::append(char), String::append(const char*, size_t length) or
String::append(LEX_CSTRING)
- Added STRING_WITH_LEN() around constant string arguments to
String::append()
- Added overflow argument to escape_string_for_mysql() and
escape_quotes_for_mysql() instead of returning (size_t) -1 on overflow.
This was needed as most usage of the above functions never tested the
result for -1 and would have given wrong results or crashes in case
of overflows.
- Added Item_func_or_sum::func_name_cstring(), which returns LEX_CSTRING.
Changed all Item_func::func_name()'s to func_name_cstring()'s.
The old Item_func_or_sum::func_name() is now an inline function that
returns func_name_cstring().str.
- Changed Item::mode_name() and Item::func_name_ext() to return
LEX_CSTRING.
- Changed for some functions the name argument from const char * to
to const LEX_CSTRING &:
- Item::Item_func_fix_attributes()
- Item::check_type_...()
- Type_std_attributes::agg_item_collations()
- Type_std_attributes::agg_item_set_converter()
- Type_std_attributes::agg_arg_charsets...()
- Type_handler_hybrid_field_type::aggregate_for_result()
- Type_handler_geometry::check_type_geom_or_binary()
- Type_handler::Item_func_or_sum_illegal_param()
- Predicant_to_list_comparator::add_value_skip_null()
- Predicant_to_list_comparator::add_value()
- cmp_item_row::prepare_comparators()
- cmp_item_row::aggregate_row_elements_for_comparison()
- Cursor_ref::print_func()
- Removes String_space() as it was only used in one cases and that
could be simplified to not use String_space(), thanks to the fixed
my_vsnprintf().
- Added some const LEX_CSTRING's for common strings:
- NULL_clex_str, DATA_clex_str, INDEX_clex_str.
- Changed primary_key_name to a LEX_CSTRING
- Renamed String::set_quick() to String::set_buffer_if_not_allocated() to
clarify what the function really does.
- Rename of protocol function:
bool store(const char *from, CHARSET_INFO *cs) to
bool store_string_or_null(const char *from, CHARSET_INFO *cs).
This was done to both clarify the difference between this 'store' function
and also to make it easier to find unoptimal usage of store() calls.
- Added Protocol::store(const LEX_CSTRING*, CHARSET_INFO*)
- Changed some 'const char*' arrays to instead be of type LEX_CSTRING.
- class Item_func_units now used LEX_CSTRING for name.
Other things:
- Fixed a bug in mysql.cc:construct_prompt() where a wrong escape character
in the prompt would cause some part of the prompt to be duplicated.
- Fixed a lot of instances where the length of the argument to
append is known or easily obtain but was not used.
- Removed some not needed 'virtual' definition for functions that was
inherited from the parent. I added override to these.
- Fixed Ordered_key::print() to preallocate needed buffer. Old code could
case memory overruns.
- Simplified some loops when adding char * to a String with delimiters.
Diffstat (limited to 'sql/ha_partition.cc')
-rw-r--r-- | sql/ha_partition.cc | 84 |
1 files changed, 49 insertions, 35 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 91047d05fc8..b50813cdc94 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -1183,9 +1183,22 @@ int ha_partition::rename_partitions(const char *path) #define ASSIGN_KEYCACHE_PARTS 5 #define PRELOAD_KEYS_PARTS 6 -static const char *opt_op_name[]= {NULL, - "optimize", "analyze", "check", "repair", - "assign_to_keycache", "preload_keys"}; +static const LEX_CSTRING opt_op_name[]= +{ + { NULL, 0}, + { STRING_WITH_LEN("optimize") }, + { STRING_WITH_LEN("analyze") }, + { STRING_WITH_LEN("check") }, + { STRING_WITH_LEN("repair") }, + { STRING_WITH_LEN("assign_to_keycache") }, + { STRING_WITH_LEN("preload_keys") } +}; + + +static const LEX_CSTRING msg_note= { STRING_WITH_LEN("note") }; +static const LEX_CSTRING msg_warning= { STRING_WITH_LEN("warning") }; +#define msg_error error_clex_str + /* Optimize table @@ -1389,14 +1402,14 @@ int ha_partition::handle_opt_part(THD *thd, HA_CHECK_OPT *check_opt, TODO: move this into the handler, or rewrite mysql_admin_table. */ bool print_admin_msg(THD* thd, uint len, - const char* msg_type, - const char* db_name, String &table_name, - const char* op_name, const char *fmt, ...) + const LEX_CSTRING *msg_type, + const char* db_name, String &table_name, + const LEX_CSTRING *op_name, const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 7, 8); bool print_admin_msg(THD* thd, uint len, - const char* msg_type, - const char* db_name, String &table_name, - const char* op_name, const char *fmt, ...) + const LEX_CSTRING *msg_type, + const char* db_name, String &table_name, + const LEX_CSTRING *op_name, const char *fmt, ...) { va_list args; Protocol *protocol= thd->protocol; @@ -1504,9 +1517,9 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, MYSQL_ERRMSG_SIZE, "error", + print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error, table_share->db.str, table->alias, - opt_op_name[flag], + &opt_op_name[flag], "Subpartition %s returned error", sub_elem->partition_name); } @@ -1531,9 +1544,9 @@ int ha_partition::handle_opt_partitions(THD *thd, HA_CHECK_OPT *check_opt, error != HA_ADMIN_ALREADY_DONE && error != HA_ADMIN_TRY_ALTER) { - print_admin_msg(thd, MYSQL_ERRMSG_SIZE, "error", + print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error, table_share->db.str, table->alias, - opt_op_name[flag], "Partition %s returned error", + &opt_op_name[flag], "Partition %s returned error", part_elem->partition_name); } /* reset part_state for the remaining partitions */ @@ -9947,9 +9960,9 @@ void ha_partition::append_row_to_str(String &str) for (; key_part != key_part_end; key_part++) { Field *field= key_part->field; - str.append(" "); + str.append(' '); str.append(&field->field_name); - str.append(":"); + str.append(':'); field_unpack(&str, field, rec, 0, false); } if (!is_rec0) @@ -9967,9 +9980,9 @@ void ha_partition::append_row_to_str(String &str) field_ptr++) { Field *field= *field_ptr; - str.append(" "); + str.append(' '); str.append(&field->field_name); - str.append(":"); + str.append(':'); field_unpack(&str, field, rec, 0, false); } if (!is_rec0) @@ -10007,14 +10020,14 @@ void ha_partition::print_error(int error, myf errflag) String str(buf,sizeof(buf),system_charset_info); uint32 part_id; str.length(0); - str.append("("); + str.append('('); str.append_ulonglong(m_last_part); - str.append(" != "); + str.append(STRING_WITH_LEN(" != ")); if (get_part_for_buf(m_err_rec, m_rec0, m_part_info, &part_id)) - str.append("?"); + str.append('?'); else str.append_ulonglong(part_id); - str.append(")"); + str.append(')'); append_row_to_str(str); /* Log this error, so the DBA can notice it and fix it! */ @@ -10967,9 +10980,9 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) read_part_id != m_part_info->vers_info->now_part->id && !m_part_info->vers_info->interval.is_set()) { - print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "note", + print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_note, table_share->db.str, table->alias, - opt_op_name[CHECK_PARTS], + &opt_op_name[CHECK_PARTS], "Not supported for non-INTERVAL history partitions"); DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED); } @@ -10998,9 +11011,9 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) if (num_misplaced_rows > 0) { - print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "warning", + print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_warning, table_share->db.str, table->alias, - opt_op_name[REPAIR_PARTS], + &opt_op_name[REPAIR_PARTS], "Moved %lld misplaced rows", num_misplaced_rows); } @@ -11020,9 +11033,9 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) if (!do_repair) { /* Check. */ - print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "error", + print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_error, table_share->db.str, table->alias, - opt_op_name[CHECK_PARTS], + &opt_op_name[CHECK_PARTS], "Found a misplaced row"); /* Break on first misplaced row! */ result= HA_ADMIN_NEEDS_UPGRADE; @@ -11047,8 +11060,9 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) str.length(0); if (result == HA_ERR_FOUND_DUPP_KEY) { - str.append("Duplicate key found, " - "please update or delete the record:\n"); + str.append(STRING_WITH_LEN("Duplicate key found, " + "please update or delete the " + "record:\n")); result= HA_ADMIN_CORRUPT; } m_err_rec= NULL; @@ -11068,9 +11082,9 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair) (uint) correct_part_id, str.c_ptr_safe()); } - print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "error", + print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, &msg_error, table_share->db.str, table->alias, - opt_op_name[REPAIR_PARTS], + &opt_op_name[REPAIR_PARTS], "Failed to move/insert a row" " from part %u into part %u:\n%s", (uint) read_part_id, @@ -11195,19 +11209,19 @@ int ha_partition::check_for_upgrade(HA_CHECK_OPT *check_opt) !(part_buf= generate_partition_syntax_for_frm(thd, m_part_info, &part_buf_len, NULL, NULL)) || - print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, "error", + print_admin_msg(thd, SQL_ADMIN_MSG_TEXT_SIZE + 1, &msg_error, table_share->db.str, table->alias, - opt_op_name[CHECK_PARTS], + &opt_op_name[CHECK_PARTS], KEY_PARTITIONING_CHANGED_STR, db_name.c_ptr_safe(), table_name.c_ptr_safe(), part_buf)) { /* Error creating admin message (too long string?). */ - print_admin_msg(thd, MYSQL_ERRMSG_SIZE, "error", + print_admin_msg(thd, MYSQL_ERRMSG_SIZE, &msg_error, table_share->db.str, table->alias, - opt_op_name[CHECK_PARTS], + &opt_op_name[CHECK_PARTS], KEY_PARTITIONING_CHANGED_STR, db_name.c_ptr_safe(), table_name.c_ptr_safe(), "<old partition clause>, but add ALGORITHM = 1" |