【问题标题】:Teradata optimizer wrongly estimates row number then accessing to table through view with unionTeradata 优化器错误估计行数,然后通过联合视图访问表
【发布时间】:2017-07-04 17:57:46
【问题描述】:

假设我有三个表:t1(它有大约 10 亿行,事实表)和t2(空表,0 行)。和t0(维度表),它们都已正确收集统计信息。另外还有观点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.

这里发生了什么?是错误还是功能?

附言。原始查询(此处显示的内容很大)并未在 35 分钟内完成。离开后刚刚t1 - 15 分钟后成功完成。

  • TD 发布:15.10.03.07

  • TD 版本:15.10.03.09

【问题讨论】:

  • 您知道 JOIN 语法完全错误
  • 优化器从不估计 0 行
  • @DuduMarkovitz 0 或 1 - 差别不大
  • (1) 对于优化器来说是 (2) 这表明你没有正确描述执行计划
  • 你是对的,但没关系)

标签: sql query-optimization union teradata sql-execution-plan


【解决方案1】:

2nd Select 的数字不一样,它是 spool 2nd Select 之后的总行数,即 10 亿加 0。

而您的查询运行缓慢,因为您使用了默认为 DISTINCTUNION,在十亿行上运行它真的很昂贵。

最好改用UNION ALL

【讨论】:

  • 你是对的,它估计了线轴的总大小,这将是相同的。感谢您提醒有关 distinct,
猜你喜欢
  • 1970-01-01
  • 2018-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-24
  • 2020-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多