Oracle 5.0 Reference Manual page 1136

Table of Contents

Advertisement

If the
statement must wait due to locks held by other sessions on any of the tables, it
LOCK TABLES
blocks until all locks can be acquired.
A session that requires locks must acquire all the locks that it needs in a single
statement. While the locks thus obtained are held, the session can access only the locked tables.
For example, in the following sequence of statements, an error occurs for the attempt to access
because it was not locked in the
mysql>
LOCK TABLES t1 READ;
mysql>
SELECT COUNT(*) FROM t1;
+----------+
| COUNT(*) |
+----------+
|
3 |
+----------+
mysql>
SELECT COUNT(*) FROM t2;
ERROR 1100 (HY000): Table 't2' was not locked with LOCK TABLES
Tables in the
INFORMATION_SCHEMA
locked explicitly even while a session holds table locks obtained with
You cannot refer to a locked table multiple times in a single query using the same name. Use aliases
instead, and obtain a separate lock for the table and each alias:
mysql>
LOCK TABLE t WRITE, t AS t1 READ;
mysql>
INSERT INTO t SELECT * FROM t;
ERROR 1100: Table 't' was not locked with LOCK TABLES
mysql>
INSERT INTO t SELECT * FROM t AS t1;
The error occurs for the first
table. The second
INSERT
If your statements refer to a table by means of an alias, you must lock the table using that same alias. It
does not work to lock the table without specifying the alias:
mysql>
LOCK TABLE t READ;
mysql>
SELECT * FROM t AS myalias;
ERROR 1100: Table 'myalias' was not locked with LOCK TABLES
Conversely, if you lock a table using an alias, you must refer to it in your statements using that alias:
mysql>
LOCK TABLE t AS myalias READ;
mysql>
SELECT * FROM t;
ERROR 1100: Table 't' was not locked with LOCK TABLES
mysql>
SELECT * FROM t AS myalias;
locks normally have higher priority than
WRITE
as soon as possible. This means that if one session obtains a
requests a
lock, subsequent
WRITE
lock has obtained the lock and released it. A request for a
permits subsequent
READ
LOW_PRIORITY WRITE
are sure that eventually there will be a time when no sessions have a
transactional mode (autocommit = 0), a waiting
lock and causes subsequent
acquires locks as follows:
LOCK TABLES
1. Sort all tables to be locked in an internally defined order. From the user standpoint, this order is
undefined.
2. If a table is to be locked with a read and a write lock, put the write lock request before the read lock
request.
3. Lock one table at a time until the session gets all locks.
and
LOCK TABLES
UNLOCK TABLES
LOCK TABLES
database are an exception. They can be accessed without being
because there are two references to the same name for a locked
INSERT
succeeds because the references to the table use different names.
lock requests wait until the session that requested the
READ
lock requests by other sessions to be satisfied first if they occur while the
request is waiting. You should use
lock requests to wait.
READ
1116
Syntax
statement:
LOCK
locks to ensure that updates are processed
READ
lock and then another session
READ
LOW_PRIORITY WRITE
LOW_PRIORITY WRITE
READ
LOW_PRIORITY WRITE
LOCK TABLES
TABLES.
lock, by contrast,
locks only if you
lock. For
tables in
InnoDB
lock acts like a regular
t2
WRITE
WRITE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents