@@ -1709,6 +1709,7 @@ innobase_fts_check_doc_id_index_in_def(
17091709
17101710return (FTS_NOT_EXIST_DOC_ID_INDEX);
17111711}
1712+
17121713/* ******************************************************************/ /* *
17131714Create an index table where indexes are ordered as follows:
17141715
@@ -1775,26 +1776,11 @@ innobase_create_key_defs(
17751776(only prefix/part of the column is indexed), MySQL will treat the
17761777index as a PRIMARY KEY unless the table already has one. */
17771778
1778- if (n_add > 0 && !new_primary && got_default_clust
1779- && (key_info[*add].flags & HA_NOSAME)
1780- && !(key_info[*add].flags & HA_KEY_HAS_PART_KEY_SEG)) {
1781- uint key_part = key_info[*add].user_defined_key_parts ;
1782-
1783- new_primary = true ;
1779+ ut_ad (altered_table->s ->primary_key == 0
1780+ || altered_table->s ->primary_key == MAX_KEY);
17841781
1785- while (key_part--) {
1786- const uint maybe_null
1787- = key_info[*add].key_part [key_part].key_type
1788- & FIELDFLAG_MAYBE_NULL;
1789- DBUG_ASSERT (!maybe_null
1790- == !key_info[*add].key_part [key_part].
1791- field->real_maybe_null ());
1792-
1793- if (maybe_null) {
1794- new_primary = false ;
1795- break ;
1796- }
1797- }
1782+ if (got_default_clust && !new_primary) {
1783+ new_primary = (altered_table->s ->primary_key != MAX_KEY);
17981784}
17991785
18001786const bool rebuild = new_primary || add_fts_doc_id
@@ -1812,8 +1798,14 @@ innobase_create_key_defs(
18121798ulint primary_key_number;
18131799
18141800if (new_primary) {
1815- DBUG_ASSERT (n_add > 0 );
1816- primary_key_number = *add;
1801+ if (n_add == 0 ) {
1802+ DBUG_ASSERT (got_default_clust);
1803+ DBUG_ASSERT (altered_table->s ->primary_key
1804+ == 0 );
1805+ primary_key_number = 0 ;
1806+ } else {
1807+ primary_key_number = *add;
1808+ }
18171809} else if (got_default_clust) {
18181810/* Create the GEN_CLUST_INDEX */
18191811index_def_t * index = indexdef++;
@@ -2900,6 +2892,8 @@ prepare_inplace_alter_table_dict(
29002892ctx->add_cols = add_cols;
29012893} else {
29022894DBUG_ASSERT (!innobase_need_rebuild (ha_alter_info));
2895+ DBUG_ASSERT (old_table->s ->primary_key
2896+ == altered_table->s ->primary_key );
29032897
29042898if (!ctx->new_table ->fts
29052899 && innobase_fulltext_exist (altered_table)) {
@@ -3892,6 +3886,27 @@ ha_innobase::prepare_inplace_alter_table(
38923886 add_fts_doc_id_idx));
38933887}
38943888
3889+ /* * Get the name of an erroneous key.
3890+ @param[in] error_key_num InnoDB number of the erroneus key
3891+ @param[in] ha_alter_info changes that were being performed
3892+ @param[in] table InnoDB table
3893+ @return the name of the erroneous key */
3894+ static
3895+ const char *
3896+ get_error_key_name (
3897+ ulint error_key_num,
3898+ const Alter_inplace_info* ha_alter_info,
3899+ const dict_table_t * table)
3900+ {
3901+ if (error_key_num == ULINT_UNDEFINED) {
3902+ return (FTS_DOC_ID_INDEX_NAME);
3903+ } else if (ha_alter_info->key_count == 0 ) {
3904+ return (dict_table_get_first_index (table)->name );
3905+ } else {
3906+ return (ha_alter_info->key_info_buffer [error_key_num].name );
3907+ }
3908+ }
3909+
38953910/* * Alter the table structure in-place with operations
38963911specified using Alter_inplace_info.
38973912The level of concurrency allowed during this operation depends
@@ -4009,17 +4024,13 @@ ha_innobase::inplace_alter_table(
40094024case DB_ONLINE_LOG_TOO_BIG:
40104025DBUG_ASSERT (ctx->online );
40114026my_error (ER_INNODB_ONLINE_LOG_TOO_BIG, MYF (0 ),
4012- (prebuilt->trx ->error_key_num == ULINT_UNDEFINED)
4013- ? FTS_DOC_ID_INDEX_NAME
4014- : ha_alter_info->key_info_buffer [
4015- prebuilt->trx ->error_key_num ].name );
4027+ get_error_key_name (prebuilt->trx ->error_key_num ,
4028+ ha_alter_info, prebuilt->table ));
40164029break ;
40174030case DB_INDEX_CORRUPT:
40184031my_error (ER_INDEX_CORRUPT, MYF (0 ),
4019- (prebuilt->trx ->error_key_num == ULINT_UNDEFINED)
4020- ? FTS_DOC_ID_INDEX_NAME
4021- : ha_alter_info->key_info_buffer [
4022- prebuilt->trx ->error_key_num ].name );
4032+ get_error_key_name (prebuilt->trx ->error_key_num ,
4033+ ha_alter_info, prebuilt->table ));
40234034break ;
40244035default :
40254036my_error_innodb (error,
@@ -4829,7 +4840,6 @@ innobase_update_foreign_cache(
48294840" Foreign key constraints for table '%s'"
48304841" are loaded with charset check off" ,
48314842user_table->name );
4832-
48334843}
48344844}
48354845
@@ -4929,14 +4939,13 @@ commit_try_rebuild(
49294939DBUG_RETURN (true );
49304940case DB_ONLINE_LOG_TOO_BIG:
49314941my_error (ER_INNODB_ONLINE_LOG_TOO_BIG, MYF (0 ),
4932- ha_alter_info->key_info_buffer [0 ].name );
4942+ get_error_key_name (err_key, ha_alter_info,
4943+ rebuilt_table));
49334944DBUG_RETURN (true );
49344945case DB_INDEX_CORRUPT:
49354946my_error (ER_INDEX_CORRUPT, MYF (0 ),
4936- (err_key == ULINT_UNDEFINED)
4937- ? FTS_DOC_ID_INDEX_NAME
4938- : ha_alter_info->key_info_buffer [err_key]
4939- .name );
4947+ get_error_key_name (err_key, ha_alter_info,
4948+ rebuilt_table));
49404949DBUG_RETURN (true );
49414950default :
49424951my_error_innodb (error, table_name, user_table->flags );
0 commit comments