Merge branch '10.5' into bb-10.5-release

This commit is contained in:
Oleksandr Byelkin 2021-11-08 19:40:39 +01:00
commit d8d6e99528
18 changed files with 232 additions and 21 deletions

View File

@ -1,4 +1,4 @@
MYSQL_VERSION_MAJOR=10
MYSQL_VERSION_MINOR=5
MYSQL_VERSION_PATCH=13
MYSQL_VERSION_PATCH=14
SERVER_MATURITY=stable

View File

@ -3373,5 +3373,31 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
#
# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed
#
set @save_default_engine= @@default_storage_engine;
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam;
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x));
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
drop table t1;
set @@default_storage_engine= @save_default_engine;
#
# MDEV-25555 Server crashes in tree_record_pos after INPLACE-recreating index on HEAP table
#
create table t1 (a int, key idx1(a), key idx2 using btree(a)) engine=memory;
alter table t1 rename index idx1 to idx3, algorithm=inplace;
delete from t1 where a = 10;
alter table t1 drop key idx3, add key idx1(a), algorithm=inplace;
ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY
delete from t1 where a = 11;
drop table t1;
#
# End of 10.5 tests
#

View File

@ -2567,6 +2567,59 @@ alter table t1 rename column abc to ABC;
show create table t1;
drop table t1;
--echo #
--echo # MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed
--echo #
set @save_default_engine= @@default_storage_engine;
--disable_query_log
if ($MTR_COMBINATION_INNODB)
{
set default_storage_engine= innodb;
}
if ($MTR_COMBINATION_ARIA)
{
set default_storage_engine= aria;
}
--enable_query_log
if (!$MTR_COMBINATION_INNODB)
{
--disable_query_log
--disable_result_log
# There is no inplace ADD INDEX for MyISAM/Aria:
create or replace table t1 (x int);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add unique (x), algorithm=inplace;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add primary key(x), algorithm=inplace;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add index(x), algorithm=inplace;
--enable_query_log
--enable_result_log
}
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam;
alter table t1 change x xx int, algorithm=inplace;
check table t1;
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x));
alter table t1 change x xx int, algorithm=inplace;
check table t1;
# cleanup
drop table t1;
set @@default_storage_engine= @save_default_engine;
--echo #
--echo # MDEV-25555 Server crashes in tree_record_pos after INPLACE-recreating index on HEAP table
--echo #
create table t1 (a int, key idx1(a), key idx2 using btree(a)) engine=memory;
alter table t1 rename index idx1 to idx3, algorithm=inplace;
delete from t1 where a = 10;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 drop key idx3, add key idx1(a), algorithm=inplace;
delete from t1 where a = 11;
# cleanup
drop table t1;
--echo #
--echo # End of 10.5 tests
--echo #

View File

@ -6473,5 +6473,24 @@ CAST(_ucs2 0x0061E0030062 AS INT)
Warnings:
Warning 1292 Truncated incorrect INTEGER value: 'ab'
#
# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
#
SET NAMES utf8, collation_connection=ucs2_general_ci;
SELECT 1 COLLATE ucs2_general_ci;
1 COLLATE ucs2_general_ci
1
SELECT 1 COLLATE ucs2_bin;
1 COLLATE ucs2_bin
1
SELECT HEX(1 COLLATE ucs2_general_ci);
HEX(1 COLLATE ucs2_general_ci)
0031
SELECT HEX(1 COLLATE ucs2_bin);
HEX(1 COLLATE ucs2_bin)
0031
SELECT 1 COLLATE latin1_swedish_ci;
ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'ucs2'
SET NAMES utf8;
#
# End of 10.5 tests
#

View File

@ -1146,6 +1146,19 @@ SELECT CAST(_ucs2 0x0061DFFF0062 AS INT);
SELECT CAST(_ucs2 0x0061D7000062 AS INT);
SELECT CAST(_ucs2 0x0061E0030062 AS INT);
--echo #
--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
--echo #
SET NAMES utf8, collation_connection=ucs2_general_ci;
SELECT 1 COLLATE ucs2_general_ci;
SELECT 1 COLLATE ucs2_bin;
SELECT HEX(1 COLLATE ucs2_general_ci);
SELECT HEX(1 COLLATE ucs2_bin);
--error ER_COLLATION_CHARSET_MISMATCH
SELECT 1 COLLATE latin1_swedish_ci;
SET NAMES utf8;
--echo #
--echo # End of 10.5 tests
--echo #

View File

@ -4149,3 +4149,21 @@ c
#
# End of 10.2 tests
#
#
# Start of 10.5 tests
#
#
# MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
#
SET NAMES utf8mb4;
SELECT 1 COLLATE utf8mb4_general_ci;
1 COLLATE utf8mb4_general_ci
1
SELECT 1 COLLATE utf8mb4_bin;
1 COLLATE utf8mb4_bin
1
SELECT 1 COLLATE latin1_swedish_ci;
ERROR 42000: COLLATION 'latin1_swedish_ci' is not valid for CHARACTER SET 'utf8mb4'
#
# End of 10.5 tests
#

View File

@ -2043,3 +2043,22 @@ EXECUTE IMMEDIATE 'SELECT ''😎'' AS c';
--echo #
--echo # End of 10.2 tests
--echo #
--echo #
--echo # Start of 10.5 tests
--echo #
--echo #
--echo # MDEV-24584 Selecting INT column with COLLATE utf8mb4_general_ci throws an error
--echo #
SET NAMES utf8mb4;
SELECT 1 COLLATE utf8mb4_general_ci;
SELECT 1 COLLATE utf8mb4_bin;
--error ER_COLLATION_CHARSET_MISMATCH
SELECT 1 COLLATE latin1_swedish_ci;
--echo #
--echo # End of 10.5 tests
--echo #

