我正在 MySQL 中运行报告。其中一个查询涉及将大量行插入到临时表中。当我尝试运行它时,我得到了这个错误:
Error code 1206: The number of locks exceeds the lock table size.
有问题的查询是:
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;
我读过更改配置文件以增加缓冲池大小会有所帮助,但这无济于事。有什么方法可以解决这个问题,作为临时解决方法还是永久修复?
编辑:更改了部分查询。不应该影响它,但我做了一个 find-replace all 并没有意识到它搞砸了。不影响提问。
编辑 2:将 typedesc 添加到 t1。我在查询中更改了它,但这里没有。
最佳答案
可以通过为 MySQL 变量 innodb_buffer_pool_size
设置更高的值来解决此问题。 innodb_buffer_pool_size
的默认值为 8,388,608
。
要更改 innodb_buffer_pool_size
的设置值,请参阅下面的设置。
my.cnf
。对于 Linux 服务器,这将主要位于 /etc/my.cnf
innodb_buffer_pool_size=64MB
行添加到此文件中要重新启动 MySQL 服务器,您可以使用以下 2 个选项中的任何一个:
引用 The total number of locks exceeds the lock table size
https://stackoverflow.com/questions/6901108/