Bug #7241 Invalid response when DELETE .. USING and LOCK TABLES used.
Submitted: 13 Dec 2004 17:51 Modified: 24 May 2005 14:22
Reporter: Scott Lane Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: MyISAM storage engine Severity:S2 (Serious)
Version:4.1.2 OS:Windows (Windows XP)
Assigned to: Antony Curtis CPU Architecture:Any

[13 Dec 2004 17:51] Scott Lane
Description:
When performing a DELETE .. USING command on tables where some of them (not the ones being deleted from) are locked with READ, an error is returned that the READ table cannot be updated.

Of course, it wasn't being updated to begin with so the message is invalid. However, it is forcing me to put a WRITE lock on the table which I don't think I should have to do given the operation I am performing (see below).

How to repeat:
Create two tables whose primary keys are the same.
CREATE table1 recid VARCHAR(64) NOT NULL PRIMARY KEY . . .
CREATE table2 recid VARCHAR(64) NOT NULL PRIMARY KEY . . .

Populate data where some of the recid values overlap in both tables.

Now:
LOCK TABLES table1 WRITE, table2 READ;
DELETE FROM table1 USING table1,table2 WHERE table1.recid=table2.recid;
alternatively you could try
DELETE table1 FROM table1,table2 WHERE table1.recid=table2.recid;

In either case you get back:
ERROR 1099 (HY000): Table 'table2 was locked with a READ lock and can't be updat
ed

The syntax above however doesn't UPDATE table2 at all!

Suggested fix:
My guess is that the parser of the command is to blame. I would make sure that lock and query reconcilliation only occur on the tables that will truly be modified by the query.
[13 Dec 2004 18:31] MySQL Verification Team
Verified against 4.1.8 Bk Source Linux.
[10 Mar 2005 22:43] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/22917
[27 Apr 2005 9:04] Antony Curtis
Refreshing patch
[23 May 2005 0:06] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/25167
[24 May 2005 10:44] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/25206
[24 May 2005 14:22] Antony Curtis
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Pushed to 4.1.13 repo