diff --git a/mysql-test/suite/innodb/r/innodb-index-online.result b/mysql-test/suite/innodb/r/innodb-index-online.result index cc900ff0201..a0227d31393 100644 --- a/mysql-test/suite/innodb/r/innodb-index-online.result +++ b/mysql-test/suite/innodb/r/innodb-index-online.result @@ -43,6 +43,10 @@ SET DEBUG_DBUG = '+d,innodb_OOM_inplace_alter'; CREATE UNIQUE INDEX c2 ON t1(c2); ERROR HY000: Out of memory. SET DEBUG_DBUG = @saved_debug_dbug; +SET DEBUG_DBUG = '+d,innodb_OOM_prepare_add_index'; +ALTER TABLE t1 ADD KEY(c2), ADD KEY c3_10(c3(10)), ADD KEY c3_c2(c3(4),c2); +ERROR HY000: Out of memory. +SET DEBUG_DBUG = @saved_debug_dbug; CREATE UNIQUE INDEX c2 ON t1(c2); DROP INDEX c2 ON t1; connection default; diff --git a/mysql-test/suite/innodb/t/innodb-index-online.test b/mysql-test/suite/innodb/t/innodb-index-online.test index 5d92b010e60..4cdbdb7c584 100644 --- a/mysql-test/suite/innodb/t/innodb-index-online.test +++ b/mysql-test/suite/innodb/t/innodb-index-online.test @@ -53,6 +53,10 @@ SET DEBUG_DBUG = '+d,innodb_OOM_inplace_alter'; --error ER_OUT_OF_RESOURCES CREATE UNIQUE INDEX c2 ON t1(c2); SET DEBUG_DBUG = @saved_debug_dbug; +SET DEBUG_DBUG = '+d,innodb_OOM_prepare_add_index'; +--error ER_OUT_OF_RESOURCES +ALTER TABLE t1 ADD KEY(c2), ADD KEY c3_10(c3(10)), ADD KEY c3_c2(c3(4),c2); +SET DEBUG_DBUG = @saved_debug_dbug; CREATE UNIQUE INDEX c2 ON t1(c2); DROP INDEX c2 ON t1; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 84f0857dcb7..ae634c791b1 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -5659,11 +5659,9 @@ index_created: if (index) { dict_mem_index_free(index); } - a++; error_handling_drop_uncached: - while (a < ctx->num_to_add_index) { - dict_mem_index_free( - ctx->add_index[a++]); + while (++a < ctx->num_to_add_index) { + dict_mem_index_free(ctx->add_index[a]); } goto error_handling; } else { @@ -5693,10 +5691,6 @@ error_handling_drop_uncached: /* No need to allocate a modification log. */ DBUG_ASSERT(!index->online_log); } else { - DBUG_EXECUTE_IF( - "innodb_OOM_prepare_inplace_alter", - error = DB_OUT_OF_MEMORY; - goto error_handling_drop_uncached;); rw_lock_x_lock(&ctx->add_index[a]->lock); bool ok = row_log_allocate( @@ -5708,6 +5702,14 @@ error_handling_drop_uncached: rw_lock_x_unlock(&index->lock); + DBUG_EXECUTE_IF( + "innodb_OOM_prepare_add_index", + if (ok && a == 1) { + row_log_free( + index->online_log); + ok = false; + }); + if (!ok) { error = DB_OUT_OF_MEMORY; goto error_handling_drop_uncached;