diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 25a0f154c25..6e08fc680b2 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -2314,10 +2314,8 @@ ha_innobase::write_row( if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT) table->timestamp_field->set_time(); - num_write_row++; - if (user_thd->lex->sql_command == SQLCOM_ALTER_TABLE - && num_write_row > 10000) { + && num_write_row >= 10000) { /* ALTER TABLE is COMMITted at every 10000 copied rows. The IX table lock for the original table has to be re-issued. As this method will be called on a temporary table where the @@ -2331,14 +2329,20 @@ ha_innobase::write_row( dict_table_t* table = lock_get_ix_table( UT_LIST_GET_FIRST(prebuilt->trx->trx_locks)); num_write_row = 0; + /* Commit the transaction. This will release the table + locks, so they have to be acquired again. */ innobase_commit(user_thd, prebuilt->trx); + /* Note that this transaction is still active. */ user_thd->transaction.all.innodb_active_trans = 1; + /* Re-acquire the IX table lock on the source table. */ row_lock_table_for_mysql(prebuilt, table); - goto new_trx; + /* We will need an IX lock on the destination table. */ + prebuilt->sql_stat_start = TRUE; } + num_write_row++; + if (last_query_id != user_thd->query_id) { - new_trx: prebuilt->sql_stat_start = TRUE; last_query_id = user_thd->query_id;