diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-10-18 08:07:40 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-10-18 10:15:17 +0400 |
commit | 9a833dc6881b896e65cf76c9699faa6c324e1775 (patch) | |
tree | 25b3daa904d7fb75a50c08d777ae3fce025684f2 /sql/sql_partition.cc | |
parent | 9c9606152505792fcb8f4b7386e5b6a25e2790b4 (diff) | |
download | mariadb-git-9a833dc6881b896e65cf76c9699faa6c324e1775.tar.gz |
MDEV-20856 Bad values in metadata views for partitions on VARBINARY
The old code to print partition values was too complicated:
- it created new Items for character set conversion purposes.
- it mixed string conversion and partition error reporting
in the same code blocks.
Simplifying the code as follows:
- Adding helper methods String::can_be_safely_convert_to() and
String::append_introducer_and_hex().
- Adding DBUG_EXECUTE_IF("generate_partition_syntax_for_frm", push_warning...)
into generate_partition_syntax_for_frm(), to test the PARTITON
clause written to FRM. Adding test partition_utf8-debug.test for this.
- Removing functions get_cs_converted_part_value_from_string() and
get_cs_converted_string_value. Changing get_partition_column_description()
to use Type_handler::partition_field_append_value() instead.
This makes SHOW CREATE TABLE and SELECT FROM I_S.PARTITIONS
use the same code path.
- Changing Type_handler::partition_field_append_value() not to
call convert_charset_partition_constant(), to avoid creating a new Item
for string conversion pursposes.
Rewritting the code to use only String methods.
- Removing error reporting code (ER_PARTITION_FUNCTION_IS_NOT_ALLOWED)
from Type_handler::partition_field_append_value().
The error is correctly detected and reported on the caller level.
So error reporting was redundant here.
Also:
- Moving methods Type_handler::partition_field_*() from sql_partition.cc
to sql_type.cc. This fixes compilation problem with -DPLUGIN_PARTITION=NO,
earlier introduced by the patch for MDEV-20831.
Diffstat (limited to 'sql/sql_partition.cc')
-rw-r--r-- | sql/sql_partition.cc | 88 |
1 files changed, 5 insertions, 83 deletions
diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index d95b14c437c..9957a3b064c 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -146,7 +146,7 @@ Item* convert_charset_partition_constant(Item *item, CHARSET_INFO *cs) item= item->safe_charset_converter(thd, cs); context->table_list= NULL; thd->where= "convert character set partition constant"; - if (item->fix_fields_if_needed(thd, (Item**)NULL)) + if (item && item->fix_fields_if_needed(thd, (Item**)NULL)) item= NULL; thd->where= save_where; context->table_list= save_list; @@ -2240,36 +2240,6 @@ static int add_partition_options(String *str, partition_element *p_elem) } -void -Type_handler::partition_field_type_not_allowed(const LEX_CSTRING &field_name) -{ - my_error(ER_FIELD_TYPE_NOT_ALLOWED_AS_PARTITION_FIELD, MYF(0), - field_name.str); -} - - -bool -Type_handler::partition_field_check_result_type(Item *item, - Item_result expected_type) -{ - if (item->result_type() != expected_type) - { - my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0)); - return TRUE; - } - return false; -} - - -bool -Type_handler_blob_common::partition_field_check(const LEX_CSTRING &field_name, - Item *item_expr) const -{ - my_error(ER_BLOB_FIELD_IN_PART_FUNC_ERROR, MYF(0)); - return true; -} - - /* Find the given field's Create_field object using name of field @@ -2303,58 +2273,6 @@ static Create_field* get_sql_field(const char *field_name, } -bool -Type_handler_general_purpose_int::partition_field_append_value( - String *str, - Item *item_expr, - CHARSET_INFO *field_cs, - partition_value_print_mode_t mode) - const -{ - DBUG_ASSERT(item_expr->cmp_type() == INT_RESULT); - StringBuffer<21> tmp; - longlong value= item_expr->val_int(); - tmp.set(value, system_charset_info); - return str->append(tmp); -} - - -bool Type_handler::partition_field_append_value( - String *str, - Item *item_expr, - CHARSET_INFO *field_cs, - partition_value_print_mode_t mode) - const -{ - DBUG_ASSERT(cmp_type() != INT_RESULT); - - if (field_cs && field_cs != item_expr->collation.collation) - { - if (!(item_expr= convert_charset_partition_constant(item_expr, - field_cs))) - { - my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); - return true; - } - } - StringBuffer<MAX_KEY_LENGTH> buf; - String val_conv, *res; - val_conv.set_charset(system_charset_info); - if (!(res= item_expr->val_str(&buf))) - { - my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); - return true; - } - if (get_cs_converted_part_value_from_string(current_thd, - item_expr, res, - &val_conv, field_cs, - mode == - PARTITION_VALUE_PRINT_MODE_FRM)) - return true; - return str->append(val_conv); -} - - static int add_column_list_values(String *str, partition_info *part_info, part_elem_value *list_value, HA_CREATE_INFO *create_info, @@ -2564,6 +2482,10 @@ char *generate_partition_syntax_for_frm(THD *thd, partition_info *part_info, Sql_mode_instant_remove sms(thd, MODE_ANSI_QUOTES); char *res= generate_partition_syntax(thd, part_info, buf_length, true, create_info, alter_info); + DBUG_EXECUTE_IF("generate_partition_syntax_for_frm", + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_YES, + ErrConvString(res, (uint32) *buf_length, + system_charset_info).ptr());); return res; } |