Chinaunix首页 | 论坛 | 博客

-

  • 博客访问: 4135283
  • 博文数量: 172
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1923
  • 用 户 组: 普通用户
  • 注册时间: 2018-12-20 14:57
文章分类
文章存档

2021年(19)

2020年(81)

2019年(68)

2018年(4)

我的朋友

分类: 敏捷开发

2020-05-18 10:07:38


一、     查询要求


Q5语句查询得到通过某个地区零件供货商而获得的收入(收入按sum(l_extendedprice * (1 -l_discount))计算)统计信息。可用于决定在给定的区域是否需要建立一个当地分配中心。

Q5语句的特点是:带有分组、排序、聚集操作并存的多表连接查询操作。

 


二、     Oracle执行


Oracle编写的查询SQL语句如下:

select /*+ parallel(n) */

         n_name,

         sum(l_extendedprice * (1 - l_discount)) as revenue

from

         customer,

         orders,

         lineitem,

         supplier,

         nation,

         region

where

         c_custkey = o_custkey

         and l_orderkey = o_orderkey

         and l_suppkey = s_suppkey

         and c_nationkey = s_nationkey

         and s_nationkey = n_nationkey

         and n_regionkey = r_regionkey

         and r_name = 'ASIA'

         and o_orderdate >= date '1995-01-01'

         and o_orderdate < date '1995-01-01' + interval '1' year

group by

         n_name

order by

         revenue desc;

其中/*+ parallel(n) */ Oracle的并行查询语法,n是并行数。

脚本执行时间,单位:秒

并行数 1 2 4 8 12
Oracle 672 368 301 224 225


三、     SPL优化


优化原理和Q3类似,只是涉及的外键表更多一些。

 

SPL脚本如下:


A
1 =1
2 =now()
3 >date=date("1995-01-01")
4 >name="ASIA"
5 =elapse@y(date,1)
6 =file(path+"region.ctx").create().cursor().select(R_NAME==name).fetch()
7 =file(path+"nation.ctx").create().cursor().switch@i(N_REGIONKEY,   A6:R_REGIONKEY).fetch().keys@i(N_NATIONKEY)
8 =file(path+"supplier.ctx").create().cursor@m(S_SUPPKEY,S_NATIONKEY;S_NATIONKEY:A7;A1).fetch().keys@i(S_SUPPKEY)
9 =file(path+"customer.ctx").create().cursor@m(C_CUSTKEY,C_NATIONKEY;C_NATIONKEY:A7;A1).fetch().keys@i(C_CUSTKEY)
10 =file(path+"orders.ctx").create().cursor@m(O_ORDERKEY,O_CUSTKEY;O_ORDERDATE>=date   && O_ORDERDATE < A5,O_CUSTKEY:A9;A1)
11 =file(path+"lineitem.ctx").create().news(A10,L_ORDERKEY,L_SUPPKEY,L_EXTENDEDPRICE,L_DISCOUNT,O_CUSTKEY;L_SUPPKEY:A8)
12 =A11.select(O_CUSTKEY.C_NATIONKEY==L_SUPPKEY.S_NATIONKEY)
13 =A12.groups@u(L_SUPPKEY.S_NATIONKEY.N_NAME;sum(L_EXTENDEDPRICE   * (1 - L_DISCOUNT)):revenue)
14 =A13.sort(revenue   :-1)
15 =now()
16 =interval@s(A2,A15)

这里大量使用了前面题目中说过的游标建立时过滤和将关联字段转换成外键表指针的技巧。

Q3不大相同的是,最后用于分组的字段不是已经有序的L_ORDERKEY,所以不能再使用groups@o

 

脚本执行时间,单位:秒

并行数 1 2 4 8 12
Oracle 672 368 301 224 225
SPL组表 353 177 91 49 34

 


阅读(1535) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~