diff --git a/mysql-test/r/innodb_autoinc.result b/mysql-test/r/innodb_autoinc.result new file mode 100644 index 0000000..21e8f31 --- /dev/null +++ b/mysql-test/r/innodb_autoinc.result @@ -0,0 +1,24 @@ +drop table if exists autoinno, noautoinno; +create table autoinno(i int not null auto_increment primary key) engine=innodb; +create table noautoinno(i int not null primary key) engine=innodb; +set autocommit=1; +insert into autoinno values (null); +insert into noautoinno values (1); +set autocommit=0; +begin; +insert into autoinno values (null); +insert into noautoinno values (2); +rollback; +begin; +insert into autoinno values (null); +insert into noautoinno values (2); +commit; +select * from autoinno; +i +1 +3 +select * from noautoinno; +i +1 +2 +drop table autoinno, noautoinno; diff --git a/mysql-test/t/innodb_autoinc.test b/mysql-test/t/innodb_autoinc.test new file mode 100644 index 0000000..e31ae4e --- /dev/null +++ b/mysql-test/t/innodb_autoinc.test @@ -0,0 +1,32 @@ +# Simple test for autoincrement with and without autocommit + +-- source include/have_innodb.inc + +--disable_warnings +drop table if exists autoinno, noautoinno; +--enable_warnings + +create table autoinno(i int not null auto_increment primary key) engine=innodb; +create table noautoinno(i int not null primary key) engine=innodb; + +set autocommit=1; +insert into autoinno values (null); +insert into noautoinno values (1); + +set autocommit=0; + +begin; +insert into autoinno values (null); +insert into noautoinno values (2); +rollback; + +begin; +insert into autoinno values (null); +insert into noautoinno values (2); +commit; + +select * from autoinno; +select * from noautoinno; + +drop table autoinno, noautoinno; + diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 3b450c3..3c72c67 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -7550,6 +7550,23 @@ innobase_xa_prepare( int error = 0; trx_t* trx = check_trx_exists(thd); + /* Release a possible FIFO ticket and search latch. Since we will + reserve the kernel mutex, we have to release the search system latch + first to obey the latching order. Do this before blocking on a global + mutex. */ + + innobase_release_stat_resources(trx); + + /* If this is an autocommit statment, release the autoinc lock before + blocking on prepare_commit_mutex. */ + if (!all && + !(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) && + trx->auto_inc_lock && + thd->lex->sql_command != SQLCOM_XA_PREPARE) { + + row_unlock_table_autoinc_for_mysql(trx); + } + if (thd->lex->sql_command != SQLCOM_XA_PREPARE) { /* For ibbackup to work the order of transactions in binlog @@ -7582,12 +7599,6 @@ innobase_xa_prepare( trx->xid=thd->transaction.xid_state.xid; - /* Release a possible FIFO ticket and search latch. Since we will - reserve the kernel mutex, we have to release the search system latch - first to obey the latching order. */ - - innobase_release_stat_resources(trx); - if (trx->active_trans == 0 && trx->conc_state != TRX_NOT_STARTED) { sql_print_error("trx->active_trans == 0, but trx->conc_state != " @@ -7607,12 +7618,6 @@ innobase_xa_prepare( /* We just mark the SQL statement ended and do not do a transaction prepare */ - if (trx->auto_inc_lock) { - /* If we had reserved the auto-inc lock for some - table in this SQL statement we release it now */ - - row_unlock_table_autoinc_for_mysql(trx); - } /* Store the current undo_no of the transaction so that we know where to roll back if we have to roll back the next SQL statement */