I'm running a report in MySQL. One of the queries involves inserting a large amount of rows into a temp table. When I try to run it, I get this error:
Error code 1206: The number of locks exceeds the lock table size.
The queries in question are:
create temporary table SkusBought( customerNum int(11), sku int(11), typedesc char(25), key `customerNum` (customerNum) )ENGINE=InnoDB DEFAULT CHARSET=latin1; insert into skusBought select t1.* from (select customer, sku, typedesc from transactiondatatransit where (cat = 150 or cat = 151) AND daysfrom07jan1 > 731 group by customer, sku union select customer, sku, typedesc from transactiondatadelaware where (cat = 150 or cat = 151) AND daysfrom07jan1 > 731 group by customer, sku union select customer, sku, typedesc from transactiondataprestige where (cat = 150 or cat = 151) AND daysfrom07jan1 > 731 group by customer, sku) t1 join (select customernum from topThreetransit group by customernum) t2 on t1.customer = t2.customernum;
I've read that changing the configuration file to increase the buffer pool size will help, but that does nothing. What would be the way to fix this, either as a temporary workaround or a permanent fix?
EDIT: changed part of the query. Shouldn't affect it, but I did a find-replace all and didn't realize it screwed that up. Doesn't affect the question.
EDIT 2: Added typedesc to t1. I changed it in the query but not here.
This issue can be resolved by setting the higher values for the MySQL variable innodb_buffer_pool_size . The default value for innodb_buffer_pool_size will be 8,388,608 .
A locked table remains locked until you either commit your transaction or roll it back, either entirely or to a savepoint before you locked the table. A lock never prevents other users from querying the table. A query never places a lock on a table.
Table locking causes problems when a session is waiting because the disk is full and free space needs to become available before the session can proceed. In this case, all sessions that want to access the problem table are also put in a waiting state until more disk space is made available.
Table-Level Locking. MySQL uses table-level locking for MyISAM , MEMORY , and MERGE tables, permitting only one session to update those tables at a time. This locking level makes these storage engines more suitable for read-only, read-mostly, or single-user applications.
This issue can be resolved by setting the higher values for the MySQL variable innodb_buffer_pool_size
. The default value for innodb_buffer_pool_size
will be 8,388,608
.
To change the settings value for innodb_buffer_pool_size
please see the below set.
my.cnf
from the server. For Linux servers this will be mostly at /etc/my.cnf
innodb_buffer_pool_size=64MB
to this fileTo restart the MySQL server, you can use anyone of the below 2 options:
Reference The total number of locks exceeds the lock table size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With