表table1包含1500000行和包含80個字段,我想基於Field 1和場2和ID字段,以便移除重複是唯一的,所以我使用的最大選項。MYSQL插入查詢失敗與鎖的總數目超過鎖表大小
選項1:插入選項
insert into table2_unique
select * from table1 a
where a.id = (select max(b.id) from table1 b
where a.field1 = b.field1
and a.field2 = b.field2);
但查詢失敗,因爲下面的錯誤的。
Error Code: 1206. The total number of locks exceeds the lock table size
EXPLAIN語句:
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 INSERT table2 NULL ALL NULL NULL NULL NULL NULL NULL NULL
1 PRIMARY a NULL ALL NULL NULL NULL NULL 1387764 100 Using where
2 DEPENDENT SUBQUERY b NULL ref field1x,field2x field1x 39 a.field1 537 10 Using where
選項2 DELETE語句:
DELETE n1 FROM table1 n1, table1 n2 WHERE n1.id > n2.id AND n1.field1 = n2.field1 and n1.field2 and n2.field2
當我執行再發生死鎖。
我不能增加緩衝池大小,請讓我知道我該寫不同的方式查詢。
哪裏是你的delete語句? –
DELETE語句還發布了 – user3738664
80個字段?聽起來像你缺乏一個正確定義的主鍵不是你唯一的問題。 – symcbean