【发布时间】:2011-10-17 14:00:59
【问题描述】:
我正在 MySQL 中运行报告。其中一个查询涉及将大量行插入到临时表中。当我尝试运行它时,我得到了这个错误:
错误码1206:锁数超过锁表大小。
有问题的查询是:
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。我在查询中更改了它,但这里没有。
【问题讨论】:
-
你为什么要在子选择中分组?
-
我觉得这很难理解。如果 t2.customernum = t1.customer 从 topThreetransit 中仅选择 customernum 是没有意义的。那么,SkusBought.typedesc 肯定是与第一列相同的客户代码吗?
-
t2 是 t1 中客户的子集。加入是为了摆脱 t1 中不在 t2 中的客户。 typedesc 的代码实际上是不正确的。再次,在实际的 sql 脚本中更改它,但不是在这里。 Typedesc 是另一列 transactiondata(全部三个)。我会修改它,使它正确且更有意义。
-
我为一个常见问题写了一个古怪的插图here