楼主: lastwinner

cube真好用,但是效率不高

[复制链接]
论坛徽章:
4
最佳人气徽章
日期:2013-03-04 10:02:12优秀写手
日期:2014-01-10 06:00:142014年新春福章
日期:2014-02-18 16:44:08马上有对象
日期:2014-02-18 16:44:08
11#
发表于 2012-9-20 18:52 | 只看该作者
这是啥执行计划工具呀?

使用道具 举报

回复
论坛徽章:
13
奥运会纪念徽章:帆船
日期:2012-09-03 17:33:58路虎
日期:2013-09-26 09:22:18阿斯顿马丁
日期:2013-09-09 11:06:02日产
日期:2013-09-02 16:42:52劳斯莱斯
日期:2013-08-26 10:10:17凯迪拉克
日期:2013-08-26 10:08:51雪佛兰
日期:2013-08-13 18:33:23林肯
日期:2013-08-13 18:33:00ITPUB社区12周年站庆徽章
日期:2013-08-07 16:23:202010广州亚运会纪念徽章:射箭
日期:2013-06-26 17:43:12
12#
发表于 2012-9-20 18:56 | 只看该作者
maoweiting 发表于 2012-9-20 18:52
这是啥执行计划工具呀?

我已经搞明白了,这个就是大名鼎鼎的toad

使用道具 举报

回复
论坛徽章:
4
最佳人气徽章
日期:2013-03-04 10:02:12优秀写手
日期:2014-01-10 06:00:142014年新春福章
日期:2014-02-18 16:44:08马上有对象
日期:2014-02-18 16:44:08
13#
发表于 2012-9-20 18:57 | 只看该作者
akagea 发表于 2012-9-20 18:56
我已经搞明白了,这个就是大名鼎鼎的toad

我是一只菜鸟 我没用过

使用道具 举报

回复
论坛徽章:
13
奥运会纪念徽章:帆船
日期:2012-09-03 17:33:58路虎
日期:2013-09-26 09:22:18阿斯顿马丁
日期:2013-09-09 11:06:02日产
日期:2013-09-02 16:42:52劳斯莱斯
日期:2013-08-26 10:10:17凯迪拉克
日期:2013-08-26 10:08:51雪佛兰
日期:2013-08-13 18:33:23林肯
日期:2013-08-13 18:33:00ITPUB社区12周年站庆徽章
日期:2013-08-07 16:23:202010广州亚运会纪念徽章:射箭
日期:2013-06-26 17:43:12
14#
发表于 2012-9-20 19:09 | 只看该作者
maoweiting 发表于 2012-9-20 18:57
我是一只菜鸟 我没用过

我刚刚下载来使用,功能很强大

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
15#
 楼主| 发表于 2012-9-21 00:34 | 只看该作者
akagea 发表于 2012-9-20 18:56
我已经搞明白了,这个就是大名鼎鼎的toad

没错,执行计划的展现还有多样性,你点右键试试看就知道了

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
16#
 楼主| 发表于 2012-9-21 00:35 | 只看该作者
anlinew 发表于 2012-9-20 14:08
要看执行的具体信息来确认哪个效率更高

真要常用的话,在OLAP里用cube结合物化视图快速刷新

在这里,物化视图是出来中间结果的吧?
你看我的查询里是带distinct的,所以是没法快速刷新的,而且也没法先做出个中间结果来

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
17#
发表于 2021-9-1 09:26 | 只看该作者
我的老帖子
http://www.itpub.net/forum.php?m ... &highlight=cube
最新在postgresql上的比较
也是没有优化cube生成
pop=# select count(*) from ren group by c1;
  count
----------
  9996826
10003174
(2 行记录)


pop=# \timing
启用计时功能.
pop=# create table test_cube1 as select c1,c2,c3,c4,c5,c6,count(*)cnt from ren group by cube(c1,c2,c3,c4,c5,c6);
SELECT 13616133
时间:514886.073 ms (08:34.886)
pop=# create table test_cube12 as select c1,c2,count(*)cnt from ren group by cube(c1,c2);
SELECT 12
时间:10644.760 ms (00:10.645)
pop=# create table test_cube12_man as select c1,c2,count(*)cnt from ren group by c1,c2
pop-# union all select c1,null,count(*)from ren group by c1
pop-# union all select null,c2,count(*)from ren group by c2
pop-# union all select null,null,count(*)from ren;
SELECT 12
时间:6798.374 ms (00:06.798)

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
18#
发表于 2021-9-1 09:36 | 只看该作者
用楼主的distinct也是类似的时间
pop=# drop table test_cube12,test_cube12_man;
DROP TABLE
时间:152.355 ms

pop=# create table test_cube12_man as select c1,c2,count(distinct c3)cnt from ren group by c1,c2
pop-# union all select c1,null,count(distinct c3)from ren group by c1
pop-# union all select null,c2,count(distinct c3)from ren group by c2
pop-# union all select null,null,count(distinct c3)from ren;
SELECT 12
时间:29847.093 ms (00:29.847)
pop=# create table test_cube12 as select c1,c2,count(distinct c3)cnt from ren group by cube(c1,c2);
SELECT 12
时间:50386.733 ms (00:50.387)

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
19#
发表于 2021-9-1 09:49 | 只看该作者
本帖最后由 〇〇 于 2021-9-1 09:58 编辑

没有distinct的查询可以这么处理
pop=# create table test_cube12_man2 as
pop-# with t as(select c1,c2,count(*)cnt from ren group by c1,c2)
pop-# select c1,c2,cnt from t
pop-# union all select c1,null,sum(cnt)from t group by c1
pop-# union all select null,c2,sum(cnt)from t group by c2
pop-# union all select null,null,sum(cnt)from t;
SELECT 12
时间:2307.743 ms (00:02.308)

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
20#
发表于 2021-9-1 10:04 | 只看该作者
有distinct的列,先不聚合,
pop=# create table test_cube12_man3 as
pop-# with t as(select c1,c2,c3 from ren group by c1,c2,c3)
pop-# select c1,c2,count(distinct c3)cnt from t group by c1,c2
pop-# union all select c1,null,count(distinct c3)from t group by c1
pop-# union all select null,c2,count(distinct c3)from t group by c2
pop-# union all select null,null,count(distinct c3)from t;
SELECT 12
时间:2469.335 ms (00:02.469)
pop=# select * from test_cube12_man3;
c1 | c2 | cnt
----+----+-----
  1 |  1 |   5
  1 |  2 |   5
  1 |  3 |   5
  2 |  1 |   5
  2 |  2 |   5
  2 |  3 |   5
  1 |    |   5
  2 |    |   5
    |  1 |   5
    |  2 |   5
    |  3 |   5
    |    |   5
(12 行记录)


时间:1.251 ms

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表