Teradata 优化器错误地估计行号,然后通过带联合的视图访问 table

Teradata optimizer wrongly estimates row number then accessing to table through view with union

假设我有三个 table:t1(它有大约 10 亿行,事实 table)和 t2(空 table , 0 行)。和t0(维度table),他们都正确地收集了统计数据。另外还有视图 v0:

REPLACE VIEW v0
AS SELECT * from t1
   union
   SELECT * from t2;

让我们看看这三个查询:

1) Select * from t1 inner t0 join on t1.id = t0.id; -- Optimizer correctly estimates 1 bln rows

2) Select * from t2 inner t0 join on t1.id = t0.id; -- Optimizer correctly estimates 0 row

3) Select * from v0 inner t0 join on v0.id = t0.id;  -- Optimizer locks t1 and t2 for read, the correctly estimated, that it will get 1 bln rows from t1, but for no clear reasons estimated same number 1 bln from table t2.

这是怎么回事?是错误还是功能?

PS。原始查询在 35 分钟内没有完成,这里显示的内容非常大。刚离开后 t1 - 在 15 分钟内成功完成。

第二个Select不是同一个数字,是第2个Select之后spool中的总行数,也就是10亿加 0.

而且您查询 运行 很慢,因为您使用了默认为 DISTINCTUNION,运行 这在十亿行上确实很昂贵。

最好改为 UNION ALL