Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 3c81da9

Browse files
authored
Add all tpch queries to sqllogictest (#253)
Also updated https://github.com/cmu-db/optd/issues/184
1 parent 5f26d36 commit 3c81da9

22 files changed

+849
-102
lines changed

optd-sqllogictest/slt/tpch-q1.slt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include _tpch_tables.slt.part
22

33
query
4-
SELECT
4+
select
55
l_returnflag,
66
l_linestatus,
77
sum(l_quantity) as sum_qty,
@@ -12,16 +12,18 @@ SELECT
1212
avg(l_extendedprice) as avg_price,
1313
avg(l_discount) as avg_disc,
1414
count(*) as count_order
15-
FROM
15+
from
1616
lineitem
17-
WHERE
18-
l_shipdate <= date '1998-12-01' - interval '90' day
19-
GROUP BY
20-
l_returnflag, l_linestatus
21-
ORDER BY
22-
l_returnflag, l_linestatus;
17+
where
18+
l_shipdate <= date '1998-12-01' - interval '71' day
19+
group by
20+
l_returnflag,
21+
l_linestatus
22+
order by
23+
l_returnflag,
24+
l_linestatus;
2325
----
2426
A F 37474.00 37569624.64 35676192.0970 37101416.222424 25.354533 25419.231826 0.050866 1478
2527
N F 1041.00 1041301.07 999060.8980 1036450.802280 27.394736 27402.659736 0.042894 38
26-
N O 75168.00 75384955.37 71653166.3034 74498798.133073 25.558653 25632.422771 0.049697 2941
28+
N O 75823.00 76040604.76 72270477.1588 75140545.284463 25.564059 25637.425745 0.049824 2966
2729
R F 36511.00 36570841.24 34738472.8758 36169060.112193 25.059025 25100.096938 0.050027 1457

optd-sqllogictest/slt/tpch-q10.slt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
c_custkey,
6+
c_name,
7+
sum(l_extendedprice * (1 - l_discount)) as revenue,
8+
c_acctbal,
9+
n_name,
10+
c_address,
11+
c_phone,
12+
c_comment
13+
from
14+
customer,
15+
orders,
16+
lineitem,
17+
nation
18+
where
19+
c_custkey = o_custkey
20+
and l_orderkey = o_orderkey
21+
and o_orderdate >= date '1993-10-01'
22+
and o_orderdate < date '1993-10-01' + interval '3' month
23+
and l_returnflag = 'R'
24+
and c_nationkey = n_nationkey
25+
group by
26+
c_custkey,
27+
c_name,
28+
c_acctbal,
29+
c_phone,
30+
n_name,
31+
c_address,
32+
c_comment
33+
order by
34+
revenue desc
35+
limit 20;
36+
----
37+
121 Customer#000000121 282635.1719 6428.32 PERU tv nCR2YKupGN73mQudO 27-411-990-2959 uriously stealthy ideas. carefully final courts use carefully
38+
124 Customer#000000124 222182.5188 1842.49 CHINA aTbyVAW5tCd,v09O 28-183-750-7809 le fluffily even dependencies. quietly s
39+
106 Customer#000000106 190241.3334 3288.42 ARGENTINA xGCOEAUjUNG 11-751-989-4627 lose slyly. ironic accounts along the evenly regular theodolites wake about the special, final gifts.
40+
16 Customer#000000016 161422.0461 4681.03 IRAN cYiaeMLZSMAOQ2 d0W, 20-781-609-3107 kly silent courts. thinly regular theodolites sleep fluffily after
41+
44 Customer#000000044 149364.5652 7315.94 MOZAMBIQUE Oi,dOSPwDu4jo4x,,P85E0dmhZGvNtBwi 26-190-260-5375 r requests around the unusual, bold a
42+
71 Customer#000000071 129481.0245 -611.19 GERMANY TlGalgdXWBmMV,6agLyWYDyIz9MKzcY8gl,w6t1B 17-710-812-5403 g courts across the regular, final pinto beans are blithely pending ac
43+
89 Customer#000000089 121663.1243 1530.76 KENYA dtR, y9JQWUO6FoJExyp8whOU 24-394-451-5404 counts are slyly beyond the slyly final accounts. quickly final ideas wake. r
44+
112 Customer#000000112 111137.7141 2953.35 ROMANIA RcfgG3bO7QeCnfjqJT1 29-233-262-8382 rmanently unusual multipliers. blithely ruthless deposits are furiously along the
45+
62 Customer#000000062 106368.0153 595.61 GERMANY upJK2Dnw13, 17-361-978-7059 kly special dolphins. pinto beans are slyly. quickly regular accounts are furiously a
46+
146 Customer#000000146 103265.9888 3328.68 CANADA GdxkdXG9u7iyI1,,y5tq4ZyrcEy 13-835-723-3223 ffily regular dinos are slyly unusual requests. slyly specia
47+
19 Customer#000000019 99306.0127 8914.71 CHINA uc,3bHIx84H,wdrmLOjVsiqXCq2tr 28-396-526-5053 nag. furiously careful packages are slyly at the accounts. furiously regular in
48+
145 Customer#000000145 99256.9018 9748.93 JORDAN kQjHmt2kcec cy3hfMh969u 23-562-444-8454 ests? express, express instructions use. blithely fina
49+
103 Customer#000000103 97311.7724 2757.45 INDONESIA 8KIsQX4LJ7QMsj6DrtFtXu0nUEdV,8a 19-216-107-2107 furiously pending notornis boost slyly around the blithely ironic ideas? final, even instructions cajole fl
50+
136 Customer#000000136 95855.3980 -842.39 GERMANY QoLsJ0v5C1IQbh,DS1 17-501-210-4726 ackages sleep ironic, final courts. even requests above the blithely bold requests g
51+
53 Customer#000000053 92568.9124 4113.64 MOROCCO HnaxHzTfFTZs8MuCpJyTbZ47Cm4wFOOgib 25-168-852-5363 ar accounts are. even foxes are blithely. fluffily pending deposits boost
52+
49 Customer#000000049 90965.7262 4573.94 IRAN cNgAeX7Fqrdf7HQN9EwjUa4nxT,68L FKAxzl 20-908-631-4424 nusual foxes! fluffily pending packages maintain to the regular
53+
37 Customer#000000037 88065.7458 -917.75 INDIA 7EV4Pwh,3SboctTWt 18-385-235-7162 ilent packages are carefully among the deposits. furiousl
54+
82 Customer#000000082 86998.9644 9468.34 CHINA zhG3EZbap4c992Gj3bK,3Ne,Xn 28-159-442-5305 s wake. bravely regular accounts are furiously. regula
55+
125 Customer#000000125 84808.0680 -234.12 ROMANIA ,wSZXdVR xxIIfm9s8ITyLl3kgjT6UC07GY0Y 29-261-996-3120 x-ray finally after the packages? regular requests c
56+
59 Customer#000000059 84655.5711 3458.60 ARGENTINA zLOCP0wh92OtBihgspOGl4 11-355-584-3112 ously final packages haggle blithely after the express deposits. furiou
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
ps_partkey,
6+
sum(ps_supplycost * ps_availqty) as value
7+
from
8+
partsupp,
9+
supplier,
10+
nation
11+
where
12+
ps_suppkey = s_suppkey
13+
and s_nationkey = n_nationkey
14+
and n_name = 'GERMANY'
15+
group by
16+
ps_partkey having
17+
sum(ps_supplycost * ps_availqty) > (
18+
select
19+
sum(ps_supplycost * ps_availqty) * 0.0001000000
20+
from
21+
partsupp,
22+
supplier,
23+
nation
24+
where
25+
ps_suppkey = s_suppkey
26+
and s_nationkey = n_nationkey
27+
and n_name = 'GERMANY'
28+
)
29+
order by
30+
value desc;
31+
----

optd-sqllogictest/slt/tpch-q12.slt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
l_shipmode,
6+
sum(case
7+
when o_orderpriority = '1-URGENT'
8+
or o_orderpriority = '2-HIGH'
9+
then 1
10+
else 0
11+
end) as high_line_count,
12+
sum(case
13+
when o_orderpriority <> '1-URGENT'
14+
and o_orderpriority <> '2-HIGH'
15+
then 1
16+
else 0
17+
end) as low_line_count
18+
from
19+
orders,
20+
lineitem
21+
where
22+
o_orderkey = l_orderkey
23+
and l_shipmode in ('MAIL', 'SHIP')
24+
and l_commitdate < l_receiptdate
25+
and l_shipdate < l_commitdate
26+
and l_receiptdate >= date '1994-01-01'
27+
and l_receiptdate < date '1994-01-01' + interval '1' year
28+
group by
29+
l_shipmode
30+
order by
31+
l_shipmode;
32+
----
33+
MAIL 5 5
34+
SHIP 5 10

optd-sqllogictest/slt/tpch-q13.slt

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
c_count,
6+
count(*) as custdist
7+
from
8+
(
9+
select
10+
c_custkey,
11+
count(o_orderkey)
12+
from
13+
customer left outer join orders on
14+
c_custkey = o_custkey
15+
and o_comment not like '%special%requests%'
16+
group by
17+
c_custkey
18+
) as c_orders (c_custkey, c_count)
19+
group by
20+
c_count
21+
order by
22+
custdist desc,
23+
c_count desc;
24+
----
25+
0 50
26+
16 8
27+
17 7
28+
20 6
29+
13 6
30+
12 6
31+
9 6
32+
23 5
33+
14 5
34+
10 5
35+
21 4
36+
18 4
37+
11 4
38+
8 4
39+
7 4
40+
26 3
41+
22 3
42+
6 3
43+
5 3
44+
4 3
45+
29 2
46+
24 2
47+
19 2
48+
15 2
49+
28 1
50+
25 1
51+
3 1

optd-sqllogictest/slt/tpch-q14.slt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
100.00 * sum(case
6+
when p_type like 'PROMO%'
7+
then l_extendedprice * (1 - l_discount)
8+
else 0
9+
end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
10+
from
11+
lineitem,
12+
part
13+
where
14+
l_partkey = p_partkey
15+
and l_shipdate >= date '1995-09-01'
16+
and l_shipdate < date '1995-09-01' + interval '1' month;
17+
----
18+
15.23021261159725

optd-sqllogictest/slt/tpch-q15.slt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
include _tpch_tables.slt.part
2+
3+
statement ok
4+
create view revenue0 (supplier_no, total_revenue) as
5+
select
6+
l_suppkey,
7+
sum(l_extendedprice * (1 - l_discount))
8+
from
9+
lineitem
10+
where
11+
l_shipdate >= date '1996-01-01'
12+
and l_shipdate < date '1996-01-01' + interval '3' month
13+
group by
14+
l_suppkey;
15+
16+
query
17+
select
18+
s_suppkey,
19+
s_name,
20+
s_address,
21+
s_phone,
22+
total_revenue
23+
from
24+
supplier,
25+
revenue0
26+
where
27+
s_suppkey = supplier_no
28+
and total_revenue = (
29+
select
30+
max(total_revenue)
31+
from
32+
revenue0
33+
)
34+
order by
35+
s_suppkey;
36+
----
37+
10 Supplier#000000010 Saygah3gYWMp72i PY 34-852-489-8585 797313.3838
38+
39+
statement ok
40+
drop view revenue0;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
p_brand,
6+
p_type,
7+
p_size,
8+
count(distinct ps_suppkey) as supplier_cnt
9+
from
10+
partsupp,
11+
part
12+
where
13+
p_partkey = ps_partkey
14+
and p_brand <> 'Brand#45'
15+
and p_type not like 'MEDIUM POLISHED%'
16+
and p_size in (49, 14, 23, 45, 19, 3, 36, 9)
17+
and ps_suppkey not in (
18+
select
19+
s_suppkey
20+
from
21+
supplier
22+
where
23+
s_comment like '%Customer%Complaints%'
24+
)
25+
group by
26+
p_brand,
27+
p_type,
28+
p_size
29+
order by
30+
supplier_cnt desc,
31+
p_brand,
32+
p_type,
33+
p_size;
34+
----
35+
Brand#11 PROMO ANODIZED TIN 45 4
36+
Brand#11 SMALL PLATED COPPER 45 4
37+
Brand#11 STANDARD POLISHED TIN 45 4
38+
Brand#13 MEDIUM ANODIZED STEEL 36 4
39+
Brand#14 SMALL ANODIZED NICKEL 45 4
40+
Brand#15 LARGE ANODIZED BRASS 45 4
41+
Brand#21 LARGE BURNISHED COPPER 19 4
42+
Brand#23 ECONOMY BRUSHED COPPER 9 4
43+
Brand#25 MEDIUM PLATED BRASS 45 4
44+
Brand#31 ECONOMY PLATED STEEL 23 4
45+
Brand#31 PROMO POLISHED TIN 23 4
46+
Brand#32 MEDIUM BURNISHED BRASS 49 4
47+
Brand#33 LARGE BRUSHED TIN 36 4
48+
Brand#33 SMALL BURNISHED NICKEL 3 4
49+
Brand#34 LARGE PLATED BRASS 45 4
50+
Brand#34 MEDIUM BRUSHED COPPER 9 4
51+
Brand#34 SMALL PLATED BRASS 14 4
52+
Brand#35 STANDARD ANODIZED STEEL 23 4
53+
Brand#43 PROMO POLISHED BRASS 19 4
54+
Brand#43 SMALL BRUSHED NICKEL 9 4
55+
Brand#44 SMALL PLATED COPPER 19 4
56+
Brand#52 MEDIUM BURNISHED TIN 45 4
57+
Brand#52 SMALL BURNISHED NICKEL 14 4
58+
Brand#53 MEDIUM BRUSHED COPPER 3 4
59+
Brand#55 STANDARD ANODIZED BRASS 36 4
60+
Brand#55 STANDARD BRUSHED COPPER 3 4
61+
Brand#13 SMALL BRUSHED NICKEL 19 2
62+
Brand#25 SMALL BURNISHED COPPER 3 2
63+
Brand#43 MEDIUM ANODIZED BRASS 14 2
64+
Brand#53 STANDARD PLATED STEEL 45 2
65+
Brand#24 MEDIUM PLATED STEEL 19 1
66+
Brand#51 ECONOMY POLISHED STEEL 49 1
67+
Brand#53 LARGE BURNISHED NICKEL 23 1
68+
Brand#54 ECONOMY ANODIZED BRASS 9 1
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include _tpch_tables.slt.part
2+
3+
query
4+
select
5+
sum(l_extendedprice) / 7.0 as avg_yearly
6+
from
7+
lineitem,
8+
part
9+
where
10+
p_partkey = l_partkey
11+
and p_brand = 'Brand#53' -- original: Brand#23
12+
and p_container = 'MED BOX'
13+
and l_quantity < (
14+
select
15+
0.2 * avg(l_quantity)
16+
from
17+
lineitem
18+
where
19+
l_partkey = p_partkey
20+
);
21+
----
22+
863.2285714285714285714285714

0 commit comments

Comments
 (0)