Commit c3da5b0b authored by marko@hundin.mysql.fi's avatar marko@hundin.mysql.fi

InnoDB: Do not distinguish explicitly requested table locks.

Since UNLOCK TABLES will commit the transaction (and thus release
all InnoDB locks held by it), it is unnecessary to release the
user-requested table locks separately.
parent 24afa4e0
...@@ -413,9 +413,7 @@ lock_table( ...@@ -413,9 +413,7 @@ lock_table(
/* out: DB_SUCCESS, DB_LOCK_WAIT, /* out: DB_SUCCESS, DB_LOCK_WAIT,
DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set,
does nothing; does nothing */
if LOCK_TABLE_EXP bits are set,
creates an explicit table lock */
dict_table_t* table, /* in: database table in dictionary cache */ dict_table_t* table, /* in: database table in dictionary cache */
ulint mode, /* in: lock mode */ ulint mode, /* in: lock mode */
que_thr_t* thr); /* in: query thread */ que_thr_t* thr); /* in: query thread */
...@@ -452,15 +450,6 @@ lock_release_off_kernel( ...@@ -452,15 +450,6 @@ lock_release_off_kernel(
/*====================*/ /*====================*/
trx_t* trx); /* in: transaction */ trx_t* trx); /* in: transaction */
/************************************************************************* /*************************************************************************
Releases table locks explicitly requested with LOCK TABLES (indicated by
lock type LOCK_TABLE_EXP), and releases possible other transactions waiting
because of these locks. */
void
lock_release_tables_off_kernel(
/*===========================*/
trx_t* trx); /* in: transaction */
/*************************************************************************
Cancels a waiting lock request and releases possible other transactions Cancels a waiting lock request and releases possible other transactions
waiting behind it. */ waiting behind it. */
...@@ -612,9 +601,6 @@ extern lock_sys_t* lock_sys; ...@@ -612,9 +601,6 @@ extern lock_sys_t* lock_sys;
/* Lock types */ /* Lock types */
#define LOCK_TABLE 16 /* these type values should be so high that */ #define LOCK_TABLE 16 /* these type values should be so high that */
#define LOCK_REC 32 /* they can be ORed to the lock mode */ #define LOCK_REC 32 /* they can be ORed to the lock mode */
#define LOCK_TABLE_EXP 80 /* explicit table lock (80 = 16 + 64) */
#define LOCK_TABLE_TRANSACTIONAL 144
/* transactional table lock (144 = 16 + 128)*/
#define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the #define LOCK_TYPE_MASK 0xF0UL /* mask used to extract lock type from the
type_mode field in a lock */ type_mode field in a lock */
/* Waiting lock flag */ /* Waiting lock flag */
......
...@@ -172,14 +172,6 @@ row_lock_table_autoinc_for_mysql( ...@@ -172,14 +172,6 @@ row_lock_table_autoinc_for_mysql(
row_prebuilt_t* prebuilt); /* in: prebuilt struct in the MySQL row_prebuilt_t* prebuilt); /* in: prebuilt struct in the MySQL
table handle */ table handle */
/************************************************************************* /*************************************************************************
Unlocks all table locks explicitly requested by trx (with LOCK TABLES,
lock type LOCK_TABLE_EXP). */
void
row_unlock_tables_for_mysql(
/*========================*/
trx_t* trx); /* in: transaction */
/*************************************************************************
Sets a table lock on the table mentioned in prebuilt. */ Sets a table lock on the table mentioned in prebuilt. */
int int
...@@ -190,9 +182,10 @@ row_lock_table_for_mysql( ...@@ -190,9 +182,10 @@ row_lock_table_for_mysql(
table handle */ table handle */
dict_table_t* table, /* in: table to lock, or NULL dict_table_t* table, /* in: table to lock, or NULL
if prebuilt->table should be if prebuilt->table should be
locked as LOCK_TABLE_EXP | locked as
prebuilt->select_lock_type */ prebuilt->select_lock_type */
ulint mode); /* in: lock mode of table */ ulint mode); /* in: lock mode of table
(ignored if table==NULL) */
/************************************************************************* /*************************************************************************
Does an insert for MySQL. */ Does an insert for MySQL. */
......
...@@ -497,13 +497,6 @@ struct trx_struct{ ...@@ -497,13 +497,6 @@ struct trx_struct{
in the lock list trx_locks */ in the lock list trx_locks */
ibool trx_create_lock;/* this is TRUE if we have created a ibool trx_create_lock;/* this is TRUE if we have created a
new lock for a record accessed */ new lock for a record accessed */
ulint n_lock_table_exp;/* number of explicit table locks
(LOCK TABLES) reserved by the
transaction, stored in trx_locks */
ulint n_lock_table_transactional;
/* number of transactional table locks
(LOCK TABLES..WHERE ENGINE) reserved by
the transaction, stored in trx_locks */
UT_LIST_NODE_T(trx_t) UT_LIST_NODE_T(trx_t)
trx_list; /* list of transactions */ trx_list; /* list of transactions */
UT_LIST_NODE_T(trx_t) UT_LIST_NODE_T(trx_t)
......
...@@ -2208,11 +2208,7 @@ lock_grant( ...@@ -2208,11 +2208,7 @@ lock_grant(
release it at the end of the SQL statement */ release it at the end of the SQL statement */
lock->trx->auto_inc_lock = lock; lock->trx->auto_inc_lock = lock;
} else if (lock_get_type(lock) == LOCK_TABLE_EXP || }
lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL) {
ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X);
}
if (lock_print_waits) { if (lock_print_waits) {
fprintf(stderr, "Lock wait for trx %lu ends\n", fprintf(stderr, "Lock wait for trx %lu ends\n",
...@@ -3415,14 +3411,6 @@ lock_table_create( ...@@ -3415,14 +3411,6 @@ lock_table_create(
lock->type_mode = type_mode | LOCK_TABLE; lock->type_mode = type_mode | LOCK_TABLE;
lock->trx = trx; lock->trx = trx;
if (lock_get_type(lock) == LOCK_TABLE_EXP) {
lock->trx->n_lock_table_exp++;
}
if (lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL) {
lock->trx->n_lock_table_transactional++;
}
lock->un_member.tab_lock.table = table; lock->un_member.tab_lock.table = table;
UT_LIST_ADD_LAST(un_member.tab_lock.locks, table->locks, lock); UT_LIST_ADD_LAST(un_member.tab_lock.locks, table->locks, lock);
...@@ -3459,14 +3447,6 @@ lock_table_remove_low( ...@@ -3459,14 +3447,6 @@ lock_table_remove_low(
trx->auto_inc_lock = NULL; trx->auto_inc_lock = NULL;
} }
if (lock_get_type(lock) == LOCK_TABLE_EXP) {
trx->n_lock_table_exp--;
}
if (lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL) {
trx->n_lock_table_transactional--;
}
UT_LIST_REMOVE(trx_locks, trx->trx_locks, lock); UT_LIST_REMOVE(trx_locks, trx->trx_locks, lock);
UT_LIST_REMOVE(un_member.tab_lock.locks, table->locks, lock); UT_LIST_REMOVE(un_member.tab_lock.locks, table->locks, lock);
} }
...@@ -3597,10 +3577,7 @@ lock_table( ...@@ -3597,10 +3577,7 @@ lock_table(
/* out: DB_SUCCESS, DB_LOCK_WAIT, /* out: DB_SUCCESS, DB_LOCK_WAIT,
DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */ DB_DEADLOCK, or DB_QUE_THR_SUSPENDED */
ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set, ulint flags, /* in: if BTR_NO_LOCKING_FLAG bit is set,
does nothing; does nothing */
if LOCK_TABLE_EXP|LOCK_TABLE_TRANSACTIONAL
bits are set,
creates an explicit table lock */
dict_table_t* table, /* in: database table in dictionary cache */ dict_table_t* table, /* in: database table in dictionary cache */
ulint mode, /* in: lock mode */ ulint mode, /* in: lock mode */
que_thr_t* thr) /* in: query thread */ que_thr_t* thr) /* in: query thread */
...@@ -3615,8 +3592,7 @@ lock_table( ...@@ -3615,8 +3592,7 @@ lock_table(
return(DB_SUCCESS); return(DB_SUCCESS);
} }
ut_a(flags == 0 || flags == LOCK_TABLE_EXP || ut_a(flags == 0);
flags == LOCK_TABLE_TRANSACTIONAL);
trx = thr_get_trx(thr); trx = thr_get_trx(thr);
...@@ -3729,9 +3705,7 @@ lock_table_dequeue( ...@@ -3729,9 +3705,7 @@ lock_table_dequeue(
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex)); ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
ut_a(lock_get_type(in_lock) == LOCK_TABLE || ut_a(lock_get_type(in_lock) == LOCK_TABLE);
lock_get_type(in_lock) == LOCK_TABLE_EXP ||
lock_get_type(in_lock) == LOCK_TABLE_TRANSACTIONAL);
lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock); lock = UT_LIST_GET_NEXT(un_member.tab_lock.locks, in_lock);
...@@ -3835,12 +3809,6 @@ lock_release_off_kernel( ...@@ -3835,12 +3809,6 @@ lock_release_off_kernel(
} }
lock_table_dequeue(lock); lock_table_dequeue(lock);
if (lock_get_type(lock) == LOCK_TABLE_EXP ||
lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL) {
ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X);
}
} }
if (count == LOCK_RELEASE_KERNEL_INTERVAL) { if (count == LOCK_RELEASE_KERNEL_INTERVAL) {
...@@ -3860,74 +3828,6 @@ lock_release_off_kernel( ...@@ -3860,74 +3828,6 @@ lock_release_off_kernel(
mem_heap_empty(trx->lock_heap); mem_heap_empty(trx->lock_heap);
ut_a(trx->auto_inc_lock == NULL); ut_a(trx->auto_inc_lock == NULL);
ut_a(trx->n_lock_table_exp == 0);
ut_a(trx->n_lock_table_transactional == 0);
}
/*************************************************************************
Releases table locks explicitly requested with LOCK TABLES (indicated by
lock type LOCK_TABLE_EXP), and releases possible other transactions waiting
because of these locks. */
void
lock_release_tables_off_kernel(
/*===========================*/
trx_t* trx) /* in: transaction */
{
dict_table_t* table;
ulint count;
lock_t* lock;
#ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */
lock = UT_LIST_GET_LAST(trx->trx_locks);
count = 0;
while (lock != NULL) {
count++;
if (lock_get_type(lock) == LOCK_TABLE_EXP) {
ut_a(lock_get_mode(lock) == LOCK_S
|| lock_get_mode(lock) == LOCK_X);
if (trx->insert_undo || trx->update_undo) {
/* The trx may have modified the table.
We block the use of the MySQL query
cache for all currently active
transactions. */
table = lock->un_member.tab_lock.table;
table->query_cache_inv_trx_id =
trx_sys->max_trx_id;
}
lock_table_dequeue(lock);
lock = UT_LIST_GET_LAST(trx->trx_locks);
continue;
}
if (count == LOCK_RELEASE_KERNEL_INTERVAL) {
/* Release the kernel mutex for a while, so that we
do not monopolize it */
lock_mutex_exit_kernel();
lock_mutex_enter_kernel();
count = 0;
}
lock = UT_LIST_GET_PREV(trx_locks, lock);
}
ut_a(trx->n_lock_table_exp == 0);
ut_a(trx->n_lock_table_transactional == 0);
} }
/************************************************************************* /*************************************************************************
...@@ -4040,15 +3940,7 @@ lock_table_print( ...@@ -4040,15 +3940,7 @@ lock_table_print(
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
ut_ad(mutex_own(&kernel_mutex)); ut_ad(mutex_own(&kernel_mutex));
#endif /* UNIV_SYNC_DEBUG */ #endif /* UNIV_SYNC_DEBUG */
ut_a(lock_get_type(lock) == LOCK_TABLE || ut_a(lock_get_type(lock) == LOCK_TABLE);
lock_get_type(lock) == LOCK_TABLE_EXP ||
lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL);
if (lock_get_type(lock) == LOCK_TABLE_EXP) {
fputs("EXPLICIT ", file);
} else if (lock_get_type(lock) == LOCK_TABLE_TRANSACTIONAL) {
fputs("TRANSACTIONAL ", file);
}
fputs("TABLE LOCK table ", file); fputs("TABLE LOCK table ", file);
ut_print_name(file, lock->trx, lock->un_member.tab_lock.table->name); ut_print_name(file, lock->trx, lock->un_member.tab_lock.table->name);
......
...@@ -970,25 +970,6 @@ row_lock_table_autoinc_for_mysql( ...@@ -970,25 +970,6 @@ row_lock_table_autoinc_for_mysql(
return((int) err); return((int) err);
} }
/*************************************************************************
Unlocks all table locks explicitly requested by trx (with LOCK TABLES,
lock type LOCK_TABLE_EXP). */
void
row_unlock_tables_for_mysql(
/*========================*/
trx_t* trx) /* in: transaction */
{
if (!trx->n_lock_table_exp) {
return;
}
mutex_enter(&kernel_mutex);
lock_release_tables_off_kernel(trx);
mutex_exit(&kernel_mutex);
}
/************************************************************************* /*************************************************************************
Sets a table lock on the table mentioned in prebuilt. */ Sets a table lock on the table mentioned in prebuilt. */
...@@ -1000,9 +981,10 @@ row_lock_table_for_mysql( ...@@ -1000,9 +981,10 @@ row_lock_table_for_mysql(
table handle */ table handle */
dict_table_t* table, /* in: table to lock, or NULL dict_table_t* table, /* in: table to lock, or NULL
if prebuilt->table should be if prebuilt->table should be
locked or a locked as
prebuilt->select_lock_type */ prebuilt->select_lock_type */
ulint mode) /* in: lock mode of table */ ulint mode) /* in: lock mode of table
(ignored if table==NULL) */
{ {
trx_t* trx = prebuilt->trx; trx_t* trx = prebuilt->trx;
que_thr_t* thr; que_thr_t* thr;
...@@ -1038,14 +1020,8 @@ row_lock_table_for_mysql( ...@@ -1038,14 +1020,8 @@ row_lock_table_for_mysql(
if (table) { if (table) {
err = lock_table(0, table, mode, thr); err = lock_table(0, table, mode, thr);
} else { } else {
if (mode == LOCK_TABLE_TRANSACTIONAL) { err = lock_table(0, prebuilt->table,
err = lock_table(LOCK_TABLE_TRANSACTIONAL, prebuilt->select_lock_type, thr);
prebuilt->table,
prebuilt->select_lock_type, thr);
} else {
err = lock_table(LOCK_TABLE_EXP, prebuilt->table,
prebuilt->select_lock_type, thr);
}
} }
trx->error_state = err; trx->error_state = err;
......
...@@ -158,8 +158,6 @@ trx_create( ...@@ -158,8 +158,6 @@ trx_create(
trx->n_tickets_to_enter_innodb = 0; trx->n_tickets_to_enter_innodb = 0;
trx->auto_inc_lock = NULL; trx->auto_inc_lock = NULL;
trx->n_lock_table_exp = 0;
trx->n_lock_table_transactional = 0;
trx->read_view_heap = mem_heap_create(256); trx->read_view_heap = mem_heap_create(256);
trx->read_view = NULL; trx->read_view = NULL;
...@@ -309,8 +307,6 @@ trx_free( ...@@ -309,8 +307,6 @@ trx_free(
ut_a(!trx->has_search_latch); ut_a(!trx->has_search_latch);
ut_a(!trx->auto_inc_lock); ut_a(!trx->auto_inc_lock);
ut_a(!trx->n_lock_table_exp);
ut_a(!trx->n_lock_table_transactional);
ut_a(trx->dict_operation_lock_mode == 0); ut_a(trx->dict_operation_lock_mode == 0);
...@@ -1711,12 +1707,6 @@ trx_print( ...@@ -1711,12 +1707,6 @@ trx_print(
(ulong) trx->mysql_n_tables_locked); (ulong) trx->mysql_n_tables_locked);
} }
if (trx->n_lock_table_transactional > 0 || trx->n_lock_table_exp > 0) {
fprintf(f, "mysql explicit table locks %lu, transactional table locks %lu\n",
(ulong) trx->n_lock_table_exp,
(ulong) trx->n_lock_table_transactional);
}
newline = TRUE; newline = TRUE;
switch (trx->que_state) { switch (trx->que_state) {
......
...@@ -5719,7 +5719,7 @@ ha_innobase::external_lock( ...@@ -5719,7 +5719,7 @@ ha_innobase::external_lock(
ulint error; ulint error;
error = row_lock_table_for_mysql(prebuilt, error = row_lock_table_for_mysql(prebuilt,
NULL, LOCK_TABLE_EXP); NULL, 0);
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
error = convert_error_code_to_mysql( error = convert_error_code_to_mysql(
...@@ -5739,9 +5739,6 @@ ha_innobase::external_lock( ...@@ -5739,9 +5739,6 @@ ha_innobase::external_lock(
trx->n_mysql_tables_in_use--; trx->n_mysql_tables_in_use--;
prebuilt->mysql_has_locked = FALSE; prebuilt->mysql_has_locked = FALSE;
auto_inc_counter_for_this_stat = 0; auto_inc_counter_for_this_stat = 0;
if (trx->n_lock_table_exp) {
row_unlock_tables_for_mysql(trx);
}
/* If the MySQL lock count drops to zero we know that the current SQL /* If the MySQL lock count drops to zero we know that the current SQL
statement has ended */ statement has ended */
...@@ -5783,7 +5780,7 @@ user issued query LOCK TABLES..WHERE ENGINE = InnoDB. */ ...@@ -5783,7 +5780,7 @@ user issued query LOCK TABLES..WHERE ENGINE = InnoDB. */
int int
ha_innobase::transactional_table_lock( ha_innobase::transactional_table_lock(
/*==================================*/ /*==================================*/
/* out: 0 */ /* out: error code */
THD* thd, /* in: handle to the user thread */ THD* thd, /* in: handle to the user thread */
int lock_type) /* in: lock type */ int lock_type) /* in: lock type */
{ {
...@@ -5847,8 +5844,7 @@ ha_innobase::transactional_table_lock( ...@@ -5847,8 +5844,7 @@ ha_innobase::transactional_table_lock(
if (thd->in_lock_tables && thd->variables.innodb_table_locks) { if (thd->in_lock_tables && thd->variables.innodb_table_locks) {
ulint error = DB_SUCCESS; ulint error = DB_SUCCESS;
error = row_lock_table_for_mysql(prebuilt,NULL, error = row_lock_table_for_mysql(prebuilt, NULL, 0);
LOCK_TABLE_TRANSACTIONAL);
if (error != DB_SUCCESS) { if (error != DB_SUCCESS) {
error = convert_error_code_to_mysql(error, user_thd); error = convert_error_code_to_mysql(error, user_thd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment