赞
踩
tpch是TPC(Transaction Processing Performance Council)组织提供的工具包。用于进行OLAP测试,以评估商业分析中决策支持系统(DSS)的性能。它包含了一整套面向商业的ad-hoc查询和并发数据修改,强调测试的是数据库、平台和I/O性能,关注查询能力。
TPC-H是业界常用的一套基准,由TPC委员会制定发布,用于评测数据库的分析型查询能力。TPC-H查询包含8张数据表、22条复杂的SQL查询,大多数查询包含若干表Join、子查询和Group by聚合等。
在使用tpch工具之前,先了解一下并行查询(OLAP)。
并行查询(OLAP)举例(以阿里云的ploarDB为例)
PolarDB MySQL 8.0集群版推出并行查询(Parallel Query)框架。并行查询默认为关闭状态,当开启并行查询后,查询数据量到达一定阈值,就会自动启动并行查询框架,从而使查询耗时下降。
说明:可以通过设置loose_max_parallel_degree参数来开启并行查询,如何设置集群参数请参见设置集群参数。
loose_max_parallel_degree参数说明如下:
最小值为0(关闭并行查询)。
最大值为1024。
建议设置并行查询参数为16。
PolarDB MySQL 8.0集群版在存储层将数据分片到不同的线程上,多个线程并行计算,将结果流水线汇聚到总线程,最后由总线程做简单归并将结果返回给用户,提高查询效率。
并行查询利用多核CPU的并行处理能力,以8核32 GB独享规格的集群为例,并行查询示意图如下所示。
相关链接:
tpch下载地址(TPC-H需要完成注册后才可以下载):
http://tpc.org/tpc_documents_current_versions/download_programs
tpch工具github仓库地址:
https://github.com/electrum/tpch-dbgen
参考阿里云tpch工具使用:
https://help.aliyun.com/document_detail/146099.html?spm=a2c4g.11186623.6.773.4797364bCS7aO5
yum install unzip -y
unzip tpch-mysql.zip
cd tpch-mysql
cd dbgen
yum install gcc-c++
执行编译
make
./dbgen -s 12
准备工作到此结束,下面开始tpch工具的使用。
说明:统一选取相同同等规格的实例进行测试,写入12G数据量,测试3次,取最终平均值进行对标(单位:s)。
mysql -hrm-uf6cbh8aq31a8prtj.mysql.rds.aliyuncs.com -P3306 -umyroot -p****** --local-infile
注明:这里登录mysql,加了–local-infile参数,否则在后面从本地导入数据的时候有可能报:
ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
use tpcd;
建表
\. /root/tpch-mysql/dbgen/dss.ddl
创建索引、外键等
\. /root/tpch-mysql/dbgen/dss.ri
如果想看看外键和主键是否添加成功,有没有添加对,可以执行 SHOW CREATE TABLE 表名(觉得默认格式很碍眼可以试试看加上\G垂直打印)
load data local infile '/root/tpch-mysql/dbgen/part.tbl' into table part fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/region.tbl' into table region fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/nation.tbl' into table nation fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/customer.tbl' into table customer fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/supplier.tbl' into table supplier fields terminated by '|';
如图表示导入成功:
##再来看另外三张表,注意:这里不要执行。因为这三张表比较大,最好是使用脚本拆解执行。
load data local infile '/root/tpch-mysql/dbgen/orders.tbl' into table orders fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/partsupp.tbl' into table partsupp fields terminated by '|';
load data local infile '/root/tpch-mysql/dbgen/lineitem.tbl' into table lineitem fields terminated by '|';
八张表的关系如下:
其中Nation和Region数据量与SF无关;Nation是固定25,Region的5不是必然;LineItem的数据量是不严格的SF倍数。
[root@localhost dbgen]# cat orders.tbl | wc -l
18000000
[root@localhost dbgen]# cat partsupp.tbl | wc -l
9600000
[root@localhost dbgen]# cat lineitem.tbl | wc -l
71985077
编辑脚本
vi split_import_file.sh
修改(三处)见以下注释
#! /bin/bash #文件名不带.tbl !!!,即对应表名 #read -p "please input filename: " filename filename=orders # 修改处1:替换文件名orders、partsupp、lineitem、 #获取原文件总行数totalline totalline=$(cat $filename.tbl | wc -l) echo totalline=$totalline #要分割成的每个小文件的行数line line=1000000 a=`expr $totalline / $line` b=`expr $totalline % $line` #获取小文件个数filenum if (( $b==0 )) then filenum=$a else filenum=`expr $a + 1` fi echo filenum=$filenum #进行文件分割,分割后第一个小文件名后缀为i,i最小值为1 i=1 # 修改处2:38 修改为1 while(( i<=$filenum )) do #每个小文件要截取行数在原文件范围min,max p=`expr $i - 1` min=`expr $p \* $line + 1` max=`expr $i \* $line` sed -n "$min,$max"p ./$filename.tbl > ./$filename.tbl.$i #将小文件导入数据库,mysql登录信息及小文件路径根据实际修改 # 修改处3:mysql连接信息(加了--local-infile) #根据自己创建的数据库的用户名、密码、数据库实例的ip、端口号、已经tpc安装包的路径信息进行修改。 mysql -umyroot -p'******' -h10.185.147.201 -P32307 --local-infile -Dtpcd -e "load data local infile '/root/tpch-mysql/dbgen/$filename.tbl.$i' into table $filename fields terminated by '|';" i=`expr $i + 1` done
改完之后保存,退出# :wq
按以上修改编辑好三个脚本,在后台运行脚本(此过程,在拆解数据表,拆解的过程中,同时往数据库中导入数据,所以不需要再执行数据导入的操作)三个脚本同时开启:
nohup sh split_import_file_partsupp.sh>split_import_partsupp.log 2>&1 &
nohup sh split_import_file_orders.sh>split_import_orders.log 2>&1 &
nohup sh split_import_file_lineitem.sh>split_import_lineitem.log 2>&1 &
运行过程中,可以查看进程,看是否跑结束了,# ps -ef 进程号
ps -ef | grep split
vi tpch-benchmark-olap.sh
修改mysql连接信息
#!/bin/sh PATH=$PATH:/usr/local/bin export PATH #set -u #set -x #set -e . ~/.bash_profile > /dev/null 2>&1 exec 3>&1 4>&2 1>> tpch-benchmark-olap-`date +'%Y%m%d%H%M%S'`.log 2>&1 I=1 II=3 while [ $I -le $II ] do N=1 T=23 while [ $N -lt $T ] do if [ $N -lt 10 ] ; then NN='0'$N else NN=$N fi echo "query $NN starting" # /etc/init.d/mysql restart # 修改这里mysql连接信息 time mysql -h10.185.147.201 -P32307 -umyroot -p****** -Dtpcd < ./queries/tpch_${NN}.sql echo "query $NN ended!" N=`expr $N + 1` echo -e echo -e done I=`expr $I + 1` done
nohup sh tpch-benchmark-olap.sh >output.log 2>&1 &
在/tpch-mysql/dbgen/路径下,会自动生成日志文件tpch-benchmark-olap-20210528143245.log
查看一下日志:
cat tpch-benchmark-olap-20210528143245.log
日志输出如下:
query 01 starting
mysql: [Warning] Using a password on the command line interface can be insecure.
l_returnflag l_linestatus sum_qty sum_base_price sum_disc_price sum_charge avg_qty avg_price avg_disc count_order
A F 453004927.00 679255118036.63 645289010691.4043 671106139941.958450 25.499290 38234.734227 0.050007 17765394
real 3m2.575s
user 0m0.024s
sys 0m0.008s
query 01 ended!
...
静静等待22条语句执行完毕。
使用TPC-H进行性能测试,需要有很多工作配合才能获得较高性能,如建立索引,表数据的合理分布(使用表空间和聚簇技术)等。
这里从查询优化技术的角度,对TPC-H的22条查询语句和主流数据库执行每条语句对应的查询执行计划进行分析,目的在于了解各个主流数据库的查询优化技术,以TPC-H实例进一步掌握查询优化技术,对比主流数据库的实现情况对查询优化技术融会贯通。
select l_returnflag, //返回标志 l_linestatus, sum(l_quantity) as sum_qty, //总的数量 sum(l_extendedprice) as sum_base_price, //聚集函数操作 sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, avg(l_quantity) as avg_qty, avg(l_extendedprice) as avg_price, avg(l_discount) as avg_disc, count(*) as count_order //每个分组所包含的行数 from lineitem where l_shipdate <= date'1998-12-01' - interval '90' day //时间段是随机生成的 group by //分组操作 l_returnflag, l_linestatus order by //排序操作 l_returnflag, l_linestatus;
select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment /*查询供应者的帐户余额、名字、国家、零件的号码、生产者、供应者的地址、电话号码、备注信息 */ from part, supplier, partsupp, nation, region //五表连接 where p_partkey = ps_partkey and s_suppkey = ps_suppkey and p_size = [SIZE] //指定大小,在区间[1, 50]内随机选择 and p_type like '%[TYPE]' //指定类型,在TPC-H标准指定的范围内随机选择 and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = '[REGION]' //指定地区,在TPC-H标准指定的范围内随机选择 and ps_supplycost = ( //子查询 select min(ps_supplycost) //聚集函数 from partsupp, supplier, nation, region //与父查询的表有重叠 where p_partkey = ps_partkey and s_suppkey = ps_suppkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = '[REGION]' ) order by //排序 s_acctbal desc, n_name, s_name, p_partkey;
select l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, //潜在的收入,聚集操作 o_orderdate, o_shippriority from customer, orders, lineitem //三表连接 where c_mktsegment = '[SEGMENT]' //在TPC-H标准指定的范围内随机选择 and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < date '[DATE]' //指定日期段,在在[1995-03-01, 1995-03-31]中随机选择 and l_shipdate > date '[DATE]' group by //分组操作 l_orderkey, //订单标识 o_orderdate, //订单日期 o_shippriority //运输优先级 order by //排序操作 revenue desc, //降序排序,把潜在最大收入列在前面 o_orderdate;
select o_orderpriority, //订单优先级 count(*) as order_count //订单优先级计数 from orders //单表查询 where o_orderdate >= date '[DATE]' and o_orderdate < date '[DATE]' + interval '3' month //指定订单的时间段--某三个月,DATE是在1993年1月和1997年10月之间随机选择的一个月的第一天 and exists ( //子查询 select * from lineitem where l_orderkey = o_orderkey and l_commitdate < l_receiptdate ) group by //按订单优先级分组 o_orderpriority order by //按订单优先级排序 o_orderpriority;
select 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 = '[REGION]' //指定地区,在TPC-H标准指定的范围内随机选择 and o_orderdate >= date '[DATE]' //DATE是从1993年到1997年中随机选择的一年的1月1日 and o_orderdate < date '[DATE]' + interval '1' year group by //按名字分组 n_name order by //按收入降序排序,注意分组和排序子句不同 revenue desc;
select
sum(l_extendedprice*l_discount) as revenue //潜在的收入增加量
from
lineitem //单表查询
where
l_shipdate >= date '[DATE]' //DATE是从[1993, 1997]中随机选择的一年的1月1日
and l_shipdate < date '[DATE]' + interval '1' year //一年内
and l_discount between [DISCOUNT] - 0.01 and [DISCOUNT] + 0.01 //between
and l_quantity < [QUANTITY]; // QUANTITY在区间[24, 25]中随机选择
select supp_nation, //供货商国家 cust_nation, //顾客国家 l_year, sum(volume) as revenue //年度、年度的货运收入 from ( //子查询 select n1.n_name as supp_nation, n2.n_name as cust_nation, extract(year from l_shipdate) as l_year, l_extendedprice * (1 - l_discount) as volume from supplier,lineitem,orders,customer,nation n1,nation n2 //六表连接 where s_suppkey = l_suppkey and o_orderkey = l_orderkey and c_custkey = o_custkey and s_nationkey = n1.n_nationkey and c_nationkey = n2.n_nationkey and ( // NATION2和NATION1的值不同,表示查询的是跨国的货运情况 (n1.n_name = '[NATION1]' and n2.n_name = '[NATION2]') or (n1.n_name = '[NATION2]' and n2.n_name = '[NATION1]') ) and l_shipdate between date '1995-01-01' and date '1996-12-31' ) as shipping group by supp_nation, cust_nation, l_year order by supp_nation, cust_nation, l_year;
select o_year, //年份 sum(case when nation = '[NATION]'//指定国家,在TPC-H标准指定的范围内随机选择 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 = '[REGION]' //指定地区,在TPC-H标准指定的范围内随机选择 and s_nationkey = n2.n_nationkey and o_orderdate between date '1995-01-01' and date '1996-12-31' //只查95、96年的情况 and p_type = '[TYPE]' //指定零件类型,在TPC-H标准指定的范围内随机选择 ) as all_nations group by //按年分组 o_year order by //按年排序 o_year;
select nation, o_year, sum(amount) as sum_profit //每个国家每一年所有被定购的零件在一年中的总利润 from (select n_name as nation, //国家 extract(year from o_orderdate) as o_year, //取出年份 l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount //利润 from part,supplier,lineitem,partsupp,orders,nation //六表连接 where s_suppkey = l_suppkey and ps_suppkey = l_suppkey and ps_partkey = l_partkey and p_partkey = l_partkey and o_orderkey = l_orderkey and s_nationkey = n_nationkey and p_name like '%[COLOR]%' //LIKE操作,查询优化器可能进行优化 ) as profit group by //按国家和年份分组 nation, o_year order by //按国家和年份排序,年份大者靠前 nation, o_year desc;
select c_custkey, c_name, //客户信息 sum(l_extendedprice * (1 - l_discount)) as revenue, //收入损失 c_acctbal, n_name, c_address, c_phone, c_comment //国家、地址、电话、意见信息等 from customer, orders, lineitem, nation where c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate >= date '[DATE]' // DATE是位于1993年一月到1994年十二月中任一月的一号 and o_orderdate < date '[DATE]' + interval '3' month //3个月内 and l_returnflag = 'R' //货物被回退 and c_nationkey = n_nationkey group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment order by revenue desc;
select ps_partkey, sum(ps_supplycost * ps_availqty) as value //聚集操作,商品的总价值 from partsupp, supplier, nation where ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = '[NATION]' group by ps_partkey having //带有HAVING子句的分组操作 sum(ps_supplycost * ps_availqty) > ( //HAVING子句中包括有子查询 select sum(ps_supplycost * ps_availqty) * [FRACTION] //子查询中存在聚集操作;FRACTION为0.0001/SF1 from partsupp, supplier, nation //与父查询的表连接一致 where //与父查询的WHEWR条件一致 ps_suppkey = s_suppkey and s_nationkey = n_nationkey and n_name = '[NATION]' //指定国家 ) order by //按商品的价值降序排序 value desc;
select l_shipmode, sum(case //聚集操作 when o_orderpriority ='1-URGENT' //OR运算,二者满足其一即可,选出URGENT或HIGH的 or o_orderpriority ='2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority <> '1-URGENT' //AND运算,二者都不满足,非URGENT非HIGH的 and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count from orders,lineitem where o_orderkey = l_orderkey and l_shipmode in ('[SHIPMODE1]', '[SHIPMODE2]') /* 指定货运模式的类型,在TPC-H标准指定的范围内随机选择,SHIPMODE2必须有别于SHIPMODE1 */ and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '[DATE]' //从1993年到1997年中任一年的一月一号 and l_receiptdate < date '[DATE]' + interval '1' year //1年之内 group by //分组操作 l_shipmode order by //排序操作 l_shipmode;
select c_count, count(*) as custdist //聚集操作,统计每个组的个数 from //子查询 (select c_custkey, count(o_orderkey) from customer left outer join orders on //子查询中包括左外连接操作 c_custkey = o_custkey and o_comment not like ‘%[WORD1]%[WORD2]%’ //LIKE操作 //WORD1 为以下四个可能值中任意一个:special、pending、unusual、express //WORD2 为以下四个可能值中任意一个:packages、requests、accounts、deposits group by //子查询中的分组操作 c_custkey )as c_orders (c_custkey, c_count) group by //分组操作 c_count order by //排序操作 custdist desc, //从大到小降序排序 c_count desc;
select
100.00 * sum(case
when p_type like 'PROMO%' //促销零件
then l_extendedprice*(1-l_discount) //某一特定时间的收入
else 0
end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
from
lineitem, part
where
l_partkey = p_partkey
and l_shipdate >= date '[DATE]' // DATE是从1993年到1997年中任一年的任一月的一号
and l_shipdate < date '[DATE]' + interval '1' month;
create view revenue[STREAM_ID](supplier_no, total_revenue) as //创建复杂视图(带有分组操作) select l_suppkey, sum(l_extendedprice * (1 - l_discount)) //获取供货商为公司带来的总利润 from lineitem where l_shipdate >= date '[DATE]' //DATE 是从1993年一月到1997年十月中任一月的一号 and l_shipdate < date '[DATE]' + interval '3' month //3个月内 group by //分组键与查询对象之一相同 l_suppkey; //查询语句 select s_suppkey, s_name, s_address, s_phone, total_revenue from supplier,revenue[STREAM_ID] //普通表与复杂视图进行连接操作 where s_suppkey = supplier_no and total_revenue = (//聚集子查询 select max(total_revenue) from revenue[STREAM_ID] //聚集子查询从视图获得数据 ) order by s_suppkey; //删除视图 drop view revenue[STREAM_ID];
select p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt //聚集、去重操作 from partsupp, part where p_partkey = ps_partkey and p_brand <> '[BRAND]' // BRAND=Brand#MN ,M和N是两个字母,代表两个数值,相互独立,取值在1到5之间 and p_type not like '[TYPE]%' //消费者不感兴趣的类型和尺寸 and p_size in ([SIZE1], [SIZE2], [SIZE3], [SIZE4], [SIZE5], [SIZE6], [SIZE7], [SIZE8]) //TYPEX是在1到50之间任意选择的一组八个不同的值 and ps_suppkey not in ( //NOT IN子查询,消费者排除某些供货商 select s_suppkey from supplier where s_comment like '%Customer%Complaints%' ) group by //分组操作 p_brand, p_type, p_size order by //排序操作 supplier_cnt desc, //按数量降序排列,按品牌、种类、尺寸升序排列 p_brand, p_type, p_size;
select sum(l_extendedprice) / 7.0 as avg_yearly //聚集操作 from lineitem, part where p_partkey = l_partkey and p_brand = '[BRAND]' /*指定品牌。 BRAND=’Brand#MN’ ,M和N是两个字母,代表两个数值,相互独立,取值在1到5之间 */ and p_container = '[CONTAINER]' //指定包装类型。在TPC-H标准指定的范围内随机选择 and l_quantity < ( //聚集子查询 select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey );
select c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice, //基本信息 sum(l_quantity) //订货总数 from customer, orders, lineitem where o_orderkey in ( //带有分组操作的IN子查询 select l_orderkey from lineitem group by l_orderkey having sum(l_quantity) > [QUANTITY] // QUANTITY是位于312到315之间的任意值 ) and c_custkey = o_custkey and o_orderkey = l_orderkey group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice order by o_totalprice desc, o_orderdate;
select sum(l_extendedprice * (1 - l_discount) ) as revenue from lineitem, part where ( p_partkey = l_partkey and p_brand = ‘[BRAND1]’ /*特定品牌。BRAND1、BRAND2、BRAND3=‘Brand#MN’,M和N是两个字母,代表两个数值,相互独立,取值在1到5之间 */ and p_container in ( ‘SM CASE’, ‘SM BOX’, ‘SM PACK’, ‘SM PKG’) //包装范围 and l_quantity >= [QUANTITY1] and l_quantity <= [QUANTITY1] + 10 /* QUANTITY1 是1到10之间的任意取值 */ and p_size between 1 and 5 //尺寸范围 and l_shipmode in (‘AIR’, ‘AIR REG’) //运输模式,如下带有阴影的粗体表示的条件是相同的,存在条件化简的可能 and l_shipinstruct = ‘DELIVER IN PERSON’ ) or ( p_partkey = l_partkey and p_brand = ‘[BRAND2]’ and p_container in (‘MED BAG’, ‘MED BOX’, ‘MED PKG’, ‘MED PACK’) and l_quantity >= [QUANTITY2] and l_quantity <= [QUANTITY2] + 10 /* QUANTITY2 是10到20之间的任意取值 */ and p_size between 1 and 10 and l_shipmode in (‘AIR’, ‘AIR REG’) and l_shipinstruct = ‘DELIVER IN PERSON’ ) or ( p_partkey = l_partkey and p_brand = ‘[BRAND3]’ and p_container in ( ‘LG CASE’, ‘LG BOX’, ‘LG PACK’, ‘LG PKG’) and l_quantity >= [QUANTITY3] and l_quantity <= [QUANTITY3] + 10 /* QUANTITY3 是20到30之间的任意取值 */ and p_size between 1 and 15 and l_shipmode in (‘AIR’, ‘AIR REG’) and l_shipinstruct = ‘DELIVER IN PERSON’ );
select s_name, s_address from supplier, nation where s_suppkey in ( //第一层的IN子查询 select ps_suppkey from partsupp where ps_partkey in ( //第二层嵌套的IN子查询 select p_partkey from part where p_name like '[COLOR]%' //COLOR为产生P_NAME的值的列表中的任意值 ) and ps_availqty > (//第二层嵌套的子查询 select 0.5 * sum(l_quantity) //聚集子查询 from lineitem where l_partkey = ps_partkey and l_suppkey = ps_suppkey and l_shipdate >= date('[DATE]’) //DATE为在1993年至1997年的任一年的一月一号 and l_shipdate < date('[DATE]’) + interval ‘1’ year //1年内 ) ) and s_nationkey = n_nationkey and n_name = '[NATION]' //TPC-H标准定义的任意值 order by s_name;
select s_name, count(*) as numwait from supplier, lineitem l1, orders, nation where s_suppkey = l1.l_suppkey and o_orderkey = l1.l_orderkey and o_orderstatus = 'F' and l1.l_receiptdate > l1.l_commitdate and exists ( //EXISTS子查询 select * from lineitem l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey ) and not exists ( //NOT EXISTS子查询 select * from lineitem l3 where l3.l_orderkey = l1.l_orderkey and l3.l_suppkey <> l1.l_suppkey and l3.l_receiptdate > l3.l_commitdate ) and s_nationkey = n_nationkey and n_name = '[NATION]' //TPC-H标准定义的任意值 group by s_name order by numwait desc, s_name;
select cntrycode, count(*) as numcust, sum(c_acctbal) as totacctbal from ( //第一层子查询 select substring(c_phone from 1 for 2) as cntrycode, c_acctbal from customer where // I1…I7是在TPC-H中定义国家代码的可能值中不重复的任意值 substring(c_phone from 1 for 2) in ('[I1]','[I2]’,'[I3]','[I4]','[I5]','[I6]','[I7]') and c_acctbal > (//第二层聚集子查询 select avg(c_acctbal) from customer where c_acctbal > 0.00 and substr (c_phone from 1 for 2) in ('[I1]','[I2]','[I3]','[I4]','[I5]','[I6]','[I7]') ) and not exists (//第二层NOT EXISTS子查询 select * from orders where o_custkey = c_custkey ) ) as custsale group by cntrycode order by cntrycode;
以各大云厂商的MySQL为例,测试结果如下。根据该表格分析对比得出各个云厂商MySQL的优劣。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。