Skip to content

Commit 077f00d

Browse files
authored
Optimized and MapJoin friendly Q16 (#3962)
1 parent 6cbda1e commit 077f00d

File tree

2 files changed

+78
-40
lines changed

2 files changed

+78
-40
lines changed

ydb/library/benchmarks/queries/tpch/ydb/q16.sql

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,61 @@
22
-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
33
-- using 1680793381 as a seed to the RNG
44

5-
$join = (
5+
$p = (
66
select
7-
ps.ps_suppkey as ps_suppkey,
8-
ps.ps_partkey as ps_partkey
7+
p.p_brand as p_brand,
8+
p.p_type as p_type,
9+
p.p_size as p_size,
10+
ps.ps_suppkey as ps_suppkey
911
from
12+
`{path}part` as p
13+
join
1014
`{path}partsupp` as ps
11-
left join
12-
`{path}supplier` as w
1315
on
14-
w.s_suppkey = ps.ps_suppkey
15-
where not (s_comment like "%Customer%Complaints%")
16+
p.p_partkey = ps.ps_partkey
17+
where
18+
p.p_brand <> 'Brand#33'
19+
and (not StartsWith(p.p_type, 'PROMO POLISHED'))
20+
and (p.p_size = 20 or p.p_size = 27 or p.p_size = 11 or p.p_size = 45 or p.p_size = 40 or p.p_size = 41 or p.p_size = 34 or p.p_size = 36)
21+
);
22+
23+
$s = (
24+
select
25+
s_suppkey
26+
from
27+
`{path}supplier`
28+
where
29+
s_comment like "%Customer%Complaints%"
1630
);
1731

32+
$j = (
1833
select
1934
p.p_brand as p_brand,
2035
p.p_type as p_type,
2136
p.p_size as p_size,
22-
count(distinct j.ps_suppkey) as supplier_cnt
37+
p.ps_suppkey as ps_suppkey
2338
from
24-
$join as j
25-
join
26-
`{path}part` as p
39+
$p as p
40+
left only join
41+
$s as s
2742
on
28-
p.p_partkey = j.ps_partkey
29-
where
30-
p.p_brand <> 'Brand#33'
31-
and (not StartsWith(p.p_type, 'PROMO POLISHED'))
32-
and (p.p_size = 20 or p.p_size = 27 or p.p_size = 11 or p.p_size = 45 or p.p_size = 40 or p.p_size = 41 or p.p_size = 34 or p.p_size = 36)
43+
p.ps_suppkey = s.s_suppkey
44+
);
45+
46+
select
47+
j.p_brand as p_brand,
48+
j.p_type as p_type,
49+
j.p_size as p_size,
50+
count(distinct j.ps_suppkey) as supplier_cnt
51+
from
52+
$j as j
3353
group by
34-
p.p_brand,
35-
p.p_type,
36-
p.p_size
54+
j.p_brand,
55+
j.p_type,
56+
j.p_size
3757
order by
3858
supplier_cnt desc,
3959
p_brand,
4060
p_type,
4161
p_size
4262
;
43-

ydb/library/benchmarks/queries/tpch/yql/q16.sql

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,61 @@
44
-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
55
-- using 1680793381 as a seed to the RNG
66

7-
$join = (
7+
$p = (
88
select
9-
ps.ps_suppkey as ps_suppkey,
10-
ps.ps_partkey as ps_partkey
9+
p.p_brand as p_brand,
10+
p.p_type as p_type,
11+
p.p_size as p_size,
12+
ps.ps_suppkey as ps_suppkey
1113
from
14+
{{part}} as p
15+
join
1216
{{partsupp}} as ps
13-
left join
14-
{{supplier}} as w
1517
on
16-
w.s_suppkey = ps.ps_suppkey
17-
where not (s_comment like "%Customer%Complaints%")
18+
p.p_partkey = ps.ps_partkey
19+
where
20+
p.p_brand <> 'Brand#33'
21+
and (not StartsWith(p.p_type, 'PROMO POLISHED'))
22+
and (p.p_size = 20 or p.p_size = 27 or p.p_size = 11 or p.p_size = 45 or p.p_size = 40 or p.p_size = 41 or p.p_size = 34 or p.p_size = 36)
23+
);
24+
25+
$s = (
26+
select
27+
s_suppkey
28+
from
29+
{{supplier}}
30+
where
31+
s_comment like "%Customer%Complaints%"
1832
);
1933

34+
$j = (
2035
select
2136
p.p_brand as p_brand,
2237
p.p_type as p_type,
2338
p.p_size as p_size,
24-
count(distinct j.ps_suppkey) as supplier_cnt
39+
p.ps_suppkey as ps_suppkey
2540
from
26-
$join as j
27-
join
28-
{{part}} as p
41+
$p as p
42+
left only join
43+
$s as s
2944
on
30-
p.p_partkey = j.ps_partkey
31-
where
32-
p.p_brand <> 'Brand#33'
33-
and (not StartsWith(p.p_type, 'PROMO POLISHED'))
34-
and (p.p_size = 20 or p.p_size = 27 or p.p_size = 11 or p.p_size = 45 or p.p_size = 40 or p.p_size = 41 or p.p_size = 34 or p.p_size = 36)
45+
p.ps_suppkey = s.s_suppkey
46+
);
47+
48+
select
49+
j.p_brand as p_brand,
50+
j.p_type as p_type,
51+
j.p_size as p_size,
52+
count(distinct j.ps_suppkey) as supplier_cnt
53+
from
54+
$j as j
3555
group by
36-
p.p_brand,
37-
p.p_type,
38-
p.p_size
56+
j.p_brand,
57+
j.p_type,
58+
j.p_size
3959
order by
4060
supplier_cnt desc,
4161
p_brand,
4262
p_type,
4363
p_size
4464
;
45-

0 commit comments

Comments
 (0)