您好,有一种方法可以用更少的时间来应用它,查询现在花费了15分钟太长的时间,并且仍在执行
从[1]的电话中删除(
从[2]中选择电话
在'2019-03-04'和'2019-03-22'之间的call_date
联盟
从[3]中选择电话
) 开始
答案 0 :(得分:2)
我建议:
DELETE one FROM [1] one
WHERE EXISTS (SELECT 1
FROM [3] three
WHERE three.phone = one.phone
) OR
EXISTS (SELECT 1
FROM [2] two
WHERE one.phone = two.phone AND
two.call_date BETWEEN '2019-03-04' AND '2019-03-22'
);
然后建议在[2](phone, call_date)
和[3](phone)
上进行索引。
答案 1 :(得分:1)
我会尝试将EXISTS
与OR
一起使用,而不是UNION
:
DELETE o
FROM [1] o
WHERE EXISTS (SELECT 1
FROM [2] t
WHERE o.phone = t.phone AND
t.call_date >= '2019-03-04' AND t.call_date <= '2019-03-22'
) OR
EXISTS (SELECT 1 FROM [3] tr WHERE tr.phone = o.phone);