sql:根据另一个人的说法,从 table 中删除行需要太长时间
sql: deleting lines from a table, according to another, takes too long
我有一些大 tables,我想用下面的命令删除一行
当我尝试这个时,它花费的时间太长了:
DELETE global, lines
FROM lines force index(cardIndex)
INNER JOIN global force index(cardIndexes)
ON global.card = lines.card
WHERE lines.product NOT IN (SELECT code FROM article);
我的 table 全局有 900.000 行,行 tables 有 6.000.000 行,文章有 40.000
知道我可以做些什么来改进命令吗?
NOT IN
是一个非常昂贵的操作。您可以使用以下替代方法消除它:
OUTER JOIN
改为article
table,而
- 仅包含
article.code
为空的那些行。
null 表示 article
table 中没有相应的记录 - 换句话说:"not in".
DELETE global, lines
FROM lines force index(cardIndex)
INNER JOIN global force index(cardIndexes) ON global.card = lines.card
LEFT JOIN article ON lines.product = article.code
WHERE article.code IS NULL;
我有一些大 tables,我想用下面的命令删除一行
当我尝试这个时,它花费的时间太长了:
DELETE global, lines
FROM lines force index(cardIndex)
INNER JOIN global force index(cardIndexes)
ON global.card = lines.card
WHERE lines.product NOT IN (SELECT code FROM article);
我的 table 全局有 900.000 行,行 tables 有 6.000.000 行,文章有 40.000 知道我可以做些什么来改进命令吗?
NOT IN
是一个非常昂贵的操作。您可以使用以下替代方法消除它:
OUTER JOIN
改为article
table,而- 仅包含
article.code
为空的那些行。
null 表示 article
table 中没有相应的记录 - 换句话说:"not in".
DELETE global, lines
FROM lines force index(cardIndex)
INNER JOIN global force index(cardIndexes) ON global.card = lines.card
LEFT JOIN article ON lines.product = article.code
WHERE article.code IS NULL;