summaryrefslogtreecommitdiff
path: root/sql/ha_innodb.cc
diff options
context:
space:
mode:
authorunknown <marko@hundin.mysql.fi>2004-11-30 17:34:37 +0200
committerunknown <marko@hundin.mysql.fi>2004-11-30 17:34:37 +0200
commitd6180d37be0fb11c5e1a5b9a090506e015934368 (patch)
tree0404a4610240b6bc7fb2939fc6f6ffe6494d7939 /sql/ha_innodb.cc
parent346dce93c2a63757540ed15e660dd07d41f7f20d (diff)
downloadmariadb-git-d6180d37be0fb11c5e1a5b9a090506e015934368.tar.gz
InnoDB: Allow ALTER TABLE to do intermediate COMMIT also when the table
contains auto_increment columns. (Bug #6633) innobase/include/lock0lock.h: Replaced lock_get_table() with lock_get_src_table() and lock_is_table_exclusive() innobase/lock/lock0lock.c: Replaced lock_get_table() with lock_get_src_table() and lock_is_table_exclusive() sql/ha_innodb.cc: ha_innobase::write_row(): Improve the ALTER TABLE optimization (do intermediate COMMIT also if table contains auto_increment columns)
Diffstat (limited to 'sql/ha_innodb.cc')
-rw-r--r--sql/ha_innodb.cc51
1 files changed, 27 insertions, 24 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 2aaf69bd208..cc69762cbdb 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -2325,29 +2325,44 @@ ha_innobase::write_row(
intermediate COMMIT, since writes by other transactions are
being blocked by a MySQL table lock TL_WRITE_ALLOW_READ. */
- dict_table_t* table;
+ dict_table_t* src_table;
ibool mode;
num_write_row = 0;
/* Commit the transaction. This will release the table
locks, so they have to be acquired again. */
- switch (prebuilt->trx->mysql_n_tables_locked) {
- case 1:
+
+ /* Altering an InnoDB table */
+ /* Get the source table. */
+ src_table = lock_get_src_table(
+ prebuilt->trx, prebuilt->table, &mode);
+ if (!src_table) {
+ no_commit:
+ /* Unknown situation: do not commit */
+ /*
+ ut_print_timestamp(stderr);
+ fprintf(stderr,
+ " InnoDB error: ALTER TABLE is holding lock"
+ " on %lu tables!\n",
+ prebuilt->trx->mysql_n_tables_locked);
+ */
+ ;
+ } else if (src_table == prebuilt->table) {
+ /* Source table is not in InnoDB format:
+ no need to re-acquire locks on it. */
+
/* Altering to InnoDB format */
innobase_commit(user_thd, prebuilt->trx);
/* Note that this transaction is still active. */
user_thd->transaction.all.innodb_active_trans = 1;
/* We will need an IX lock on the destination table. */
prebuilt->sql_stat_start = TRUE;
- break;
- case 2:
- /* Altering an InnoDB table */
- ut_a(UT_LIST_GET_LEN(prebuilt->trx->trx_locks) >= 2);
- table = lock_get_table(
- UT_LIST_GET_FIRST(prebuilt->trx->trx_locks),
- &mode);
- if (!table) {
+ } else {
+ /* Ensure that there are no other table locks than
+ LOCK_IX and LOCK_AUTO_INC on the destination table. */
+ if (!lock_is_table_exclusive(prebuilt->table,
+ prebuilt->trx)) {
goto no_commit;
}
@@ -2357,21 +2372,9 @@ ha_innobase::write_row(
/* Note that this transaction is still active. */
user_thd->transaction.all.innodb_active_trans = 1;
/* Re-acquire the table lock on the source table. */
- row_lock_table_for_mysql(prebuilt, table, mode);
+ row_lock_table_for_mysql(prebuilt, src_table, mode);
/* We will need an IX lock on the destination table. */
prebuilt->sql_stat_start = TRUE;
- break;
- default:
- no_commit:
- /* Unknown situation: do nothing (no commit) */
- /*
- ut_print_timestamp(stderr);
- fprintf(stderr,
- " InnoDB error: ALTER TABLE is holding lock"
- " on %lu tables!\n",
- prebuilt->trx->mysql_n_tables_locked);
- */
- break;
}
}