我在P
- 表中有250个miljon行,在J
- 表中有100 000行。我正在尝试删除P
- 表中与J
- 表缺乏关系的所有行。
每一行缺少关系(约100 000有关系)将从P
- 表中删除。
DELETE P
FROM P
LEFT JOIN J ON J.P_id = P.id
WHERE J.id IS NULL;
ERROR 2006 (HY000): MySQL server has gone away
SET innodb_lock_wait_timeout=63000;
SET wait_timeout=63000;
/* ... followed by the query stated above ... */
如何达到预期效果?
所以我猜这个查询仍在运行..
+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+
| 540 | root | localhost | scraper | Query | 63298 | Sending data | DELETE Domain_Page FROM Domain_Page LEFT JOIN StructuredData_Joppli ON StructuredData_Joppli.Domain_ |
| 556 | root | localhost | scraper | Query | 0 | NULL | show processlist |
+-----+------+-----------+---------+---------+-------+--------------+------------------------------------------------------------------------------------------------------+
答案 0 :(得分:0)
更改此
DELETE P
FROM P
到
DELETE
FROM P
答案 1 :(得分:0)
如果没有索引关系,请尝试删除较小的部分。
DELETE P
FROM P
LEFT JOIN J ON J.P_id = P.id
WHERE J.id IS NULL LIMIT 10000;
修改
使用子查询怎么样?请先试用一下测试表。
DELETE p FROM p
JOIN
(SELECT J.P_Id
FROM J LEFT JOIN P ON J.P_Id=P.Id
WHERE j.Id IS NULL LIMIT 1000
) P2 ON p.Id=P2.P_Id
答案 2 :(得分:0)
delete
from P left join J ON J.P_id = P.id
where J.id IS NULL
如果列不是NULL但只是空白,则需要执行以下操作:
delete
frome P
left join J ON J.P_id = P.id
where J.id=''