【问题标题】:Join operation between Table and ViewTable和View之间的join操作
【发布时间】:2017-03-30 17:18:55
【问题描述】:

我在使用视图连接表格时遇到了问题

select count(*) from table A inner join table B
on A.scen_id=B.scen_id
and A.value=10 --(till here records returned are 0)
inner join View C --this view contains millions of records
on B.scen_id=C.scen_id

由于两个表 A 和 B 的连接返回 0 条记录,但整个查询是 takinh ~ 2 小时,只是因为 View 并给了我 0 条记录。

有没有办法解决这个问题,所以我可以得到 0 条性能良好的记录?

【问题讨论】:

  • 有连接列的统计信息吗?你能解释一下吗?
  • 当然还有A.value 专栏?
  • 当我在 table 上运行命令 help stat 时,我们正在收集 scen_id 而不是 A.value 上的统计数据
  • 如果没有A.value 上的统计信息,优化器将估计该条件将返回 10% 的行,这显然是完全错误的。使用统计信息,连接顺序可能会完全改变。
  • 我尝试删除 A.value 过滤器,但它又花了很长时间。我能看到的唯一选择是将视图转换为一个表,我可以在其中定义加入列的统计信息 (C.scen_id )

标签: teradata


【解决方案1】:

您能否尝试关注,发送解释并告知它是否有效:

select count(*) 
from table A 
inner join table B
on A.scen_id=B.scen_id
inner join View C 
on B.scen_id=C.scen_id
where  A.value=10 

还要确保 A.Value 的统计数据已刷新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-18
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2012-03-17
    • 2023-03-17
    相关资源
    最近更新 更多