多列 count(distinct)改写优化

问题现象
对多列 count(distinct) 改写优化。 GBase 8a MPP Cluster FAQ FAQ
文档版本(2021-04-02) 南大通用数据技术股份有限公司
78
处理方法
对多列 count(distinct) ,当前执行计划是:
先在各节点对参与 count(distinct) 的列进行 group by 去重,结果集再汇集到一
个节点进行 count(distinct) 运算;
count(distinct) 列很多时,参与 group by 运算的列也很多,去重效果不理
想,导致大量数据要拉到一个节点进行 count(distinct) 运算,拉表和汇总节点计
算耗时非常长;
优化的方法是改写 sql ,各列分别计算 count(distinct) ,提高去重效果,然后对
结果集进行拼接。
示例
优化前
select count(distinct col1), count(distinct col2) from tb;
优化后
select * from
(select count(distinct col1) from tb) a
join
(select count(distinct col2) from tb) b;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值