diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2021-11-09 08:40:14 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2021-11-09 08:40:14 +0200 |
commit | 47ab793d71f2755b026672e4657174a1740b6ae2 (patch) | |
tree | 919aa71c2f31dbafa84a0e3b5fdf61f8d23afd3a /sql | |
parent | de2fa9eced796a38bf2a194f35589f6eef814483 (diff) | |
parent | 524b4a89da3d9143ad72a82d73617ffde9e3a7a8 (diff) | |
download | mariadb-git-47ab793d71f2755b026672e4657174a1740b6ae2.tar.gz |
Merge 10.3 into 10.4
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_partition.cc | 7 | ||||
-rw-r--r-- | sql/handler.cc | 10 | ||||
-rw-r--r-- | sql/handler.h | 1 | ||||
-rw-r--r-- | sql/item.h | 13 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 4 | ||||
-rw-r--r-- | sql/mysqld.cc | 1 | ||||
-rw-r--r-- | sql/sql_alter.cc | 4 | ||||
-rw-r--r-- | sql/sql_alter.h | 1 | ||||
-rw-r--r-- | sql/sql_table.cc | 52 |
9 files changed, 69 insertions, 24 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index c8d5d68b5d6..7f53eeb565c 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -10932,11 +10932,8 @@ 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", - table_share->db.str, table->alias, - opt_op_name[CHECK_PARTS], - "Not supported for non-INTERVAL history partitions"); - DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED); + /* Skip this check as it is not supported for non-INTERVAL history partitions. */ + DBUG_RETURN(HA_ADMIN_OK); } if (do_repair) diff --git a/sql/handler.cc b/sql/handler.cc index f7fb0ea4854..812de48fa68 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -7523,15 +7523,16 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields( if (!vers_info.need_check(alter_info)) return false; - if (!vers_info.versioned_fields && vers_info.unversioned_fields && - !(alter_info->flags & ALTER_ADD_SYSTEM_VERSIONING)) + const bool add_versioning= alter_info->flags & ALTER_ADD_SYSTEM_VERSIONING; + + if (!vers_info.versioned_fields && vers_info.unversioned_fields && !add_versioning) { // All is correct but this table is not versioned. options&= ~HA_VERSIONED_TABLE; return false; } - if (!(alter_info->flags & ALTER_ADD_SYSTEM_VERSIONING) && vers_info) + if (!add_versioning && vers_info && !vers_info.versioned_fields) { my_error(ER_MISSING, MYF(0), create_table.table_name.str, "WITH SYSTEM VERSIONING"); @@ -7541,8 +7542,7 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields( List_iterator<Create_field> it(alter_info->create_list); while (Create_field *f= it++) { - if ((f->versioning == Column_definition::VERSIONING_NOT_SET && - !(alter_info->flags & ALTER_ADD_SYSTEM_VERSIONING)) || + if ((f->versioning == Column_definition::VERSIONING_NOT_SET && !add_versioning) || f->versioning == Column_definition::WITHOUT_VERSIONING) { f->flags|= VERS_UPDATE_UNVERSIONED_FLAG; diff --git a/sql/handler.h b/sql/handler.h index f3be9e7de6a..94ac56c3073 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -454,6 +454,7 @@ enum enum_alter_inplace_result { #define HA_CREATE_TMP_ALTER 8U #define HA_LEX_CREATE_SEQUENCE 16U #define HA_VERSIONED_TABLE 32U +#define HA_SKIP_KEY_SORT 64U #define HA_MAX_REC_LENGTH 65535 diff --git a/sql/item.h b/sql/item.h index 6b64e7788bc..2e4383cf9ac 100644 --- a/sql/item.h +++ b/sql/item.h @@ -7540,6 +7540,19 @@ public: /* + fix_escape_item() sets the out "escape" parameter to: + - native code in case of an 8bit character set + - Unicode code point in case of a multi-byte character set + + The value meaning a not-initialized ESCAPE character must not be equal to + any valid value, so must be outside of these ranges: + - -128..+127, not to conflict with a valid 8bit charcter + - 0..0x10FFFF, not to conflict with a valid Unicode code point + The exact value does not matter. +*/ +#define ESCAPE_NOT_INITIALIZED -1000 + +/* It's used in ::fix_fields() methods of LIKE and JSON_SEARCH functions to handle the ESCAPE parameter. This parameter is quite non-standard so the specific function. diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 6cf8b985486..c2e58a72dd2 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5476,7 +5476,7 @@ void Item_func_like::print(String *str, enum_query_type query_type) longlong Item_func_like::val_int() { DBUG_ASSERT(fixed == 1); - DBUG_ASSERT(escape != -1); + DBUG_ASSERT(escape != ESCAPE_NOT_INITIALIZED); String* res= args[0]->val_str(&cmp_value1); if (args[0]->null_value) { @@ -5580,7 +5580,7 @@ bool fix_escape_item(THD *thd, Item *escape_item, String *tmp_str, return TRUE; } - IF_DBUG(*escape= -1,); + IF_DBUG(*escape= ESCAPE_NOT_INITIALIZED,); if (escape_item->const_item()) { diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ec77366129a..7d734d091cd 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8908,7 +8908,6 @@ static int get_options(int *argc_ptr, char ***argv_ptr) { /* Allow break with SIGINT, no core or stack trace */ test_flags|= TEST_SIGINT; - opt_stack_trace= 1; test_flags&= ~TEST_CORE_ON_SIGNAL; } /* Set global MyISAM variables from delay_key_write_options */ diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index f1a67e7d968..6d75c20e868 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -256,7 +256,7 @@ Alter_table_ctx::Alter_table_ctx() db(null_clex_str), table_name(null_clex_str), alias(null_clex_str), new_db(null_clex_str), new_name(null_clex_str), new_alias(null_clex_str), fk_error_if_delete_row(false), fk_error_id(NULL), - fk_error_table(NULL) + fk_error_table(NULL), modified_primary_key(false) #ifdef DBUG_ASSERT_EXISTS , tmp_table(false) #endif @@ -276,7 +276,7 @@ Alter_table_ctx::Alter_table_ctx(THD *thd, TABLE_LIST *table_list, tables_opened(tables_opened_arg), new_db(*new_db_arg), new_name(*new_name_arg), fk_error_if_delete_row(false), fk_error_id(NULL), - fk_error_table(NULL) + fk_error_table(NULL), modified_primary_key(false) #ifdef DBUG_ASSERT_EXISTS , tmp_table(false) #endif diff --git a/sql/sql_alter.h b/sql/sql_alter.h index 71920b84792..d9749592a4f 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -324,6 +324,7 @@ public: const char *fk_error_id; /** Name of table for the above error. */ const char *fk_error_table; + bool modified_primary_key; private: char new_filename[FN_REFLEN + 1]; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index f64abe72bac..e46a13ce7a9 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4256,9 +4256,30 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, my_message(ER_WRONG_AUTO_KEY, ER_THD(thd, ER_WRONG_AUTO_KEY), MYF(0)); DBUG_RETURN(TRUE); } - /* Sort keys in optimized order */ - my_qsort((uchar*) *key_info_buffer, *key_count, sizeof(KEY), - (qsort_cmp) sort_keys); + /* + We cannot do qsort of key info if MyISAM/Aria does inplace. These engines + do not synchronise key info on inplace alter and that qsort is + indeterministic (MDEV-25803). + + Yet we do not know whether we do inplace or not. That detection is done + after this create_table_impl() and that cannot be changed because of chicken + and egg problem (inplace processing requires key info made by + create_table_impl()). + + MyISAM/Aria cannot add index inplace so we are safe to qsort key info in + that case. And if we don't add index then we do not need qsort at all. + */ + if (!(create_info->options & HA_SKIP_KEY_SORT)) + { + /* + Sort keys in optimized order. + + Note: PK must be always first key, otherwise init_from_binary_frm_image() + can not understand it. + */ + my_qsort((uchar*) *key_info_buffer, *key_count, sizeof(KEY), + (qsort_cmp) sort_keys); + } create_info->null_bits= null_fields; /* Check fields. */ @@ -8085,7 +8106,6 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, uint used_fields, dropped_sys_vers_fields= 0; KEY *key_info=table->key_info; bool rc= TRUE; - bool modified_primary_key= FALSE; bool vers_system_invisible= false; Create_field *def; Field **f_ptr,*field; @@ -8471,6 +8491,12 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, if (key_info->flags & HA_INVISIBLE_KEY) continue; const char *key_name= key_info->name.str; + const bool primary_key= table->s->primary_key == i; + const bool explicit_pk= primary_key && + !my_strcasecmp(system_charset_info, key_name, + primary_key_name); + const bool implicit_pk= primary_key && !explicit_pk; + Alter_drop *drop; drop_it.rewind(); while ((drop=drop_it++)) @@ -8484,7 +8510,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, if (table->s->tmp_table == NO_TMP_TABLE) { (void) delete_statistics_for_index(thd, table, key_info, FALSE); - if (i == table->s->primary_key) + if (primary_key) { KEY *tab_key_info= table->key_info; for (uint j=0; j < table->s->keys; j++, tab_key_info++) @@ -8534,13 +8560,19 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } if (!cfield) { - if (table->s->primary_key == i) - modified_primary_key= TRUE; + if (primary_key) + alter_ctx->modified_primary_key= true; delete_index_stat= TRUE; if (!(kfield->flags & VERS_SYSTEM_FIELD)) dropped_key_part= key_part_name; continue; // Field is removed } + + DBUG_ASSERT(!primary_key || kfield->flags & NOT_NULL_FLAG); + if (implicit_pk && !alter_ctx->modified_primary_key && + !(cfield->flags & NOT_NULL_FLAG)) + alter_ctx->modified_primary_key= true; + key_part_length= key_part->length; if (cfield->field) // Not new field { @@ -8589,7 +8621,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, { if (delete_index_stat) (void) delete_statistics_for_index(thd, table, key_info, FALSE); - else if (modified_primary_key && + else if (alter_ctx->modified_primary_key && key_info->user_defined_key_parts != key_info->ext_key_parts) (void) delete_statistics_for_index(thd, table, key_info, TRUE); } @@ -8633,7 +8665,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, key_type= Key::SPATIAL; else if (key_info->flags & HA_NOSAME) { - if (! my_strcasecmp(system_charset_info, key_name, primary_key_name)) + if (explicit_pk) key_type= Key::PRIMARY; else key_type= Key::UNIQUE; @@ -10123,6 +10155,8 @@ do_continue:; tmp_disable_binlog(thd); create_info->options|=HA_CREATE_TMP_ALTER; + if (!(alter_info->flags & ALTER_ADD_INDEX) && !alter_ctx.modified_primary_key) + create_info->options|= HA_SKIP_KEY_SORT; create_info->alias= alter_ctx.table_name; error= create_table_impl(thd, alter_ctx.db, alter_ctx.table_name, alter_ctx.new_db, alter_ctx.tmp_name, |