13.3.5.3. Table-Locking Restrictions and Conditions
You can safely use
"KILL
Syntax".
You should not lock any tables that you are using with
in this case results in an error because the insert must be handled by a separate thread, not by the
session which holds the lock.
LOCK TABLES
Normally, you do not need to lock tables, because all single
session can interfere with any other currently executing SQL statement. However, there are a few
cases when locking tables may provide an advantage:
• If you are going to run many operations on a set of
you are going to use. Locking
because MySQL does not flush the key cache for the locked tables until
Normally, the key cache is flushed after each SQL statement.
The downside to locking the tables is that no session can update a READ-locked table (including the
one holding the lock) and no session can access a WRITE-locked table other than the one holding
the lock.
• If you are using tables for a nontransactional storage engine, you must use
want to ensure that no other session modifies the tables between a
example shown here requires
LOCK TABLES trans READ, customer WRITE;
SELECT SUM(value) FROM trans WHERE customer_id=some_id;
UPDATE customer
SET
total_value=sum_from_previous_statement
WHERE customer_id=some_id;
UNLOCK TABLES;
Without
LOCK
between execution of the
You can avoid using
value=value+new_value) or the
SET
"Transactions and Atomic
You can also avoid locking tables in some cases by using the user-level advisory lock functions
GET_LOCK()
and implemented with
See
Section 12.14, "Miscellaneous
See
Section 8.7.1, "Internal Locking
13.3.6.
SET TRANSACTION
SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
{
REPEATABLE READ
| READ COMMITTED
| READ UNCOMMITTED
| SERIALIZABLE
}
This statement sets the transaction isolation level, used for operations on
Scope of the Isolation Level
You can set the isolation level globally, for the current session, or for the next transaction:
SET TRANSACTION
to terminate a session that is waiting for a table lock. See
KILL
and
UNLOCK TABLES
MyISAM
LOCK TABLES
TABLES, it is possible that another session might insert a new row in the
and
SELECT
in many cases by using relative updates
LOCK TABLES
Operations".
[965]
and
RELEASE_LOCK()
pthread_mutex_lock()
Functions".
Methods", for more information on locking policy.
Syntax
Syntax
INSERT
cannot be used within stored programs.
UPDATE
MyISAM
tables speeds up inserting, updating, or deleting on them
to execute safely:
statements.
UPDATE
LAST_INSERT_ID()
[967]. These locks are saved in a hash table in the server
and
pthread_mutex_unlock()
1119
Section 13.7.6.3,
DELAYED. An
INSERT DELAYED
statements are atomic; no other
tables, it is much faster to lock the tables
UNLOCK TABLES
LOCK TABLES
and an UPDATE. The
SELECT
(UPDATE customer
[961]
function. See
Section 1.8.5.3,
tables.
InnoDB
is called.
if you
table
trans
for high speed.
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers