一、 查询要求

Q8语句是查询在过去的两年中一个给定零件类型在某国某地区市场份额的变化情况。

Q8语句的特点是:带有分组、排序、聚集、子查询操作并存的查询操作。子查询的父层查询不存在其他查询对象,是格式相对简单的子查询,但子查询自身是多表连接的查询。

二、 Oracle执行

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

select  /+ parallel(n) /

         o_year,

         sum(case

                   when nation = 'CHINA' then volume

                   else 0

         end)/ sum(volume) as mkt_share

from

         (

                   select

                            extract(year from o_orderdate) as o_year,

                            l_extendedprice * (1 - l_discount) as volume,

                            n2.n_name as nation

                   from

                            part,

                            supplier,

                            lineitem,

                            orders,

                            customer,

                            nation n1,

                            nation n2,

                            region

                   where

                            p_partkey = l_partkey

                            and s_suppkey = l_suppkey

                            and l_orderkey = o_orderkey

                            and o_custkey = c_custkey

                            and c_nationkey = n1.n_nationkey

                            and n1.n_regionkey = r_regionkey

                            and r_name = 'ASIA'

                            and s_nationkey = n2.n_nationkey

                            and o_orderdate between date '1995-01-01' and date '1996-12-31'

                            and p_type = 'STANDARD POLISHED BRASS'

         ) all_nations

group by

         o_year

order by

         o_year;

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

脚本执行时间,单位:秒

1png

三、 SPL优化

这里的orders与lineitem主子表关联优化原理与Q3中类似。

SPL脚本如下:

2png

nation表作为外键表被用了两次,这里在A8,A9基于读出来的A7分别生成相应的外键表。

脚本执行时间,单位:秒

3png


raqsoft
114 声望10 粉丝