当前位置:   article > 正文

DM8达梦数据库tpch测试步骤_tpch怎么执行

tpch怎么执行

此篇文档只介绍了如何在DM8上使用测试工具进行tpch测试的步骤,关于参数性能优化方面的内容不做介绍。

  1. 更多达梦数据库相关问题,请浏览云适配技术社区。
  2. 达梦云适配技术社区
  3. https://eco.dameng.com/

1.准备tpch测试工具benchmark

2.生成.tbl数据文件
利用degen工具模拟生成1G的数据

  1. cd /ceshi/tpch/linux/tpch_dbgen
  2.  
  3. ./dbgen -s 1

会在当前目录下生成数据源文件,用来之后dmfldr导入的元数据。

3.修改每个表的dmfldr控制文件
修改下面8个表对应的导入控制文件

vi customer.ctrl
vi lineitem.ctrl
vi nation.ctrl
vi orders.ctrl
vi part.ctrl
vi partsupp.ctrl
vi region.ctrl
vi supplier.ctrl
以下是customer表的示例修改

4创建表的结构
执行下面的sql语句用来创建表的结构

  1. drop table customer;        
  2. drop table lineitem;        
  3. drop table nation;        
  4. drop table orders;        
  5. drop table part;        
  6. drop table partsupp;        
  7. drop table region;        
  8. drop table supplier;        
  9.         
  10. create huge table CUSTOMER        
  11. (        
  12. C_CUSTKEY                 int not null,                
  13. C_NAME                    varchar(25) not null,    
  14. C_ADDRESS                 varchar(40) not null,     
  15. C_NATIONKEY               int not null,              
  16. C_PHONE                   char(15) not null,        
  17. C_ACCTBAL                 float not null,    
  18. C_MKTSEGMENT             char(10) not null,        
  19. C_COMMENT                 varchar(117) not null,    
  20. primary key (C_CUSTKEY)        
  21. );        
  22.         
  23. create huge table LINEITEM        
  24. (        
  25. L_ORDERKEY               int not null,       
  26. L_PARTKEY                int not null,     
  27. L_SUPPKEY                int not null,    
  28. L_LINENUMBER             int not null,    
  29. L_QUANTITY               float not null,    
  30. L_EXTENDEDPRICE          float not null,    
  31. L_DISCOUNT               float not null,    
  32. L_TAX                    float not null,    
  33. L_RETURNFLAG             char(1) not null,    
  34. L_LINESTATUS             char(1) not null,     
  35. L_SHIPDATE               date not null,    
  36. L_COMMITDATE             date not null,    
  37. L_RECEIPTDATE            date not null,    
  38. L_SHIPINSTRUCT           char(25) not null,    
  39. L_SHIPMODE               char(10) not null,     
  40. L_COMMENT                varchar(44) not null,    
  41. primary key(L_ORDERKEY , L_LINENUMBER)        
  42. );        
  43.         
  44. create huge table NATION        
  45. (        
  46. N_NATIONKEY              int not null,             
  47. N_NAME                   char(25) not null,        
  48. N_REGIONKEY              int not null,             
  49. N_COMMENT                varchar(152) not null,    
  50. primary key (N_NATIONKEY)        
  51. );        
  52.         
  53. create huge table ORDERS        
  54. (        
  55. O_ORDERKEY               int not null,     
  56. O_CUSTKEY                int not null,    
  57. O_ORDERSTATUS            char(1) not null,     
  58. O_TOTALPRICE             float not null,    
  59. O_ORDERDATE              date not null,    
  60. O_ORDERPRIORITY          char(15) not null,    
  61. O_CLERK                  char(15) not null,    
  62. O_SHIPPRIORITY           integer not null,    
  63. O_COMMENT                varchar(79) not null,    
  64. primary key(O_ORDERKEY)        
  65. );        
  66.         
  67. create huge table part        
  68. (        
  69. P_PARTKEY        int not null,
  70. P_NAME                    varchar(55) not null,    
  71. P_MFGR                    char(25) not null,    
  72. P_BRAND                   char(10) not null,    
  73. P_TYPE                    varchar(25) not null,    
  74. P_SIZE                    int not null,    
  75. P_CONTAINER               char(10) not null,    
  76. P_RETAILPRICE             float not null,    
  77. P_COMMENT                 varchar(23) not null,    
  78. primary key (P_PARTKEY)        
  79. );        
  80.         
  81. create huge table PARTSUPP        
  82. (        
  83. PS_PARTKEY                int not null,                    
  84. PS_SUPPKEY                int not null,                    
  85. PS_AVAILQTY               int not null,                    
  86. PS_SUPPLYCOST             float not null,    
  87. PS_COMMENT                varchar(199) not null,    
  88.  primary key (PS_PARTKEY , PS_SUPPKEY)        
  89. );        
  90.         
  91. create huge table REGION        
  92. (        
  93. R_REGIONKEY              int not null,               
  94. R_NAME                   char(25) not null,          
  95. R_COMMENT                varchar(152) not null,     
  96. primary key (R_REGIONKEY)        
  97. );        
  98.         
  99. create huge table SUPPLIER        
  100. (        
  101. S_SUPPKEY                 int not null,                   
  102. S_NAME                    char(25) not null,             
  103. S_ADDRESS                 varchar(40) not null,          
  104. S_NATIONKEY               int not null,                   
  105. S_PHONE                   char(15) not null,             
  106. S_ACCTBAL                 float not null,    
  107. S_COMMENT                 varchar(101) not null,        
  108. primary key (S_SUPPKEY)        
  109. );        


