1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Merge 10.6 into 10.7

This commit is contained in:
Marko Mäkelä
2021-11-09 09:40:29 +02:00
60 changed files with 1773 additions and 101 deletions

View File

@ -3553,9 +3553,30 @@ without_overlaps_err:
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. */
@ -7767,7 +7788,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;
@ -8191,6 +8211,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.str);
const bool implicit_pk= primary_key && !explicit_pk;
Alter_drop *drop;
drop_it.rewind();
while ((drop=drop_it++))
@ -8204,7 +8230,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++)
@ -8303,13 +8329,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
{
@ -8358,7 +8390,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);
}
@ -8403,7 +8435,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.str))
if (explicit_pk)
key_type= Key::PRIMARY;
else
key_type= Key::UNIQUE;
@ -10135,6 +10167,10 @@ 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;
else
alter_info->flags|= ALTER_INDEX_ORDER;
create_info->alias= alter_ctx.table_name;
/*
Create the .frm file for the new table. Storage engine table will not be
@ -10193,7 +10229,7 @@ do_continue:;
*/
if (!(ha_alter_info.handler_flags &
~(ALTER_COLUMN_ORDER | ALTER_RENAME_COLUMN)))
~(ALTER_COLUMN_ORDER | ALTER_RENAME_COLUMN | ALTER_INDEX_ORDER)))
{
/*
No-op ALTER, no need to call handler API functions.
@ -10208,6 +10244,9 @@ do_continue:;
Also note that we ignore the LOCK clause here.
TODO don't create partitioning metadata in the first place
TODO: Now case-change index name is treated as noop which is not quite
correct.
*/
table->file->ha_create_partitioning_metadata(alter_ctx.get_tmp_path(),
NULL, CHF_DELETE_FLAG);