0

在同一内部查询多次运行的情况下,有什么方法可以自定义以下 SQL 以提高性能?

DELETE FROM interactionrel 
WHERE  ( from_interact_id IN(SELECT interaction_id 
                             FROM   interaction 
                             WHERE  instance_pk = ?) ) 
        OR ( to_interact_id IN(SELECT interaction_id 
                               FROM   interaction 
                               WHERE  instance_pk = ?) ) 
4

2 回答 2

2

你可以试试这个——尽管你需要对优化器运行它:

DELETE FROM interactionrel a
WHERE EXISTS (SELECT * 
              FROM interaction b
              WHERE b.instance_pl = ?
                    AND (b.interaction_id = a.from_interact_id
                         OR b.interaction_id = a.to_interact_id))
于 2013-03-15T21:14:51.110 回答
1
DELETE il 
FROM   interactionrel il, 
       interaction 
WHERE  ( interaction.interaction_id = il.from_interact_id 
          OR interaction.interaction_id = il.to_interact_id ) 
       AND interaction.instance_pk = ? 
于 2013-03-15T11:18:33.390 回答