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
https://forums.phpfreaks.com/topic/34585-need-help-with-table-locking-innodb/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.