SET TRANSACTION
Syntax
1119
13.3.5.3. Table-Locking Restrictions and Conditions
You can safely use
KILL
to terminate a session that is waiting for a table lock. See
Section 13.7.6.3,
“
KILL
Syntax”
.
You should not lock any tables that you are using with
INSERT DELAYED
. An
INSERT DELAYED
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
and
UNLOCK TABLES
cannot be used within stored programs.
Normally, you do not need to lock tables, because all single
UPDATE
statements are atomic; no other
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
MyISAM
tables, it is much faster to lock the tables
you are going to use. Locking
MyISAM
tables speeds up inserting, updating, or deleting on them
because MySQL does not flush the key cache for the locked tables until
UNLOCK TABLES
is called.
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
LOCK TABLES
if you
want to ensure that no other session modifies the tables between a
SELECT
and an
UPDATE
. The
example shown here requires
LOCK TABLES
to execute safely:
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 TABLES
, it is possible that another session might insert a new row in the
trans
table
between execution of the
SELECT
and
UPDATE
statements.
You can avoid using
LOCK TABLES
in many cases by using relative updates (
UPDATE customer
SET value=value+new_value
) or the
LAST_INSERT_ID()
[961]
function. See
Section 1.8.5.3,
“Transactions and Atomic Operations”
.
You can also avoid locking tables in some cases by using the user-level advisory lock functions
GET_LOCK()
[965]
and
RELEASE_LOCK()
[967]
. These locks are saved in a hash table in the server
and implemented with
pthread_mutex_lock()
and
pthread_mutex_unlock()
for high speed.
See
Section 12.14, “Miscellaneous Functions”
.
See
Section 8.7.1, “Internal Locking Methods”
, for more information on locking policy.
13.3.6.
SET TRANSACTION
Syntax
SET [GLOBAL | SESSION] TRANSACTION ISOLATION LEVEL
{
REPEATABLE READ
| READ COMMITTED
| READ UNCOMMITTED
| SERIALIZABLE
}
This statement sets the transaction isolation level, used for operations on
InnoDB
tables.
Scope of the Isolation Level
You can set the isolation level globally, for the current session, or for the next transaction:
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...