Jump to content

Need help with table locking INNODB


UMfan

Recommended Posts

I'm a newbie, and having help.  Nobody has been able to help me with this in the mysql forum.  :-\

I have two tables: "fast" and "new data"  Both have about 7 million rows.  Both are InnoDB.

I am running the query below in order to find the data that is in "new data" that is not in "Fast".  I want to store these results in a third table called "Fall outs".

My query (please note the subquery in the WHERE statement.  This query works fine as a SELECT query, I only have problems when I add the "INSERT INTO" line):

INSERT INTO `fall outs`
SELECT (I have about 120 data fields I'm selecting here)
FROM `new DATA` LEFT JOIN `fast` ON `new DATA`.`FB_ID` = `fast`.`FB_ID`
WHERE
`new DATA`.`BAT_CREAT_DTM` <= (SELECT MAX(`fast`.`BAT_CREAT_DTM`)FROM `fast`) AND `fast`.`fb_id` IS NULL;



When I run this query I get an error that I've exceeded my number of locks.  I did some research and found that I should modify my query so that it reads:

SET @@AUTOCOMMIT=0;
LOCK TABLES `fall outs` WRITE, `new data` READ;
INSERT INTO `fall outs`
SELECT (insert my select statement here)
WHERE (insert my where statement here);
UNLOCK TABLES;

If I do this, I get an error that the table "fast" was not locked.  So how do I modify the above so that I can lock "fall outs" as the WRITE table and lock both "fast" and "new data" as the READ tables?

I'm also open to an easier way of doing this if anyone has suggestions.

I'd really appreciate the help.  I'm stuck on a project at work until I can overcome this.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.