5.加载数据
使用dmfldr工具导入数据

  1. cd /home/dmdba/dmdbms/bin/
  2.  
  3. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/customer.ctrl\'
  4.  
  5. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/lineitem.ctrl\'
  6.  
  7. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/nation.ctrl\'
  8.  
  9. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/orders.ctrl\'
  10.  
  11. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/partsupp.ctrl\'
  12.  
  13. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/part.ctrl\'
  14.  
  15. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/region.ctrl\'
  16.  
  17. ./dmfldr userid=SYSDBA/SYSDBA:5236 control=\'/ceshi/tpch/linux/supplier.ctrl\'


6.更新统计信息
执行下面的sql信息更新统计信息

  1. --删除表上所有列的统计信息
  2. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'CUSTOMER');
  3. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'LINEITEM');
  4. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'NATION');
  5. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'ORDERS');
  6. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'PART');
  7. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'PARTSUPP');
  8. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'REGION');
  9. CALL SP_TAB_COL_STAT_DEINIT ('SYSDBA', 'SUPPLIER');
  10. --删除表的统计信息
  11. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'CUSTOMER');
  12. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'LINEITEM');
  13. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'NATION');
  14. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'ORDERS');
  15. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'PART');
  16. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'PARTSUPP');
  17. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'REGION');
  18. CALL SP_TAB_STAT_DEINIT ('SYSDBA', 'SUPPLIER');
  19. --更新统计信息
  20. SP_TAB_STAT_INIT('SYSDBA','REGION');
  21. SP_TAB_STAT_INIT('SYSDBA','NATION');
  22. SP_TAB_STAT_INIT('SYSDBA','PART');
  23. SP_TAB_STAT_INIT('SYSDBA','PARTSUPP');
  24. SP_TAB_STAT_INIT('SYSDBA','SUPPLIER');
  25. SP_TAB_STAT_INIT('SYSDBA','CUSTOMER');
  26. SP_TAB_STAT_INIT('SYSDBA','ORDERS');
  27. SP_TAB_STAT_INIT('SYSDBA','LINEITEM');
  28.  
  29. STAT 100 ON REGION(R_NAME) ;
  30. STAT 100 ON REGION(R_REGIONKEY) ;
  31. STAT 100 ON NATION(N_NAME) ;
  32. STAT 100 ON NATION(N_NATIONKEY) ;
  33. STAT 100 ON NATION(N_REGIONKEY) ;
  34. STAT 100 ON SUPPLIER(S_SUPPKEY) ;
  35. STAT 100 ON SUPPLIER(S_NATIONKEY) ;
  36. STAT 100 ON SUPPLIER(S_COMMENT) ;
  37.  
  38. STAT 100 ON PART(P_SIZE);
  39. STAT 100 ON PART(P_BRAND);
  40. STAT 100 ON PART(P_TYPE);
  41. STAT 100 ON PART(P_NAME);
  42. STAT 100 ON PART(P_PARTKEY);
  43. STAT 100 ON PART(P_CONTAINER);
  44.  
  45. STAT 100 ON PARTSUPP(PS_SUPPKEY);
  46. STAT 100 ON PARTSUPP(PS_PARTKEY);
  47.  
  48. STAT 100 ON ORDERS(O_ORDERKEY);
  49. STAT 100 ON ORDERS(O_ORDERDATE);
  50. STAT 100 ON ORDERS(O_ORDERSTATUS);
  51. STAT 100 ON ORDERS(O_ORDERPRIORITY);
  52. STAT 100 ON ORDERS(O_CUSTKEY);
  53. STAT 100 ON ORDERS(O_COMMENT);
  54.  
  55. STAT 100 ON LINEITEM(L_SUPPKEY);
  56. STAT 100 ON LINEITEM(L_PARTKEY);
  57. STAT 100 ON LINEITEM(L_ORDERKEY);
  58. STAT 100 ON LINEITEM(L_SHIPDATE);
  59. STAT 100 ON LINEITEM(L_SHIPMODE);
  60. STAT 100 ON LINEITEM(L_COMMITDATE);
  61. STAT 100 ON LINEITEM(L_RECEIPTDATE);
  62. STAT 100 ON LINEITEM(L_RETURNFLAG);
  63. STAT 100 ON LINEITEM(L_LINESTATUS);
  64. STAT 100 ON LINEITEM(L_QUANTITY);
  65. STAT 100 ON LINEITEM(L_SHIPINSTRUCT);
  66.  
  67. STAT 100 ON CUSTOMER(C_CUSTKEY);
  68. STAT 100 ON CUSTOMER(C_MKTSEGMENT);
  69. STAT 100 ON CUSTOMER(C_NATIONKEY);
  70. STAT 100 ON CUSTOMER(C_ACCTBAL);

