Bug #30319 LOCK TABLES doesn't follow aliases
Submitted: 8 Aug 2007 18:00 Modified: 8 Aug 2007 21:29
Reporter: Cory Watson Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0.41 OS:MacOS (10.4.10)
Assigned to: CPU Architecture:Any
Tags: alias lock

[8 Aug 2007 18:00] Cory Watson
Description:
If you request a LOCK TABLES and then attempt a query using an alias that does not match the name used when the lock was requested, MySQL believes it was not locked.

Done on current GA release on OS X w/InnoDB tables

How to repeat:
LOCK TABLES accounts;
SELECT * FROM accounts acc;
(fails)
SELECT * FROM accounts;
(succeeds)
UNLOCK TABLES;

LOCK TABLES accounts acc;
SELECT * FROM accounts acc;
(succeeds)
SELECT * FROM accounts;
(fails)
UNLOCK TABLES;

Suggested fix:
Resolve the actual table that the alias points to.  This makes it very difficult to pre acquire locks for tables that are accessed via an ORM that uses aliasing.
[8 Aug 2007 21:29] Sveta Smirnova
Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://dev.mysql.com/doc/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Please read about how LOCK TABLES works with aliases at http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html