View File

@ -596,17 +596,17 @@ t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
UNIQUE KEY `db_row_hash_1` (`db_row_hash_1`),
UNIQUE KEY `db_row_hash_2` (`db_row_hash_2`),
UNIQUE KEY `d` (`d`) USING HASH,
UNIQUE KEY `e` (`e`),
UNIQUE KEY `a` (`a`),
UNIQUE KEY `d` (`d`) USING HASH
UNIQUE KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 0 db_row_hash_1 1 db_row_hash_1 A NULL NULL NULL YES BTREE
t1 0 db_row_hash_2 1 db_row_hash_2 A NULL NULL NULL YES BTREE
t1 0 d 1 d A NULL NULL NULL YES HASH
t1 0 e 1 e A NULL NULL NULL YES BTREE
t1 0 a 1 a A NULL NULL NULL YES BTREE
t1 0 d 1 d A NULL NULL NULL YES HASH
alter table t1 add column clm1 blob unique,add column clm2 blob unique;
#try changing the name;
alter table t1 change column clm1 clm_changed1 blob, change column clm2 clm_changed2 blob;

View File

@ -479,6 +479,7 @@ enum chf_create_flags {
#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
@ -785,6 +786,13 @@ typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
*/
#define ALTER_COLUMN_INDEX_LENGTH (1ULL << 60)
/**
Indicate that index order might have been changed. Disables inplace algorithm
by default (not for InnoDB).
*/
#define ALTER_INDEX_ORDER (1ULL << 61)
/*
Flags set in partition_flags when altering partitions
*/

View File

@ -3552,10 +3552,12 @@ String *Item_func_set_collation::val_str(String *str)
bool Item_func_set_collation::fix_length_and_dec()
{
if (!my_charset_same(args[0]->collation.collation, m_set_collation))
if (agg_arg_charsets_for_string_result(collation, args, 1))
return true;
if (!my_charset_same(collation.collation, m_set_collation))
{
my_error(ER_COLLATION_CHARSET_MISMATCH, MYF(0),
m_set_collation->name, args[0]->collation.collation->csname);
m_set_collation->name, collation.collation->csname);
return TRUE;
}
collation.set(m_set_collation, DERIVATION_EXPLICIT,

View File

@ -259,7 +259,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
@ -279,7 +279,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

View File

@ -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];

View File

@ -4435,9 +4435,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. */
@ -8380,7 +8401,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;
@ -8804,6 +8824,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++))
@ -8817,7 +8843,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++)
@ -8904,13 +8930,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
{
@ -8959,7 +8991,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);
}
@ -9003,7 +9035,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;
@ -10589,6 +10621,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;
error= create_table_impl(thd, alter_ctx.db, alter_ctx.table_name,
alter_ctx.new_db, alter_ctx.tmp_name,
@ -10625,7 +10661,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.
@ -10640,6 +10676,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);

View File

@ -7205,7 +7205,8 @@ ha_connect::check_if_supported_inplace_alter(TABLE *altered_table,
ALTER_ADD_UNIQUE_INDEX |
ALTER_DROP_UNIQUE_INDEX |
ALTER_ADD_PK_INDEX |
ALTER_DROP_PK_INDEX;
ALTER_DROP_PK_INDEX |
ALTER_INDEX_ORDER;
alter_table_operations inplace_offline_operations=
ALTER_COLUMN_TYPE_CHANGE_BY_ENGINE |

View File

@ -114,6 +114,7 @@ static const alter_table_operations INNOBASE_INPLACE_IGNORE
| ALTER_VIRTUAL_GCOL_EXPR
| ALTER_DROP_CHECK_CONSTRAINT
| ALTER_RENAME
| ALTER_INDEX_ORDER
| ALTER_COLUMN_INDEX_LENGTH
| ALTER_CHANGE_INDEX_COMMENT;
@ -2454,7 +2455,8 @@ next_column:
| ALTER_ADD_UNIQUE_INDEX
*/
| ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX
| ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX);
| ALTER_DROP_NON_UNIQUE_NON_PRIM_INDEX
| ALTER_INDEX_ORDER);
if (supports_instant) {
flags &= ~(ALTER_DROP_STORED_COLUMN
#if 0 /* MDEV-17468: remove check_v_col_in_order() and fix the code */

View File

@ -735,6 +735,11 @@ static int table2maria(TABLE *table_arg, data_file_type row_type,
- compare SPATIAL keys;
- compare FIELD_SKIP_ZERO which is converted to FIELD_NORMAL correctly
(should be correctly detected in table2maria).
FIXME:
maria_check_definition() is never used! CHECK TABLE does not detect the
corruption! Do maria_check_definition() like check_definition() is done
by MyISAM (related to MDEV-25803).
*/
int maria_check_definition(MARIA_KEYDEF *t1_keyinfo,

View File

@ -713,7 +713,11 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
}
#endif
/* Write key and keyseg definitions */
/* Write key and keyseg definitions
TODO: update key and keyseg definitions for inplace alter (grep sql layer by
MDEV-25803). Do the same for Aria.
*/
DBUG_PRINT("info", ("write key and keyseg definitions"));
for (i=0 ; i < share.base.keys - uniques; i++)
{

View File

@ -12427,6 +12427,7 @@ my_core::enum_alter_inplace_result ha_rocksdb::check_if_supported_inplace_alter(
ALTER_ADD_NON_UNIQUE_NON_PRIM_INDEX |
ALTER_PARTITIONED |
ALTER_ADD_UNIQUE_INDEX |
ALTER_INDEX_ORDER |
ALTER_CHANGE_CREATE_OPTION)) {
DBUG_RETURN(my_core::HA_ALTER_INPLACE_NOT_SUPPORTED);
}