7.测试语句执行时间
下方sql为测试的sql语句

  1. --Q1(LINEITEM)
  2. select  
  3.     l_returnflag, 
  4.     l_linestatus, 
  5.     sum(l_quantity) as sum_qty, 
  6.     sum(l_extendedprice) as sum_base_price, 
  7.     sum(l_extendedprice*(1-l_discount)) as sum_disc_price, 
  8.     sum(l_extendedprice*(1-l_discount)*(1+l_tax)) as sum_charge, 
  9.     avg(l_quantity) as avg_qty, 
  10.     avg(l_extendedprice) as avg_price, 
  11.     avg(l_discount) as avg_disc, 
  12.     count(*) as count_order 
  13. from lineitem 
  14. where l_shipdate <= date'1998-12-01' - interval '90' day 
  15. group by l_returnflag, l_linestatus 
  16. order by l_returnflag, l_linestatus;
  17. --Q2
  18. select TOP 100 
  19.     s_acctbal, s_name, 
  20.     n_name, p_partkey, p_mfgr, 
  21.     s_address, s_phone, s_comment 
  22. from part, supplier, partsupp, nation, region 
  23. where p_partkey = ps_partkey 
  24.     and s_suppkey = ps_suppkey 
  25.     and p_size = 15 
  26.     and p_type like '%BRASS' 
  27.     and s_nationkey = n_nationkey 
  28.     and n_regionkey = r_regionkey 
  29.     and r_name = 'EUROPE' 
  30.     and ps_supplycost = 
  31.         ( select min(ps_supplycost) 
  32.         from partsupp, supplier, nation, region 
  33.         where p_partkey = ps_partkey 
  34.             and s_suppkey = ps_suppkey 
  35.             and s_nationkey = n_nationkey 
  36.             and n_regionkey = r_regionkey 
  37.             and r_name = 'EUROPE'
  38.         order by s_acctbal desc, n_name, s_name, p_partkey;
  39. --Q3
  40. select  TOP 10 
  41.     l_orderkey, 
  42.     sum(l_extendedprice*(1-l_discount)) as revenue, 
  43.     o_orderdate, 
  44.     o_shippriority 
  45. from customer, orders, lineitem 
  46. where c_mktsegment = 'BUILDING' 
  47.     and c_custkey = o_custkey 
  48.     and l_orderkey = o_orderkey 
  49.     and o_orderdate < date'1995-03-15' 
  50.     and l_shipdate > date'1995-03-15' 
  51. group by l_orderkey, o_orderdate, o_shippriority 
  52. order by revenue desc, o_orderdate;
  53. --Q4
  54. select  
  55.     o_orderpriority, 
  56.     count(*) as order_count 
  57. from orders 
  58. where o_orderdate >= date'1993-07-01' 
  59.     and o_orderdate < date '1993-07-01' + interval '3' month 
  60.     and exists 
  61.         (select * 
  62.         from lineitem 
  63.         where l_orderkey = o_orderkey 
  64.             and l_commitdate < l_receiptdate ) 
  65.         group by o_orderpriority 
  66.         order by o_orderpriority;
  67. --Q5
  68. select  
  69.     n_name, 
  70.     sum(l_extendedprice * (1 - l_discount)) as revenue 
  71. from customer, orders, lineitem, supplier, nation, region 
  72. where c_custkey = o_custkey 
  73.     and l_orderkey = o_orderkey 
  74.     and l_suppkey = s_suppkey 
  75.     and c_nationkey = s_nationkey 
  76.     and s_nationkey = n_nationkey 
  77.     and n_regionkey = r_regionkey 
  78.     and r_name = 'ASIA' 
  79.     and o_orderdate >= date'1994-01-01' 
  80.     and o_orderdate < date '1994-01-01' + interval '1' year 
  81. group by n_name 
  82. order by revenue desc;
  83. --Q6
  84. select  
  85.     sum(l_extendedprice*l_discount) as revenue 
  86. from lineitem 
  87. where l_shipdate >= '1994-01-01' 
  88.     and l_shipdate < dateadd(year,1, '1994-01-01'
  89.     and l_discount between 0.06 - 0.01 
  90.     and 0.06 + 0.01 
  91.     and l_quantity < 24;
  92. --Q7
  93. select  
  94.     supp_nation, 
  95.     cust_nation, 
  96.     l_year, 
  97.     sum(volume) as revenue 
  98. from ( select n1.n_name as supp_nation, 
  99.         n2.n_name as cust_nation, 
  100.         extract(year from l_shipdate) as l_year, 
  101.         l_extendedprice * (1 - l_discount) as volume 
  102.     from supplier, lineitem, orders, customer, nation n1, nation n2 
  103.     where s_suppkey = l_suppkey 
  104.         and o_orderkey = l_orderkey 
  105.         and c_custkey = o_custkey 
  106.         and s_nationkey = n1.n_nationkey 
  107.         and c_nationkey = n2.n_nationkey 
  108.         and ( (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY') or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE') ) 
  109.         and l_shipdate between date'1995-01-01' and date'1996-12-31' ) as shipping 
  110.     group by supp_nation, cust_nation, l_year 
  111.     order by supp_nation, cust_nation, l_year;
  112. --Q8
  113. select  
  114.     o_year, 
  115.     sum(case when nation = 'BRAZIL' then volume else 0 end) / sum(volume) as mkt_share 
  116. from ( select extract(year from o_orderdate) as o_year, 
  117.         l_extendedprice * (1-l_discount) as volume, 
  118.         n2.n_name as nation 
  119.     from part, supplier, lineitem, orders, customer, nation n1, nation n2, region 
  120.     where p_partkey = l_partkey 
  121.         and s_suppkey = l_suppkey 
  122.         and l_orderkey = o_orderkey 
  123.         and o_custkey = c_custkey 
  124.         and c_nationkey = n1.n_nationkey 
  125.         and n1.n_regionkey = r_regionkey 
  126.         and r_name = 'AMERICA' 
  127.         and s_nationkey = n2.n_nationkey 
  128.         and o_orderdate between date '1995-01-01' 
  129.         and date '1996-12-31' 
  130.         and p_type = 'ECONOMY ANODIZED STEEL' ) as all_nations 
  131.     group by o_year 
  132.     order by o_year;
  133. --Q9
  134. select  
  135.     nation, 
  136.     o_year, 
  137.     sum(amount) as sum_profit 
  138. from ( select n_name as nation, 
  139.         extract(year from o_orderdate) as o_year, 
  140.         l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount 
  141.     from part, supplier, lineitem, partsupp, orders, nation 
  142.     where s_suppkey = l_suppkey 
  143.         and ps_suppkey = l_suppkey 
  144.         and ps_partkey = l_partkey 
  145.         and p_partkey = l_partkey 
  146.         and o_orderkey = l_orderkey 
  147.         and s_nationkey = n_nationkey 
  148.         and p_name like '%green%' ) as profit 
  149. group by nation, o_year 
  150. order by nation, o_year desc;
  151. --Q10
  152. select  top 20 
  153.     c_custkey, 
  154.     c_name, 
  155.     sum(l_extendedprice * (1 - l_discount)) as revenue, 
  156.     c_acctbal, 
  157.     n_name, 
  158.     c_address,     c_phone, 
  159.     c_comment 
  160. from customer, orders, lineitem, nation 
  161. where c_custkey = o_custkey 
  162.     and l_orderkey = o_orderkey 
  163.     and o_orderdate >= date'1993-10-01' 
  164.     and o_orderdate < date'1993-10-01' + interval '3' month 
  165.     and l_returnflag = 'R' 
  166.     and c_nationkey = n_nationkey 
  167. group by c_custkey, c_name, c_acctbal, c_phone, n_name, c_address, c_comment 
  168. order by revenue desc;
  169. --Q11
  170. select  
  171.     ps_partkey, 
  172.     sum(ps_supplycost * ps_availqty) as valuess 
  173. from partsupp, supplier, nation 
  174. where ps_suppkey = s_suppkey 
  175.     and s_nationkey = n_nationkey 
  176.     and n_name = 'GERMANY' 
  177. group by ps_partkey 
  178. having sum(ps_supplycost * ps_availqty) > ( select sum(ps_supplycost * ps_availqty) * 0.0001 
  179.                     from partsupp, supplier, nation 
  180.                     where ps_suppkey = s_suppkey 
  181.                         and s_nationkey = n_nationkey 
  182.                         and n_name = 'GERMANY'
  183. order by valuess desc;
  184. --Q12
  185. select  
  186.     l_shipmode, 
  187.     sum(case when o_orderpriority ='1-URGENT' or o_orderpriority ='2-HIGH' then 1 else 0 end) as high_line_count
  188.     sum(case when o_orderpriority <> '1-URGENT' and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count 
  189. from orders, lineitem 
  190. where o_orderkey = l_orderkey 
  191.     and l_shipmode in ('MAIL', 'SHIP'
  192.     and l_commitdate < l_receiptdate 
  193.     and l_shipdate < l_commitdate 
  194.     and l_receiptdate >= date '1994-01-01' 
  195.     and l_receiptdate < date  '1994-01-01' + interval '1' year 
  196. group by l_shipmode 
  197. order by l_shipmode;
  198. --Q13
  199. select  
  200.     c_count
  201.     count(*) as custdist 
  202. from ( select c_custkey, 
  203.         count(o_orderkey) 
  204.     from customer left outer join orders on c_custkey = o_custkey 
  205.                         and o_comment not like '%special%requests%' 
  206.                 group by c_custkey )as c_orders (c_custkey, c_count
  207. group by c_count 
  208. order by custdist desc, c_count desc;
  209. --Q14
  210. select  
  211.     100.00 * sum(case when p_type like 'PROMO%' 
  212.             then l_extendedprice*(1-l_discount) 
  213.             else 0 end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue 
  214. from lineitem, part 
  215. where l_partkey = p_partkey 
  216.     and l_shipdate >= date '1995-09-01' 
  217.     and l_shipdate < date'1995-09-01' + interval '1' month;
  218. --Q15
  219. create view revenue (supplier_no, total_revenue) as 
  220. select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem 
  221. where l_shipdate >= date '1996-01-01' and l_shipdate < date '1996-01-01' + interval '3' month group by l_suppkey;
  222. select  
  223.     s_suppkey, 
  224.     s_name, 
  225.     s_address
  226.     s_phone, 
  227.     total_revenue 
  228. from supplier, revenue  
  229. where s_suppkey = supplier_no 
  230.     and total_revenue = 
  231.         ( select max(total_revenue) from revenue ) order by s_suppkey;
  232. drop view revenue;
  233. --Q16
  234. select  
  235.     p_brand, 
  236.     p_type
  237.     p_size
  238.     count(distinct ps_suppkey) as supplier_cnt 
  239. from partsupp, part 
  240. where p_partkey = ps_partkey 
  241.     and p_brand <> 'Brand#45' 
  242.     and p_type not like 'MEDIUM POLISHED%' 
  243.     and p_size in (49, 14, 23, 45, 19, 3, 36, 9
  244.     and ps_suppkey not in ( select s_suppkey 
  245.                     from supplier 
  246.                 where s_comment like '%Customer%Complaints%'
  247. group by p_brand, p_type, p_size 
  248. order by supplier_cnt desc, p_brand, p_type, p_size;
  249. --Q17
  250. select  
  251.     sum(l_extendedprice) / 7.0 as avg_yearly 
  252. from lineitem, part 
  253. where p_partkey = l_partkey 
  254.     and p_brand = 'Brand#23' 
  255.     and p_container = 'MED BOX' 
  256.     and l_quantity < ( select 0.2 * avg(l_quantity) from lineitem where l_partkey = p_partkey );
  257. --Q18
  258. select  top 100 
  259.     c_name, 
  260.     c_custkey, 
  261.     o_orderkey, 
  262.     o_orderdate, 
  263.     o_totalprice, 
  264.     sum(l_quantity) 
  265. from customer, orders, lineitem 
  266. where o_orderkey in ( select l_orderkey 
  267.             from lineitem 
  268.             group by l_orderkey 
  269.             having sum(l_quantity) > 300
  270.     and c_custkey = o_custkey 
  271.     and o_orderkey = l_orderkey 
  272. group by c_name, c_custkey, o_orderkey, o_orderdate, o_totalprice 
  273. order by o_totalprice desc, o_orderdate;
  274. --Q19
  275. select  
  276.     sum(l_extendedprice * (1 - l_discount) ) as revenue 
  277. from lineitem, part 
  278. where ( p_partkey = l_partkey 
  279.     and p_brand = 'Brand#12' 
  280.     and p_container in ( 'SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'
  281.     and l_quantity >= 1 
  282.     and l_quantity <= 1 + 10 
  283.     and p_size between 1 and 5 
  284.     and l_shipmode in ('AIR', 'AIR REG'
  285.     and l_shipinstruct = 'DELIVER IN PERSON'
  286. or ( p_partkey = l_partkey and p_brand = 'Brand#23' 
  287.     and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'
  288.     and l_quantity >= 10 
  289.     and l_quantity <= 10 + 10 
  290.     and p_size between 1 and 10 
  291.     and l_shipmode in ('AIR', 'AIR REG'
  292.     and l_shipinstruct = 'DELIVER IN PERSON'
  293. or ( p_partkey = l_partkey 
  294.     and p_brand = 'Brand#34' 
  295.     and p_container in ( 'LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'
  296.     and l_quantity >= 20 
  297.     and l_quantity <= 20 + 10 
  298.     and p_size between 1 and 15 
  299.     and l_shipmode in ('AIR', 'AIR REG'
  300.     and l_shipinstruct = 'DELIVER IN PERSON' );
  301. --Q20
  302. select  
  303.     s_name, 
  304.     s_address 
  305. from supplier, nation 
  306. where s_suppkey in ( select ps_suppkey from partsupp 
  307.             where ps_partkey in ( select p_partkey from part where p_name like 'forest%'
  308.                 and ps_availqty > ( select 0.5 * sum(l_quantity) from lineitem where l_partkey = ps_partkey 
  309.                             and l_suppkey = ps_suppkey 
  310.                             and l_shipdate >= date '1994-01-01' 
  311.                             and l_shipdate < date '1994-01-01' + interval '1' year ) 
  312.            ) 
  313.     and s_nationkey = n_nationkey 
  314.     and n_name = 'CANADA' 
  315. order by s_name;
  316. --Q21
  317. select  top 100 
  318.     s_name, 
  319.     count(*) as numwait 
  320. from supplier, lineitem l1, orders, nation 
  321. where s_suppkey = l1.l_suppkey     and o_orderkey = l1.l_orderkey 
  322.     and o_orderstatus = 'F' 
  323.     and l1.l_receiptdate > l1.l_commitdate 
  324.     and exists ( select * from lineitem l2 
  325.             where l2.l_orderkey = l1.l_orderkey 
  326.                 and l2.l_suppkey <> l1.l_suppkey ) 
  327.     and not exists ( select * from lineitem l3 
  328.                 where l3.l_orderkey = l1.l_orderkey 
  329.                     and l3.l_suppkey <> l1.l_suppkey 
  330.                     and l3.l_receiptdate > l3.l_commitdate ) 
  331.     and s_nationkey = n_nationkey 
  332.     and n_name = 'SAUDI ARABIA' 
  333. group by s_name 
  334. order by numwait desc, s_name;
  335. --Q22
  336. select  
  337.     cntrycode,  
  338.     count(*) as numcust, 
  339.     sum(c_acctbal) as totacctbal 
  340. from ( select substring(c_phone from 1 for 2) as cntrycode, c_acctbal 
  341.     from customer  
  342.     where substring(c_phone from 1 for 2) in ('13','31','23','29','30','18','17'
  343.         and c_acctbal > ( select avg(c_acctbal) from customer where c_acctbal > 0.00 
  344.                     and substring (c_phone from 1 for 2) in ('13','31','23','29','30','18','17'
  345.                 ) 
  346.         and not exists ( select * from orders where o_custkey = c_custkey ) 
  347.      ) as custsale 
  348. group by cntrycode 
  349. order by cntrycode;

下方为Q22的测试运行时间

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/935543?site
推荐阅读
相关标签
  

闽ICP备14008679号