Select count(*) 与 Select * 在 Teradata 中执行
Select count(*) vs Select * execution in Teradata
我有一个 WHERE NOT EXISTS 查询,基本上如下所示:
select count(*)
from TableA a
where not exists (Select 1 from TableB b where a.ID = b.ID);
表A大约有8562212条记录,和表B一样
当我 运行 上面的查询时 运行 无限期地。当我替换
select count(*)
只有
select *
查询 运行s 在 2 秒内和 returns 0 行(如预期)。此外,当我 运行 不存在的反向(不存在的 TableB....TableA)时,使用计数(*)它在 2 秒内 运行s 和 returns 0 行。
唯一的问题是上面的查询。我要补充一点,我对很多数据库表都有 运行 类似的查询,但从未 运行 进入这个问题。为什么会发生这种情况的任何想法?我很难过。谢谢
您尝试过左连接吗?
select count(*)
from TableA a
LEft join TableB b on a.ID = b.ID
where b.ID is null
我有一个 WHERE NOT EXISTS 查询,基本上如下所示:
select count(*)
from TableA a
where not exists (Select 1 from TableB b where a.ID = b.ID);
表A大约有8562212条记录,和表B一样
当我 运行 上面的查询时 运行 无限期地。当我替换
select count(*)
只有
select *
查询 运行s 在 2 秒内和 returns 0 行(如预期)。此外,当我 运行 不存在的反向(不存在的 TableB....TableA)时,使用计数(*)它在 2 秒内 运行s 和 returns 0 行。
唯一的问题是上面的查询。我要补充一点,我对很多数据库表都有 运行 类似的查询,但从未 运行 进入这个问题。为什么会发生这种情况的任何想法?我很难过。谢谢
您尝试过左连接吗?
select count(*)
from TableA a
LEft join TableB b on a.ID = b.ID
where b.ID is null