1
0
mirror of https://github.com/MariaDB/server.git synced 2025-12-24 11:21:21 +03:00

Bug#11853126 RE-ENABLE CONCURRENT READS WHILE CREATING

SECONDARY INDEX IN INNODB

The patches for Bug#11751388 and Bug#11784056 enabled concurrent
reads while creating secondary indexes in InnoDB. However, they
introduced a regression. This regression occured if ALTER TABLE
failed after the index had been added, for example during the
lock upgrade needed to update .FRM. If this happened, InnoDB
and the server got out of sync with regards to which indexes
actually existed. Therefore the patch for Bug#11815600 again
disabled concurrent reads.

This patch re-enables concurrent reads. The original regression
is fixed by splitting the ADD INDEX operation into two parts.
First the new index is created but not made active. This is
done while concurrent reads are allowed. The second part of
the operation makes the index active (or reverts the change).
This is done after lock upgrade, which prevents the original
regression.

In order to implement this change, the patch changes the storage
API for in-place index creation. handler::add_index() is split
into two functions, handler_add_index() and
handler::final_add_index(). The former for creating indexes without
making them visible and the latter for commiting (i.e. making
visible) new indexes or reverting the changes.

Large parts of this patch were written by Marko Mäkelä.

Test case added to innodb_mysql_lock.test.
This commit is contained in:
Jon Olav Hauglid
2011-06-01 10:06:55 +02:00
parent bd708b4240
commit f21fd6e40f
11 changed files with 578 additions and 235 deletions

View File

@@ -5680,6 +5680,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
uint index_drop_count= 0;
uint *index_drop_buffer= NULL;
uint index_add_count= 0;
handler_add_index *add= NULL;
bool pending_inplace_add_index= false;
uint *index_add_buffer= NULL;
uint candidate_key_count= 0;
bool no_pk;
@@ -6434,6 +6436,9 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
if (error)
goto err_new_table_cleanup;
/* If we did not need to copy, we might still need to add/drop indexes. */
if (! new_table)
{
@@ -6465,7 +6470,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
key_part->field= table->field[key_part->fieldnr];
}
/* Add the indexes. */
if ((error= table->file->add_index(table, key_info, index_add_count)))
if ((error= table->file->add_index(table, key_info, index_add_count,
&add)))
{
/*
Exchange the key_info for the error message. If we exchange
@@ -6477,11 +6483,27 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
table->key_info= save_key_info;
goto err_new_table_cleanup;
}
pending_inplace_add_index= true;
}
/*end of if (index_add_count)*/
if (index_drop_count)
{
/* Currently we must finalize add index if we also drop indexes */
if (pending_inplace_add_index)
{
/* Committing index changes needs exclusive metadata lock. */
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE,
table_list->db,
table_list->table_name,
MDL_EXCLUSIVE));
if ((error= table->file->final_add_index(add, true)))
{
table->file->print_error(error, MYF(0));
goto err_new_table_cleanup;
}
pending_inplace_add_index= false;
}
/* The prepare_drop_index() method takes an array of key numbers. */
key_numbers= (uint*) thd->alloc(sizeof(uint) * index_drop_count);
keyno_p= key_numbers;
@@ -6522,11 +6544,14 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
}
/*end of if (! new_table) for add/drop index*/
if (error)
goto err_new_table_cleanup;
if (table->s->tmp_table != NO_TMP_TABLE)
{
/*
In-place operations are not supported for temporary tables, so
we don't have to call final_add_index() in this case. The assert
verifies that in-place add index has not been done.
*/
DBUG_ASSERT(!pending_inplace_add_index);
/* Close lock if this is a transactional table */
if (thd->lock)
{
@@ -6593,8 +6618,30 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
my_casedn_str(files_charset_info, old_name);
if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
{
if (pending_inplace_add_index)
{
pending_inplace_add_index= false;
table->file->final_add_index(add, false);
}
// Mark this TABLE instance as stale to avoid out-of-sync index information.
table->m_needs_reopen= true;
goto err_new_table_cleanup;
}
if (pending_inplace_add_index)
{
pending_inplace_add_index= false;
DBUG_EXECUTE_IF("alter_table_rollback_new_index", {
table->file->final_add_index(add, false);
my_error(ER_UNKNOWN_ERROR, MYF(0));
goto err_new_table_cleanup;
});
if ((error= table->file->final_add_index(add, true)))
{
table->file->print_error(error, MYF(0));
goto err_new_table_cleanup;
}
}
close_all_tables_for_name(thd, table->s,
new_name != table_name || new_db != db);