0

以下查询:

DELETE FROM attachmentdata
WHERE attachmentid IN
  ( SELECT attachmentid
    FROM attachments
    WHERE pageid IN
      ( SELECT contentid FROM content_delete )
  );

如果内部嵌套的 SELECT 查询返回一个小列表(可能是几百个),则可以完美地工作。

但现在我试图在将返回 10000 - 15000 行的东西上运行它,这需要很长时间。我运行了查询,45 分钟后没有任何反应。

是否可以修改查询,以便内部 SELECT 返回的每 100 个结果都转到外部 DELETE 查询,然后转到下一个 100 个结果?

4

1 回答 1

1

为了让它更快,摆脱IN...

(甲骨文)...

DELETE  ad
FROM attachmentdata AS ad 
INNER JOIN attachments AS att ON ad.attachmentid = att.attachmentid
INNER JOIN content_delete AS cd ON cd.contentid = att.pageid

(mysql) ...

DELETE  ad.*
FROM attachmentdata AS ad 
INNER JOIN attachments AS att ON ad.attachmentid = att.attachmentid
INNER JOIN content_delete AS cd ON cd.contentid = att.pageid
于 2013-05-22T15:03:50.473 回答