aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexv-smirnov <alex@ydb.tech>2023-07-11 17:43:06 +0300
committeralexv-smirnov <alex@ydb.tech>2023-07-11 17:43:06 +0300
commit18962b0e85f2652a798fb2f95fad7171abc21e38 (patch)
tree314f0fca4ecb9669a04a4dab5433d8a6ae3a4d95
parent1f002d7c846bdae1c5564d7d05ed46aebbef00c8 (diff)
downloadydb-18962b0e85f2652a798fb2f95fad7171abc21e38.tar.gz
Add queries for benchmarks
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q1.sql26
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q10.sql38
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q11.sql33
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q12.sql34
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q13.sql25
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q14.sql19
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q15.sql38
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q16.sql35
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q17.sql23
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q18.sql39
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q19.sql40
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q2.sql49
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q20.sql43
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q21.sql46
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q22.sql41
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q3.sql28
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q4.sql27
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q5.sql30
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q6.sql13
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q7.sql44
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q8.sql42
-rw-r--r--ydb/library/benchmarks/queries/tpch/orig/q9.sql37
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q1.sql28
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q10.sql40
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q11.sql35
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q12.sql36
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q13.sql27
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q14.sql21
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q15.sql40
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q16.sql37
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q17.sql25
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q18.sql41
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q19.sql42
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q2.sql51
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q20.sql45
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q21.sql48
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q22.sql43
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q3.sql31
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q4.sql29
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q5.sql32
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q6.sql16
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q7.sql46
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q8.sql44
-rw-r--r--ydb/library/benchmarks/queries/tpch/pg/q9.sql39
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q1.sql25
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q10.sql86
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q11.sql59
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q12.sql44
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q13.sql32
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q14.sql20
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q15.sql55
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q16.sql43
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q17.sql40
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q18.sql52
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q19.sql39
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q2.sql67
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q20.sql82
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q21.sql86
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q22.sql57
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q3.sql54
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q4.sql28
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q5.sql101
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q6.sql15
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q7.sql96
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q8.sql109
-rw-r--r--ydb/library/benchmarks/queries/tpch/ydb/q9.sql58
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q1.sql27
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q10.sql88
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q11.sql64
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q12.sql46
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q13.sql34
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q14.sql22
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q15.sql57
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q16.sql45
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q17.sql42
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q18.sql54
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q19.sql41
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q2.sql69
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q20.sql84
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q21.sql88
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q22.sql59
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q3.sql56
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q4.sql30
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q5.sql103
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q6.sql17
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q7.sql88
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q8.sql111
-rw-r--r--ydb/library/benchmarks/queries/tpch/yql/q9.sql60
88 files changed, 4079 insertions, 0 deletions
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q1.sql b/ydb/library/benchmarks/queries/tpch/orig/q1.sql
new file mode 100644
index 0000000000..91fb3ba0d6
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q1.sql
@@ -0,0 +1,26 @@
+-- TPC-H/TPC-R Pricing Summary Report Query (Q1)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 '100' day
+group by
+ l_returnflag,
+ l_linestatus
+order by
+ l_returnflag,
+ l_linestatus;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q10.sql b/ydb/library/benchmarks/queries/tpch/orig/q10.sql
new file mode 100644
index 0000000000..892bdc0936
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q10.sql
@@ -0,0 +1,38 @@
+-- TPC-H/TPC-R Returned Item Reporting Query (Q10)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 '1993-12-01'
+ and o_orderdate < date '1993-12-01' + interval '3' month
+ 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
+limit 20;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q11.sql b/ydb/library/benchmarks/queries/tpch/orig/q11.sql
new file mode 100644
index 0000000000..257c53b02e
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q11.sql
@@ -0,0 +1,33 @@
+-- TPC-H/TPC-R Important Stock Identification Query (Q11)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 = 'CANADA'
+group by
+ ps_partkey having
+ sum(ps_supplycost * ps_availqty) > (
+ select
+ sum(ps_supplycost * ps_availqty) * 0.0001000000
+ from
+ partsupp,
+ supplier,
+ nation
+ where
+ ps_suppkey = s_suppkey
+ and s_nationkey = n_nationkey
+ and n_name = 'CANADA'
+ )
+order by
+ value desc;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q12.sql b/ydb/library/benchmarks/queries/tpch/orig/q12.sql
new file mode 100644
index 0000000000..643bdc1030
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q12.sql
@@ -0,0 +1,34 @@
+-- TPC-H/TPC-R Shipping Modes and Order Priority Query (Q12)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ l_shipmode,
+ sum(case
+ when o_orderpriority = '1-URGENT'
+ or o_orderpriority = '2-HIGH'
+ then 1
+ else 0
+ end) as high_line_count,
+ sum(case
+ when o_orderpriority <> '1-URGENT'
+ 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 ('MAIL', 'TRUCK')
+ and l_commitdate < l_receiptdate
+ and l_shipdate < l_commitdate
+ and l_receiptdate >= date '1994-01-01'
+ and l_receiptdate < date '1994-01-01' + interval '1' year
+group by
+ l_shipmode
+order by
+ l_shipmode;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q13.sql b/ydb/library/benchmarks/queries/tpch/orig/q13.sql
new file mode 100644
index 0000000000..84fdb79ad7
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q13.sql
@@ -0,0 +1,25 @@
+-- TPC-H/TPC-R Customer Distribution Query (Q13)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 '%unusual%requests%'
+ group by
+ c_custkey
+ ) as c_orders (c_custkey, c_count)
+group by
+ c_count
+order by
+ custdist desc,
+ c_count desc;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q14.sql b/ydb/library/benchmarks/queries/tpch/orig/q14.sql
new file mode 100644
index 0000000000..a99e3c260d
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q14.sql
@@ -0,0 +1,19 @@
+-- TPC-H/TPC-R Promotion Effect Query (Q14)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 '1994-08-01'
+ and l_shipdate < date '1994-08-01' + interval '1' month;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q15.sql b/ydb/library/benchmarks/queries/tpch/orig/q15.sql
new file mode 100644
index 0000000000..b1fe81cf04
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q15.sql
@@ -0,0 +1,38 @@
+-- TPC-H/TPC-R Top Supplier Query (Q15)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+create view revenue0 (supplier_no, total_revenue) as
+ select
+ l_suppkey,
+ sum(l_extendedprice * (1 - l_discount))
+ from
+ lineitem
+ where
+ l_shipdate >= date '1997-03-01'
+ and l_shipdate < date '1997-03-01' + interval '3' month
+ group by
+ l_suppkey;
+
+select
+ s_suppkey,
+ s_name,
+ s_address,
+ s_phone,
+ total_revenue
+from
+ supplier,
+ revenue0
+where
+ s_suppkey = supplier_no
+ and total_revenue = (
+ select
+ max(total_revenue)
+ from
+ revenue0
+ )
+order by
+ s_suppkey;
+
+drop view revenue0;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q16.sql b/ydb/library/benchmarks/queries/tpch/orig/q16.sql
new file mode 100644
index 0000000000..4980c40872
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q16.sql
@@ -0,0 +1,35 @@
+-- TPC-H/TPC-R Parts/Supplier Relationship Query (Q16)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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#33'
+ and p_type not like 'PROMO POLISHED%'
+ and p_size in (20, 27, 11, 45, 40, 41, 34, 36)
+ and ps_suppkey 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;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q17.sql b/ydb/library/benchmarks/queries/tpch/orig/q17.sql
new file mode 100644
index 0000000000..2a25e05680
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q17.sql
@@ -0,0 +1,23 @@
+-- TPC-H/TPC-R Small-Quantity-Order Revenue Query (Q17)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l_extendedprice) / 7.0 as avg_yearly
+from
+ lineitem,
+ part
+where
+ p_partkey = l_partkey
+ and p_brand = 'Brand#35'
+ and p_container = 'LG DRUM'
+ and l_quantity < (
+ select
+ 0.2 * avg(l_quantity)
+ from
+ lineitem
+ where
+ l_partkey = p_partkey
+ );
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q18.sql b/ydb/library/benchmarks/queries/tpch/orig/q18.sql
new file mode 100644
index 0000000000..c07bb70ce3
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q18.sql
@@ -0,0 +1,39 @@
+-- TPC-H/TPC-R Large Volume Customer Query (Q18)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ c_name,
+ c_custkey,
+ o_orderkey,
+ o_orderdate,
+ o_totalprice,
+ sum(l_quantity)
+from
+ customer,
+ orders,
+ lineitem
+where
+ o_orderkey in (
+ select
+ l_orderkey
+ from
+ lineitem
+ group by
+ l_orderkey having
+ sum(l_quantity) > 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
+limit 100;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q19.sql b/ydb/library/benchmarks/queries/tpch/orig/q19.sql
new file mode 100644
index 0000000000..aff211adce
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q19.sql
@@ -0,0 +1,40 @@
+-- TPC-H/TPC-R Discounted Revenue Query (Q19)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l_extendedprice* (1 - l_discount)) as revenue
+from
+ lineitem,
+ part
+where
+ (
+ p_partkey = l_partkey
+ and p_brand = 'Brand#23'
+ and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
+ and l_quantity >= 7 and l_quantity <= 7 + 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 = 'Brand#15'
+ and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
+ and l_quantity >= 17 and l_quantity <= 17 + 10
+ 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 = 'Brand#44'
+ and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
+ and l_quantity >= 25 and l_quantity <= 25 + 10
+ and p_size between 1 and 15
+ and l_shipmode in ('AIR', 'AIR REG')
+ and l_shipinstruct = 'DELIVER IN PERSON'
+ );
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q2.sql b/ydb/library/benchmarks/queries/tpch/orig/q2.sql
new file mode 100644
index 0000000000..ee36c3ffc6
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q2.sql
@@ -0,0 +1,49 @@
+-- TPC-H/TPC-R Minimum Cost Supplier Query (Q2)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 = 10
+ and p_type like '%COPPER'
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'AMERICA'
+ 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 = 'AMERICA'
+ )
+order by
+ s_acctbal desc,
+ n_name,
+ s_name,
+ p_partkey
+limit 100;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q20.sql b/ydb/library/benchmarks/queries/tpch/orig/q20.sql
new file mode 100644
index 0000000000..65dfb8d3e2
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q20.sql
@@ -0,0 +1,43 @@
+-- TPC-H/TPC-R Potential Part Promotion Query (Q20)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ s_name,
+ s_address
+from
+ supplier,
+ nation
+where
+ s_suppkey in (
+ select
+ ps_suppkey
+ from
+ partsupp
+ where
+ ps_partkey in (
+ select
+ p_partkey
+ from
+ part
+ where
+ p_name like 'maroon%'
+ )
+ 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 '1993-01-01'
+ and l_shipdate < date '1993-01-01' + interval '1' year
+ )
+ )
+ and s_nationkey = n_nationkey
+ and n_name = 'VIETNAM'
+order by
+ s_name;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q21.sql b/ydb/library/benchmarks/queries/tpch/orig/q21.sql
new file mode 100644
index 0000000000..107281d409
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q21.sql
@@ -0,0 +1,46 @@
+-- TPC-H/TPC-R Suppliers Who Kept Orders Waiting Query (Q21)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 (
+ select
+ *
+ from
+ lineitem l2
+ where
+ l2.l_orderkey = l1.l_orderkey
+ and l2.l_suppkey <> l1.l_suppkey
+ )
+ and 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 = 'EGYPT'
+group by
+ s_name
+order by
+ numwait desc,
+ s_name
+limit 100;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q22.sql b/ydb/library/benchmarks/queries/tpch/orig/q22.sql
new file mode 100644
index 0000000000..44530c799e
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q22.sql
@@ -0,0 +1,41 @@
+-- TPC-H/TPC-R Global Sales Opportunity Query (Q22)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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
+ substring(c_phone from 1 for 2) in
+ ('31', '29', '30', '26', '28', '25', '15')
+ and c_acctbal > (
+ select
+ avg(c_acctbal)
+ from
+ customer
+ where
+ c_acctbal > 0.00
+ and substring(c_phone from 1 for 2) in
+ ('31', '29', '30', '26', '28', '25', '15')
+ )
+ and not exists (
+ select
+ *
+ from
+ orders
+ where
+ o_custkey = c_custkey
+ )
+ ) as custsale
+group by
+ cntrycode
+order by
+ cntrycode;
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q3.sql b/ydb/library/benchmarks/queries/tpch/orig/q3.sql
new file mode 100644
index 0000000000..033993165b
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q3.sql
@@ -0,0 +1,28 @@
+-- TPC-H/TPC-R Shipping Priority Query (Q3)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ l_orderkey,
+ sum(l_extendedprice * (1 - l_discount)) as revenue,
+ o_orderdate,
+ o_shippriority
+from
+ customer,
+ orders,
+ lineitem
+where
+ c_mktsegment = 'MACHINERY'
+ and c_custkey = o_custkey
+ and l_orderkey = o_orderkey
+ and o_orderdate < date '1995-03-08'
+ and l_shipdate > date '1995-03-08'
+group by
+ l_orderkey,
+ o_orderdate,
+ o_shippriority
+order by
+ revenue desc,
+ o_orderdate
+limit 10;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q4.sql b/ydb/library/benchmarks/queries/tpch/orig/q4.sql
new file mode 100644
index 0000000000..39a721a19c
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q4.sql
@@ -0,0 +1,27 @@
+-- TPC-H/TPC-R Order Priority Checking Query (Q4)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ o_orderpriority,
+ count(*) as order_count
+from
+ orders
+where
+ o_orderdate >= date '1994-03-01'
+ and o_orderdate < date '1994-03-01' + interval '3' month
+ and exists (
+ select
+ *
+ from
+ lineitem
+ where
+ l_orderkey = o_orderkey
+ and l_commitdate < l_receiptdate
+ )
+group by
+ o_orderpriority
+order by
+ o_orderpriority;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q5.sql b/ydb/library/benchmarks/queries/tpch/orig/q5.sql
new file mode 100644
index 0000000000..4f249dc2a8
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q5.sql
@@ -0,0 +1,30 @@
+-- TPC-H/TPC-R Local Supplier Volume Query (Q5)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 = 'AFRICA'
+ and o_orderdate >= date '1995-01-01'
+ and o_orderdate < date '1995-01-01' + interval '1' year
+group by
+ n_name
+order by
+ revenue desc;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q6.sql b/ydb/library/benchmarks/queries/tpch/orig/q6.sql
new file mode 100644
index 0000000000..74dd411c3c
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q6.sql
@@ -0,0 +1,13 @@
+-- TPC-H/TPC-R Forecasting Revenue Change Query (Q6)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l_extendedprice * l_discount) as revenue
+from
+ lineitem
+where
+ l_shipdate >= date '1995-01-01'
+ and l_shipdate < date '1995-01-01' + interval '1' year
+ and l_discount between 0.07 - 0.01 and 0.07 + 0.01
+ and l_quantity < 25;
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q7.sql b/ydb/library/benchmarks/queries/tpch/orig/q7.sql
new file mode 100644
index 0000000000..999c2a1dda
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q7.sql
@@ -0,0 +1,44 @@
+-- TPC-H/TPC-R Volume Shipping Query (Q7)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 (
+ (n1.n_name = 'PERU' and n2.n_name = 'MOZAMBIQUE')
+ or (n1.n_name = 'MOZAMBIQUE' and n2.n_name = 'PERU')
+ )
+ 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;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q8.sql b/ydb/library/benchmarks/queries/tpch/orig/q8.sql
new file mode 100644
index 0000000000..0325120a32
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q8.sql
@@ -0,0 +1,42 @@
+-- TPC-H/TPC-R National Market Share Query (Q8)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ o_year,
+ sum(case
+ when nation = 'MOZAMBIQUE' 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 = 'AFRICA'
+ and s_nationkey = n2.n_nationkey
+ and o_orderdate between date '1995-01-01' and date '1996-12-31'
+ and p_type = 'ECONOMY PLATED COPPER'
+ ) as all_nations
+group by
+ o_year
+order by
+ o_year;
+
diff --git a/ydb/library/benchmarks/queries/tpch/orig/q9.sql b/ydb/library/benchmarks/queries/tpch/orig/q9.sql
new file mode 100644
index 0000000000..a70ba2fc3e
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/orig/q9.sql
@@ -0,0 +1,37 @@
+-- TPC-H/TPC-R Product Type Profit Measure Query (Q9)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 '%rose%'
+ ) as profit
+group by
+ nation,
+ o_year
+order by
+ nation,
+ o_year desc;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q1.sql b/ydb/library/benchmarks/queries/tpch/pg/q1.sql
new file mode 100644
index 0000000000..af1e05c86f
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q1.sql
@@ -0,0 +1,28 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Pricing Summary Report Query (Q1)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ l_returnflag,
+ l_linestatus,
+ sum(l_quantity) as sum_qty,
+ sum(l_extendedprice) as sum_base_price,
+ sum(l_extendedprice * (1::numeric - l_discount)) as sum_disc_price,
+ sum(l_extendedprice * (1::numeric - l_discount) * (1::numeric + 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 '100' day
+group by
+ l_returnflag,
+ l_linestatus
+order by
+ l_returnflag,
+ l_linestatus;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q10.sql b/ydb/library/benchmarks/queries/tpch/pg/q10.sql
new file mode 100644
index 0000000000..2ad34ffc06
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q10.sql
@@ -0,0 +1,40 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Returned Item Reporting Query (Q10)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ c_custkey,
+ c_name,
+ sum(l_extendedprice * (1::numeric - 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 '1993-12-01'
+ and o_orderdate < date '1993-12-01' + interval '3' month
+ 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
+limit 20;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q11.sql b/ydb/library/benchmarks/queries/tpch/pg/q11.sql
new file mode 100644
index 0000000000..0c84114832
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q11.sql
@@ -0,0 +1,35 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Important Stock Identification Query (Q11)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ ps_partkey,
+ sum(ps_supplycost * ps_availqty::numeric) as value
+from
+ {{partsupp}},
+ {{supplier}},
+ {{nation}}
+where
+ ps_suppkey = s_suppkey
+ and s_nationkey = n_nationkey
+ and n_name = 'CANADA'
+group by
+ ps_partkey having
+ sum(ps_supplycost * ps_availqty::numeric) > (
+ select
+ sum(ps_supplycost * ps_availqty::numeric) * 0.0001000000::numeric
+ from
+ {{partsupp}},
+ {{supplier}},
+ {{nation}}
+ where
+ ps_suppkey = s_suppkey
+ and s_nationkey = n_nationkey
+ and n_name = 'CANADA'
+ )
+order by
+ value desc;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q12.sql b/ydb/library/benchmarks/queries/tpch/pg/q12.sql
new file mode 100644
index 0000000000..b4c1deb5a8
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q12.sql
@@ -0,0 +1,36 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Shipping Modes and Order Priority Query (Q12)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ l_shipmode,
+ sum(case
+ when o_orderpriority = '1-URGENT'
+ or o_orderpriority = '2-HIGH'
+ then 1
+ else 0
+ end) as high_line_count,
+ sum(case
+ when o_orderpriority <> '1-URGENT'
+ 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 ('MAIL', 'TRUCK')
+ and l_commitdate < l_receiptdate
+ and l_shipdate < l_commitdate
+ and l_receiptdate >= date '1994-01-01'
+ and l_receiptdate < date '1994-01-01' + interval '1' year
+group by
+ l_shipmode
+order by
+ l_shipmode;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q13.sql b/ydb/library/benchmarks/queries/tpch/pg/q13.sql
new file mode 100644
index 0000000000..9dfdca9db6
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q13.sql
@@ -0,0 +1,27 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Customer Distribution Query (Q13)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ coalesce(c_count, 0::int8) as 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 '%unusual%requests%'
+ group by
+ c_custkey
+ ) as c_orders (c_custkey, c_count)
+group by
+ c_count
+order by
+ custdist desc,
+ c_count desc;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q14.sql b/ydb/library/benchmarks/queries/tpch/pg/q14.sql
new file mode 100644
index 0000000000..d2e5156dcb
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q14.sql
@@ -0,0 +1,21 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Promotion Effect Query (Q14)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ 100.00::numeric * sum(case
+ when p_type like 'PROMO%'
+ then l_extendedprice * (1::numeric - l_discount)
+ else 0::numeric
+ end) / sum(l_extendedprice * (1::numeric - l_discount)) as promo_revenue
+from
+ {{lineitem}},
+ {{part}}
+where
+ l_partkey = p_partkey
+ and l_shipdate >= date '1994-08-01'
+ and l_shipdate < date '1994-08-01' + interval '1' month;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q15.sql b/ydb/library/benchmarks/queries/tpch/pg/q15.sql
new file mode 100644
index 0000000000..8c7521d444
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q15.sql
@@ -0,0 +1,40 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Top Supplier Query (Q15)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+create view revenue0 (supplier_no, total_revenue) as
+ select
+ l_suppkey,
+ sum(l_extendedprice * (1::numeric - l_discount))
+ from
+ {{lineitem}}
+ where
+ l_shipdate >= date '1997-03-01'
+ and l_shipdate < date '1997-03-01' + interval '3' month
+ group by
+ l_suppkey;
+
+select
+ s_suppkey,
+ s_name,
+ s_address,
+ s_phone,
+ total_revenue
+from
+ {{supplier}},
+ revenue0
+where
+ s_suppkey = supplier_no
+ and total_revenue = (
+ select
+ max(total_revenue)
+ from
+ revenue0
+ )
+order by
+ s_suppkey;
+
+drop view revenue0;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q16.sql b/ydb/library/benchmarks/queries/tpch/pg/q16.sql
new file mode 100644
index 0000000000..d7ebd13bba
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q16.sql
@@ -0,0 +1,37 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Parts/Supplier Relationship Query (Q16)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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#33'
+ and p_type not like 'PROMO POLISHED%'
+ and p_size::int4 in (20, 27, 11, 45, 40, 41, 34, 36)
+ and ps_suppkey 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;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q17.sql b/ydb/library/benchmarks/queries/tpch/pg/q17.sql
new file mode 100644
index 0000000000..17dcf2cda9
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q17.sql
@@ -0,0 +1,25 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Small-Quantity-Order Revenue Query (Q17)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l_extendedprice) / 7.0::numeric as avg_yearly
+from
+ {{lineitem}},
+ {{part}}
+where
+ p_partkey = l_partkey
+ and p_brand = 'Brand#35'
+ and p_container = 'LG DRUM'
+ and l_quantity < (
+ select
+ 0.2::numeric * avg(l_quantity)
+ from
+ {{lineitem}}
+ where
+ l_partkey = p_partkey
+ );
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q18.sql b/ydb/library/benchmarks/queries/tpch/pg/q18.sql
new file mode 100644
index 0000000000..5bf3496b4e
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q18.sql
@@ -0,0 +1,41 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Large Volume Customer Query (Q18)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ c_name,
+ c_custkey,
+ o_orderkey,
+ o_orderdate,
+ o_totalprice,
+ sum(l_quantity)
+from
+ {{customer}},
+ {{orders}},
+ {{lineitem}}
+where
+ o_orderkey in (
+ select
+ l_orderkey
+ from
+ {{lineitem}}
+ group by
+ l_orderkey having
+ sum(l_quantity) > 315::numeric
+ )
+ 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
+limit 100;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q19.sql b/ydb/library/benchmarks/queries/tpch/pg/q19.sql
new file mode 100644
index 0000000000..8de76c2c81
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q19.sql
@@ -0,0 +1,42 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Discounted Revenue Query (Q19)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l_extendedprice* (1::numeric - l_discount)) as revenue
+from
+ {{lineitem}},
+ {{part}}
+where
+ (
+ p_partkey = l_partkey
+ and p_brand = 'Brand#23'
+ and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG')
+ and l_quantity >= 7::numeric and l_quantity <= 7::numeric + 10::numeric
+ and p_size::int4 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 = 'Brand#15'
+ and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK')
+ and l_quantity >= 17::numeric and l_quantity <= 17::numeric + 10::numeric
+ and p_size::int4 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 = 'Brand#44'
+ and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG')
+ and l_quantity >= 25::numeric and l_quantity <= 25::numeric + 10::numeric
+ and p_size::int4 between 1 and 15
+ and l_shipmode in ('AIR', 'AIR REG')
+ and l_shipinstruct = 'DELIVER IN PERSON'
+ );
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q2.sql b/ydb/library/benchmarks/queries/tpch/pg/q2.sql
new file mode 100644
index 0000000000..741f7d13da
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q2.sql
@@ -0,0 +1,51 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Minimum Cost Supplier Query (Q2)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 = 10
+ and p_type like '%COPPER'
+ and s_nationkey = n_nationkey
+ and n_regionkey = r_regionkey
+ and r_name = 'AMERICA'
+ 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 = 'AMERICA'
+ )
+order by
+ s_acctbal desc,
+ n_name,
+ s_name,
+ p_partkey
+limit 100;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q20.sql b/ydb/library/benchmarks/queries/tpch/pg/q20.sql
new file mode 100644
index 0000000000..5d42a94b7d
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q20.sql
@@ -0,0 +1,45 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Potential Part Promotion Query (Q20)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ s_name,
+ s_address
+from
+ {{supplier}},
+ {{nation}}
+where
+ s_suppkey in (
+ select
+ ps_suppkey
+ from
+ {{partsupp}}
+ where
+ ps_partkey in (
+ select
+ p_partkey
+ from
+ {{part}}
+ where
+ p_name like 'maroon%'
+ )
+ and ps_availqty::numeric > (
+ select
+ 0.5::numeric * sum(l_quantity)
+ from
+ {{lineitem}}
+ where
+ l_partkey = ps_partkey
+ and l_suppkey = ps_suppkey
+ and l_shipdate >= date '1993-01-01'
+ and l_shipdate < date '1993-01-01' + interval '1' year
+ )
+ )
+ and s_nationkey = n_nationkey
+ and n_name = 'VIETNAM'
+order by
+ s_name;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q21.sql b/ydb/library/benchmarks/queries/tpch/pg/q21.sql
new file mode 100644
index 0000000000..6db84602e2
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q21.sql
@@ -0,0 +1,48 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Suppliers Who Kept Orders Waiting Query (Q21)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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 (
+ select
+ *
+ from
+ {{lineitem}} l2
+ where
+ l2.l_orderkey = l1.l_orderkey
+ and l2.l_suppkey <> l1.l_suppkey
+ )
+ and 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 = 'EGYPT'
+group by
+ s_name
+order by
+ numwait desc,
+ s_name
+limit 100;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q22.sql b/ydb/library/benchmarks/queries/tpch/pg/q22.sql
new file mode 100644
index 0000000000..916b9dfd65
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q22.sql
@@ -0,0 +1,43 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Global Sales Opportunity Query (Q22)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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
+ substring(c_phone from 1 for 2) in
+ ('31', '29', '30', '26', '28', '25', '15')
+ and c_acctbal > (
+ select
+ avg(c_acctbal)
+ from
+ {{customer}}
+ where
+ c_acctbal > 0.00::numeric
+ and substring(c_phone from 1 for 2) in
+ ('31', '29', '30', '26', '28', '25', '15')
+ )
+ and not exists (
+ select
+ *
+ from
+ {{orders}}
+ where
+ o_custkey = c_custkey
+ )
+ ) as custsale
+group by
+ cntrycode
+order by
+ cntrycode;
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q3.sql b/ydb/library/benchmarks/queries/tpch/pg/q3.sql
new file mode 100644
index 0000000000..88fa1465a2
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q3.sql
@@ -0,0 +1,31 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Shipping Priority Query (Q3)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+-- q3
+select
+ l_orderkey,
+ sum(l_extendedprice * (1::numeric - l_discount)) as revenue,
+ o_orderdate,
+ o_shippriority
+from
+ {{customer}},
+ {{orders}},
+ {{lineitem}}
+where
+ c_mktsegment = 'MACHINERY'
+ and c_custkey = o_custkey
+ and l_orderkey = o_orderkey
+ and o_orderdate < date '1995-03-08'
+ and l_shipdate > date '1995-03-08'
+group by
+ l_orderkey,
+ o_orderdate,
+ o_shippriority
+order by
+ revenue desc,
+ o_orderdate
+limit 10;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q4.sql b/ydb/library/benchmarks/queries/tpch/pg/q4.sql
new file mode 100644
index 0000000000..f41369e693
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q4.sql
@@ -0,0 +1,29 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Order Priority Checking Query (Q4)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ o_orderpriority,
+ count(*) as order_count
+from
+ {{orders}}
+where
+ o_orderdate >= date '1994-03-01'
+ and o_orderdate < date '1994-03-01' + interval '3' month
+ and exists (
+ select
+ *
+ from
+ {{lineitem}}
+ where
+ l_orderkey = o_orderkey
+ and l_commitdate < l_receiptdate
+ )
+group by
+ o_orderpriority
+order by
+ o_orderpriority;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q5.sql b/ydb/library/benchmarks/queries/tpch/pg/q5.sql
new file mode 100644
index 0000000000..d9eb78d78b
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q5.sql
@@ -0,0 +1,32 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Local Supplier Volume Query (Q5)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ n_name,
+ sum(l_extendedprice * (1::numeric - 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 = 'AFRICA'
+ and o_orderdate >= date '1995-01-01'
+ and o_orderdate < date '1995-01-01' + interval '1' year
+group by
+ n_name
+order by
+ revenue desc;
+
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q6.sql b/ydb/library/benchmarks/queries/tpch/pg/q6.sql
new file mode 100644
index 0000000000..3d1fea8a12
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q6.sql
@@ -0,0 +1,16 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Forecasting Revenue Change Query (Q6)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+
+select
+ sum(l_extendedprice * l_discount) as revenue
+from
+ {{lineitem}}
+where
+ l_shipdate >= date '1995-01-01'
+ and l_shipdate < date '1995-01-01' + interval '1' year
+ and l_discount between 0.07::numeric - 0.01::numeric and 0.07::numeric + 0.01::numeric
+ and l_quantity < 25::numeric;
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q7.sql b/ydb/library/benchmarks/queries/tpch/pg/q7.sql
new file mode 100644
index 0000000000..c9c40e2232
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q7.sql
@@ -0,0 +1,46 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Volume Shipping Query (Q7)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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::numeric - 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 (
+ (n1.n_name = 'PERU' and n2.n_name = 'MOZAMBIQUE')
+ or (n1.n_name = 'MOZAMBIQUE' and n2.n_name = 'PERU')
+ )
+ 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;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q8.sql b/ydb/library/benchmarks/queries/tpch/pg/q8.sql
new file mode 100644
index 0000000000..fc23429511
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q8.sql
@@ -0,0 +1,44 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R National Market Share Query (Q8)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ o_year,
+ sum(case
+ when nation = 'MOZAMBIQUE' then volume
+ else 0::numeric
+ end) / sum(volume) as mkt_share
+from
+ (
+ select
+ extract(year from o_orderdate) as o_year,
+ l_extendedprice * (1::numeric - 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 = 'AFRICA'
+ and s_nationkey = n2.n_nationkey
+ and o_orderdate between date '1995-01-01' and date '1996-12-31'
+ and p_type = 'ECONOMY PLATED COPPER'
+ ) as all_nations
+group by
+ o_year
+order by
+ o_year;
+
diff --git a/ydb/library/benchmarks/queries/tpch/pg/q9.sql b/ydb/library/benchmarks/queries/tpch/pg/q9.sql
new file mode 100644
index 0000000000..bf22ab26df
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/pg/q9.sql
@@ -0,0 +1,39 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Product Type Profit Measure Query (Q9)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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::numeric - 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 '%rose%'
+ ) as profit
+group by
+ nation,
+ o_year
+order by
+ nation,
+ o_year desc;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q1.sql b/ydb/library/benchmarks/queries/tpch/ydb/q1.sql
new file mode 100644
index 0000000000..23ae468755
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q1.sql
@@ -0,0 +1,25 @@
+-- TPC-H/TPC-R Pricing Summary Report Query (Q1)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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
+ `{path}lineitem`
+where
+ CAST(l_shipdate AS Timestamp) <= (CAST('1998-12-01' AS Date) - Interval("P100D"))
+group by
+ l_returnflag,
+ l_linestatus
+order by
+ l_returnflag,
+ l_linestatus;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q10.sql b/ydb/library/benchmarks/queries/tpch/ydb/q10.sql
new file mode 100644
index 0000000000..dacca45225
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q10.sql
@@ -0,0 +1,86 @@
+-- TPC-H/TPC-R Returned Item Reporting Query (Q10)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1993-12-01");
+$join1 = (
+select
+ c.c_custkey as c_custkey,
+ c.c_name as c_name,
+ c.c_acctbal as c_acctbal,
+ c.c_address as c_address,
+ c.c_phone as c_phone,
+ c.c_comment as c_comment,
+ c.c_nationkey as c_nationkey,
+ o.o_orderkey as o_orderkey
+from
+ `{path}customer` as c
+join
+ `{path}orders` as o
+on
+ c.c_custkey = o.o_custkey
+where
+ cast(o.o_orderdate as timestamp) >= $border and
+ cast(o.o_orderdate as timestamp) < ($border + Interval("P90D"))
+);
+$join2 = (
+select
+ j.c_custkey as c_custkey,
+ j.c_name as c_name,
+ j.c_acctbal as c_acctbal,
+ j.c_address as c_address,
+ j.c_phone as c_phone,
+ j.c_comment as c_comment,
+ j.c_nationkey as c_nationkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_discount as l_discount
+from
+ $join1 as j
+join
+ `{path}lineitem` as l
+on
+ l.l_orderkey = j.o_orderkey
+where
+ l.l_returnflag = 'R'
+);
+$join3 = (
+select
+ j.c_custkey as c_custkey,
+ j.c_name as c_name,
+ j.c_acctbal as c_acctbal,
+ j.c_address as c_address,
+ j.c_phone as c_phone,
+ j.c_comment as c_comment,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ n.n_name as n_name
+from
+ $join2 as j
+join
+ `{path}nation` as n
+on
+ n.n_nationkey = j.c_nationkey
+);
+select
+ c_custkey,
+ c_name,
+ sum(l_extendedprice * (1 - l_discount)) as revenue,
+ c_acctbal,
+ n_name,
+ c_address,
+ c_phone,
+ c_comment
+from
+ $join3
+group by
+ c_custkey,
+ c_name,
+ c_acctbal,
+ c_phone,
+ n_name,
+ c_address,
+ c_comment
+order by
+ revenue desc
+limit 20;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q11.sql b/ydb/library/benchmarks/queries/tpch/ydb/q11.sql
new file mode 100644
index 0000000000..85d88789d6
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q11.sql
@@ -0,0 +1,59 @@
+-- TPC-H/TPC-R Important Stock Identification Query (Q11)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ ps.ps_partkey as ps_partkey,
+ ps.ps_supplycost as ps_supplycost,
+ ps.ps_availqty as ps_availqty,
+ s.s_nationkey as s_nationkey
+from
+ `{path}partsupp` as ps
+join
+ `{path}supplier` as s
+on
+ ps.ps_suppkey = s.s_suppkey
+);
+$join2 = (
+select
+ j.ps_partkey as ps_partkey,
+ j.ps_supplycost as ps_supplycost,
+ j.ps_availqty as ps_availqty,
+ j.s_nationkey as s_nationkey
+from
+ $join1 as j
+join
+ `{path}nation` as n
+on
+ n.n_nationkey = j.s_nationkey
+where
+ n.n_name = 'CANADA'
+);
+$threshold = (
+select
+ sum(ps_supplycost * ps_availqty) * 0.0001000000 as threshold
+from
+ $join2
+);
+$values = (
+select
+ ps_partkey,
+ sum(ps_supplycost * ps_availqty) as value
+from
+ $join2
+group by
+ ps_partkey
+);
+
+select
+ v.ps_partkey as ps_partkey,
+ v.value as value
+from
+ $values as v
+cross join
+ $threshold as t
+where
+ v.value > t.threshold
+order by
+ value desc;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q12.sql b/ydb/library/benchmarks/queries/tpch/ydb/q12.sql
new file mode 100644
index 0000000000..ed19f2d239
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q12.sql
@@ -0,0 +1,44 @@
+-- TPC-H/TPC-R Shipping Modes and Order Priority Query (Q12)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join = (
+ select
+ l.l_shipmode as l_shipmode,
+ o.o_orderpriority as o_orderpriority,
+ l.l_commitdate as l_commitdate,
+ l.l_shipdate as l_shipdate,
+ l.l_receiptdate as l_receiptdate
+ from
+ `{path}orders` as o
+ join `{path}lineitem` as l
+ on o.o_orderkey == l.l_orderkey
+);
+
+$border = Date("1994-01-01");
+
+select
+ l_shipmode,
+ sum(case
+ when o_orderpriority = '1-URGENT'
+ or o_orderpriority = '2-HIGH'
+ then 1
+ else 0
+ end) as high_line_count,
+ sum(case
+ when o_orderpriority <> '1-URGENT'
+ and o_orderpriority <> '2-HIGH'
+ then 1
+ else 0
+ end) as low_line_count
+from $join
+where
+ (l_shipmode = 'MAIL' or l_shipmode = 'TRUCK')
+ and l_commitdate < l_receiptdate
+ and l_shipdate < l_commitdate
+ and cast(l_receiptdate as timestamp) >= $border
+ and cast(l_receiptdate as timestamp) < ($border + Interval("P365D"))
+group by
+ l_shipmode
+order by
+ l_shipmode;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q13.sql b/ydb/library/benchmarks/queries/tpch/ydb/q13.sql
new file mode 100644
index 0000000000..f9b5f3abc1
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q13.sql
@@ -0,0 +1,32 @@
+-- TPC-H/TPC-R Customer Distribution Query (Q13)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$orders = (
+ select
+ o_orderkey,
+ o_custkey
+ from
+ `{path}orders`
+ where
+ o_comment NOT LIKE "%unusual%requests%"
+);
+select
+ c_count as c_count,
+ count(*) as custdist
+from
+ (
+ select
+ c.c_custkey as c_custkey,
+ count(o.o_orderkey) as c_count
+ from
+ `{path}customer` as c left outer join $orders as o on
+ c.c_custkey = o.o_custkey
+ group by
+ c.c_custkey
+ ) as c_orders
+group by
+ c_count
+order by
+ custdist desc,
+ c_count desc;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q14.sql b/ydb/library/benchmarks/queries/tpch/ydb/q14.sql
new file mode 100644
index 0000000000..fa052f3178
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q14.sql
@@ -0,0 +1,20 @@
+-- TPC-H/TPC-R Promotion Effect Query (Q14)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1994-08-01");
+select
+ 100.00 * sum(case
+ when StartsWith(p.p_type, 'PROMO')
+ then l.l_extendedprice * (1 - l.l_discount)
+ else 0
+ end) / sum(l.l_extendedprice * (1 - l.l_discount)) as promo_revenue
+from
+ `{path}lineitem` as l
+join
+ `{path}part` as p
+on
+ l.l_partkey = p.p_partkey
+where
+ cast(l.l_shipdate as timestamp) >= $border
+ and cast(l.l_shipdate as timestamp) < ($border + Interval("P31D"));
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q15.sql b/ydb/library/benchmarks/queries/tpch/ydb/q15.sql
new file mode 100644
index 0000000000..c405749460
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q15.sql
@@ -0,0 +1,55 @@
+-- TPC-H/TPC-R Top Supplier Query (Q15)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1997-03-01");
+$revenue0 = (
+ select
+ l_suppkey as supplier_no,
+ sum(l_extendedprice * (1 - l_discount)) as total_revenue,
+ cast(sum(l_extendedprice * (1 - l_discount)) as Uint64) as total_revenue_approx
+ from
+ `{path}lineitem`
+ where
+ cast(l_shipdate as timestamp) >= $border
+ and cast(l_shipdate as timestamp) < ($border + Interval("P92D"))
+ group by
+ l_suppkey
+);
+$max_revenue = (
+select
+ max(total_revenue_approx) as max_revenue
+from
+ $revenue0
+);
+$join1 = (
+select
+ s.s_suppkey as s_suppkey,
+ s.s_name as s_name,
+ s.s_address as s_address,
+ s.s_phone as s_phone,
+ r.total_revenue as total_revenue,
+ r.total_revenue_approx as total_revenue_approx
+from
+ `{path}supplier` as s
+join
+ $revenue0 as r
+on
+ s.s_suppkey = r.supplier_no
+);
+
+select
+ j.s_suppkey as s_suppkey,
+ j.s_name as s_name,
+ j.s_address as s_address,
+ j.s_phone as s_phone,
+ j.total_revenue as total_revenue
+from
+ $join1 as j
+join
+ $max_revenue as m
+on
+ j.total_revenue_approx = m.max_revenue
+order by
+ s_suppkey;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q16.sql b/ydb/library/benchmarks/queries/tpch/ydb/q16.sql
new file mode 100644
index 0000000000..167da30ced
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q16.sql
@@ -0,0 +1,43 @@
+-- TPC-H/TPC-R Parts/Supplier Relationship Query (Q16)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join = (
+select
+ ps.ps_suppkey as ps_suppkey,
+ ps.ps_partkey as ps_partkey
+from
+ `{path}partsupp` as ps
+left join
+ `{path}supplier` as w
+on
+ w.s_suppkey = ps.ps_suppkey
+where not (s_comment like "%Customer%Complaints%")
+);
+
+select
+ p.p_brand as p_brand,
+ p.p_type as p_type,
+ p.p_size as p_size,
+ count(distinct j.ps_suppkey) as supplier_cnt
+from
+ $join as j
+join
+ `{path}part` as p
+on
+ p.p_partkey = j.ps_partkey
+where
+ p.p_brand <> 'Brand#33'
+ and (not StartsWith(p.p_type, 'PROMO POLISHED'))
+ 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)
+group by
+ p.p_brand,
+ p.p_type,
+ p.p_size
+order by
+ supplier_cnt desc,
+ p_brand,
+ p_type,
+ p_size
+;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q17.sql b/ydb/library/benchmarks/queries/tpch/ydb/q17.sql
new file mode 100644
index 0000000000..4e0ef36215
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q17.sql
@@ -0,0 +1,40 @@
+-- TPC-H/TPC-R Small-Quantity-Order Revenue Query (Q17)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$threshold = (
+select
+ 0.2 * avg(l_quantity) as threshold,
+ l_partkey
+from
+ `{path}lineitem`
+group by
+ l_partkey
+);
+
+$join1 = (
+select
+ p.p_partkey as p_partkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_quantity as l_quantity
+from
+ `{path}lineitem` as l
+join
+ `{path}part` as p
+on
+ p.p_partkey = l.l_partkey
+where
+ p.p_brand = 'Brand#35'
+ and p.p_container = 'LG DRUM'
+);
+
+select
+ sum(j.l_extendedprice) / 7.0 as avg_yearly
+from
+ $join1 as j
+join
+ $threshold as t
+on
+ j.p_partkey = t.l_partkey
+where
+ j.l_quantity < t.threshold;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q18.sql b/ydb/library/benchmarks/queries/tpch/ydb/q18.sql
new file mode 100644
index 0000000000..876900f721
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q18.sql
@@ -0,0 +1,52 @@
+-- TPC-H/TPC-R Large Volume Customer Query (Q18)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$in = (
+select
+ l_orderkey,
+ sum(l_quantity) as sum_l_quantity
+from
+ `{path}lineitem`
+group by
+ l_orderkey having
+ sum(l_quantity) > 315
+);
+
+$join1 = (
+select
+ c.c_name as c_name,
+ c.c_custkey as c_custkey,
+ o.o_orderkey as o_orderkey,
+ o.o_orderdate as o_orderdate,
+ o.o_totalprice as o_totalprice
+from
+ `{path}customer` as c
+join
+ `{path}orders` as o
+on
+ c.c_custkey = o.o_custkey
+);
+select
+ j.c_name as c_name,
+ j.c_custkey as c_custkey,
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.o_totalprice as o_totalprice,
+ sum(i.sum_l_quantity) as sum_l_quantity
+from
+ $join1 as j
+join
+ $in as i
+on
+ i.l_orderkey = j.o_orderkey
+group by
+ j.c_name,
+ j.c_custkey,
+ j.o_orderkey,
+ j.o_orderdate,
+ j.o_totalprice
+order by
+ o_totalprice desc,
+ o_orderdate
+limit 100;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q19.sql b/ydb/library/benchmarks/queries/tpch/ydb/q19.sql
new file mode 100644
index 0000000000..ea98b9f377
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q19.sql
@@ -0,0 +1,39 @@
+-- TPC-H/TPC-R Discounted Revenue Query (Q19)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l.l_extendedprice* (1 - l.l_discount)) as revenue
+from
+ `{path}lineitem` as l
+join
+ `{path}part` as p
+on
+ p.p_partkey = l.l_partkey
+where
+ (
+ p.p_brand = 'Brand#23'
+ and (p.p_container = 'SM CASE' or p.p_container = 'SM BOX' or p.p_container = 'SM PACK' or p.p_container = 'SM PKG')
+ and l.l_quantity >= 7 and l.l_quantity <= 7 + 10
+ and p.p_size between 1 and 5
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ )
+ or
+ (
+ p.p_brand = 'Brand#15'
+ and (p.p_container = 'MED BAG' or p.p_container = 'MED BOX' or p.p_container = 'MED PKG' or p.p_container = 'MED PACK')
+ and l.l_quantity >= 17 and l.l_quantity <= 17 + 10
+ and p.p_size between 1 and 10
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ )
+ or
+ (
+ p.p_brand = 'Brand#44'
+ and (p.p_container = 'LG CASE' or p.p_container = 'LG BOX' or p.p_container = 'LG PACK' or p.p_container = 'LG PKG')
+ and l.l_quantity >= 25 and l.l_quantity <= 25 + 10
+ and p.p_size between 1 and 15
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ );
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q2.sql b/ydb/library/benchmarks/queries/tpch/ydb/q2.sql
new file mode 100644
index 0000000000..a06b4711be
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q2.sql
@@ -0,0 +1,67 @@
+-- TPC-H/TPC-R Minimum Cost Supplier Query (Q2)
+-- using 1680793381 as a seed to the RNG
+
+$r = (select r_regionkey from
+ `{path}region`
+where r_name='AMERICA');
+
+$j1 = (select n_name,n_nationkey
+ from `{path}nation` as n
+ join $r as r on
+ n.n_regionkey = r.r_regionkey);
+
+$j2 = (select s_acctbal,s_name,s_address,s_phone,s_comment,n_name,s_suppkey
+ from `{path}supplier` as s
+ join $j1 as j on
+ s.s_nationkey = j.n_nationkey
+);
+
+$j3 = (select ps_partkey,ps_supplycost,s_acctbal,s_name,s_address,s_phone,s_comment,n_name
+ from `{path}partsupp` as ps
+ join $j2 as j on
+ ps.ps_suppkey = j.s_suppkey
+);
+
+$min_ps_supplycost = (select min(ps_supplycost) as min_ps_supplycost,ps_partkey
+ from $j3
+ group by ps_partkey
+);
+
+$p = (select p_partkey,p_mfgr
+ from `{path}part`
+ where
+ p_size = 10
+ and p_type like '%COPPER'
+);
+
+$j4 = (select s_acctbal,
+ s_name,
+ n_name,
+ p_partkey,
+ p_mfgr,
+ s_address,
+ s_phone,
+ s_comment
+ from $p as p
+ join $j3 as j on p.p_partkey = j.ps_partkey
+ join $min_ps_supplycost as m on p.p_partkey = m.ps_partkey
+ where min_ps_supplycost=ps_supplycost
+);
+
+select
+ s_acctbal,
+ s_name,
+ n_name,
+ p_partkey,
+ p_mfgr,
+ s_address,
+ s_phone,
+ s_comment
+from $j4
+order by
+ s_acctbal desc,
+ n_name,
+ s_name,
+ p_partkey
+limit 100;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q20.sql b/ydb/library/benchmarks/queries/tpch/ydb/q20.sql
new file mode 100644
index 0000000000..b70925abed
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q20.sql
@@ -0,0 +1,82 @@
+-- TPC-H/TPC-R Potential Part Promotion Query (Q20)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1993-01-01");
+$threshold = (
+select
+ 0.5 * sum(l_quantity) as threshold,
+ l_partkey as l_partkey,
+ l_suppkey as l_suppkey
+from
+ `{path}lineitem`
+where
+ cast(l_shipdate as timestamp) >= $border
+ and cast(l_shipdate as timestamp) < ($border + Interval("P365D"))
+group by
+ l_partkey, l_suppkey
+);
+
+$parts = (
+select
+ p_partkey
+from
+ `{path}part`
+where
+ StartsWith(p_name, 'maroon')
+);
+
+$join1 = (
+select
+ ps.ps_suppkey as ps_suppkey,
+ ps.ps_availqty as ps_availqty,
+ ps.ps_partkey as ps_partkey
+from
+ `{path}partsupp` as ps
+join any
+ $parts as p
+on
+ ps.ps_partkey = p.p_partkey
+);
+
+$join2 = (
+select
+ distinct(j.ps_suppkey) as ps_suppkey
+from
+ $join1 as j
+join any
+ $threshold as t
+on
+ j.ps_partkey = t.l_partkey and j.ps_suppkey = t.l_suppkey
+where
+ j.ps_availqty > t.threshold
+);
+
+$join3 = (
+select
+ j.ps_suppkey as ps_suppkey,
+ s.s_name as s_name,
+ s.s_address as s_address,
+ s.s_nationkey as s_nationkey
+from
+ $join2 as j
+join any
+ `{path}supplier` as s
+on
+ j.ps_suppkey = s.s_suppkey
+);
+
+select
+ j.s_name as s_name,
+ j.s_address as s_address
+from
+ $join3 as j
+join
+ `{path}nation` as n
+on
+ j.s_nationkey = n.n_nationkey
+where
+ n.n_name = 'VIETNAM'
+order by
+ s_name;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q21.sql b/ydb/library/benchmarks/queries/tpch/ydb/q21.sql
new file mode 100644
index 0000000000..ddd255b4fb
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q21.sql
@@ -0,0 +1,86 @@
+-- TPC-H/TPC-R Suppliers Who Kept Orders Waiting Query (Q21)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$exists = (
+ select
+ COUNT(*) > 0 as result,
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ `{path}lineitem` as l1
+ join
+ `{path}lineitem` as l2
+ on
+ l2.l_orderkey = l1.l_orderkey
+ where
+ l2.l_suppkey <> l1.l_suppkey
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+$not_exists_inverse = (
+ select
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ `{path}lineitem` as l1
+ join
+ `{path}lineitem` as l3
+ on
+ l3.l_orderkey = l1.l_orderkey
+ where
+ l3.l_suppkey <> l1.l_suppkey
+ and l3.l_receiptdate > l3.l_commitdate
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+$not_exists = (
+ select
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ `{path}lineitem` as l1
+ left only join
+ $not_exists_inverse AS nei
+ on
+ nei.l_orderkey = l1.l_orderkey and
+ nei.l_suppkey = l1.l_suppkey
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+
+select
+ s.s_name as s_name,
+ count(*) as numwait
+from
+ `{path}supplier` as s
+join
+ `{path}lineitem` as l1
+on
+ s.s_suppkey = l1.l_suppkey
+join
+ `{path}orders` as o
+on
+ o.o_orderkey = l1.l_orderkey
+join
+ `{path}nation` as n
+on
+ s.s_nationkey = n.n_nationkey
+join
+ $exists as e
+ on e.l_orderkey == l1.l_orderkey and
+ e.l_suppkey == l1.l_suppkey
+join
+ $not_exists as ne
+ on ne.l_orderkey == l1.l_orderkey and
+ ne.l_suppkey == l1.l_suppkey
+where
+ o.o_orderstatus = 'F'
+ and l1.l_receiptdate > l1.l_commitdate
+ and n.n_name = 'EGYPT'
+group by
+ s.s_name
+order by
+ numwait desc,
+ s_name
+limit 100;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q22.sql b/ydb/library/benchmarks/queries/tpch/ydb/q22.sql
new file mode 100644
index 0000000000..33829df38f
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q22.sql
@@ -0,0 +1,57 @@
+-- TPC-H/TPC-R Global Sales Opportunity Query (Q22)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$customers = (
+select
+ c_acctbal,
+ c_custkey,
+ Substring(c_phone, 0u, 2u) as cntrycode
+from
+ `{path}customer`
+where (Substring(c_phone, 0u, 2u) = '31' or Substring(c_phone, 0u, 2u) = '29' or Substring(c_phone, 0u, 2u) = '30' or Substring(c_phone, 0u, 2u) = '26' or Substring(c_phone, 0u, 2u) = '28' or Substring(c_phone, 0u, 2u) = '25' or Substring(c_phone, 0u, 2u) = '15')
+);
+$avg = (
+select
+ avg(c_acctbal) as a
+from
+ $customers
+where
+ c_acctbal > 0.00
+);
+$join1 = (
+select
+ c.c_acctbal as c_acctbal,
+ c.c_custkey as c_custkey,
+ c.cntrycode as cntrycode
+from
+ $customers as c
+cross join
+ $avg as a
+where
+ c.c_acctbal > a.a
+);
+$join2 = (
+select
+ j.cntrycode as cntrycode,
+ c_custkey,
+ j.c_acctbal as c_acctbal
+from
+ $join1 as j
+left only join
+ `{path}orders` as o
+on
+ o.o_custkey = j.c_custkey
+);
+
+select
+ cntrycode,
+ count(*) as numcust,
+ sum(c_acctbal) as totacctbal
+from
+ $join2 as custsale
+group by
+ cntrycode
+order by
+ cntrycode;
+
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q3.sql b/ydb/library/benchmarks/queries/tpch/ydb/q3.sql
new file mode 100644
index 0000000000..5da862c45c
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q3.sql
@@ -0,0 +1,54 @@
+-- TPC-H/TPC-R Shipping Priority Query (Q3)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ c.c_mktsegment as c_mktsegment,
+ o.o_orderdate as o_orderdate,
+ o.o_shippriority as o_shippriority,
+ o.o_orderkey as o_orderkey
+from
+ `{path}customer` as c
+join
+ `{path}orders` as o
+on
+ c.c_custkey = o.o_custkey
+);
+
+$join2 = (
+select
+ j1.c_mktsegment as c_mktsegment,
+ j1.o_orderdate as o_orderdate,
+ j1.o_shippriority as o_shippriority,
+ l.l_orderkey as l_orderkey,
+ l.l_discount as l_discount,
+ l.l_shipdate as l_shipdate,
+ l.l_extendedprice as l_extendedprice
+from
+ $join1 as j1
+join
+ `{path}lineitem` as l
+on
+ l.l_orderkey = j1.o_orderkey
+);
+
+select
+ l_orderkey,
+ sum(l_extendedprice * (1 - l_discount)) as revenue,
+ o_orderdate,
+ o_shippriority
+from
+ $join2
+where
+ c_mktsegment = 'MACHINERY'
+ and CAST(o_orderdate AS Timestamp) < Date('1995-03-08')
+ and CAST(l_shipdate AS Timestamp) > Date('1995-03-08')
+group by
+ l_orderkey,
+ o_orderdate,
+ o_shippriority
+order by
+ revenue desc,
+ o_orderdate
+limit 10;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q4.sql b/ydb/library/benchmarks/queries/tpch/ydb/q4.sql
new file mode 100644
index 0000000000..3cebbcbcb5
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q4.sql
@@ -0,0 +1,28 @@
+-- TPC-H/TPC-R Order Priority Checking Query (Q4)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1994-03-01");
+
+$join = (select
+ o.o_orderpriority as o_orderpriority,
+ o.o_orderdate as o_orderdate,
+ l.l_commitdate as l_commitdate,
+ l.l_receiptdate as l_receiptdate
+ from
+ `{path}orders` as o
+ join any `{path}lineitem` as l
+ on o.o_orderkey = l.l_orderkey);
+
+select
+ o_orderpriority,
+ count(*) as order_count
+from $join
+where
+ CAST(o_orderdate AS Timestamp) >= $border
+ and CAST(o_orderdate AS Timestamp) < DateTime::MakeDate(DateTime::ShiftMonths($border, 3))
+ and l_commitdate < l_receiptdate
+group by
+ o_orderpriority
+order by
+ o_orderpriority;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q5.sql b/ydb/library/benchmarks/queries/tpch/ydb/q5.sql
new file mode 100644
index 0000000000..279b43ee3e
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q5.sql
@@ -0,0 +1,101 @@
+-- TPC-H/TPC-R Local Supplier Volume Query (Q5)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ o.o_orderkey as o_orderkey,
+ o.o_orderdate as o_orderdate,
+ c.c_nationkey as c_nationkey
+from
+ `{path}customer` as c
+join
+ `{path}orders` as o
+on
+ c.c_custkey = o.o_custkey
+);
+
+$join2 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_discount as l_discount,
+ l.l_suppkey as l_suppkey
+from
+ $join1 as j
+join
+ `{path}lineitem` as l
+on
+ l.l_orderkey = j.o_orderkey
+);
+
+$join3 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ s.s_nationkey as s_nationkey
+from
+ $join2 as j
+join
+ `{path}supplier` as s
+on
+ j.l_suppkey = s.s_suppkey
+);
+$join4 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ j.s_nationkey as s_nationkey,
+ n.n_regionkey as n_regionkey,
+ n.n_name as n_name
+from
+ $join3 as j
+join
+ `{path}nation` as n
+on
+ j.s_nationkey = n.n_nationkey
+ and j.c_nationkey = n.n_nationkey
+);
+$join5 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ j.s_nationkey as s_nationkey,
+ j.n_regionkey as n_regionkey,
+ j.n_name as n_name,
+ r.r_name as r_name
+from
+ $join4 as j
+join
+ `{path}region` as r
+on
+ j.n_regionkey = r.r_regionkey
+);
+$border = Date("1995-01-01");
+select
+ n_name,
+ sum(l_extendedprice * (1 - l_discount)) as revenue
+from
+ $join5
+where
+ r_name = 'AFRICA'
+ and CAST(o_orderdate AS Timestamp) >= $border
+ and CAST(o_orderdate AS Timestamp) < ($border + Interval("P365D"))
+group by
+ n_name
+order by
+ revenue desc;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q6.sql b/ydb/library/benchmarks/queries/tpch/ydb/q6.sql
new file mode 100644
index 0000000000..272b01b521
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q6.sql
@@ -0,0 +1,15 @@
+-- TPC-H/TPC-R Forecasting Revenue Change Query (Q6)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1995-01-01");
+
+select
+ sum(l_extendedprice * l_discount) as revenue
+from
+ `{path}lineitem`
+where
+ CAST(l_shipdate AS Timestamp) >= $border
+ and cast(l_shipdate as Timestamp) < ($border + Interval("P365D"))
+ and l_discount between 0.07 - 0.01 and 0.07 + 0.01
+ and l_quantity < 25;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q7.sql b/ydb/library/benchmarks/queries/tpch/ydb/q7.sql
new file mode 100644
index 0000000000..e9935234e8
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q7.sql
@@ -0,0 +1,96 @@
+-- TPC-H/TPC-R Volume Shipping Query (Q7)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ l.l_extendedprice * (1 - l.l_discount) as volume,
+ DateTime::GetYear(cast(l.l_shipdate as timestamp)) as l_year,
+ l.l_orderkey as l_orderkey,
+ s.s_nationkey as s_nationkey
+from
+ `{path}supplier` as s
+join
+ `{path}lineitem` as l
+on
+ s.s_suppkey = l.l_suppkey
+where cast(cast(l.l_shipdate as Timestamp) as Date) between
+ Date('1995-01-01')
+ and Date('1996-12-31')
+);
+$join2 = (
+select
+ j.volume as volume,
+ j.l_year as l_year,
+ j.s_nationkey as s_nationkey,
+ o.o_orderkey as o_orderkey,
+ o.o_custkey as o_custkey
+from
+ $join1 as j
+join
+ `{path}orders` as o
+on
+ o.o_orderkey = j.l_orderkey
+);
+
+$join3 = (
+select
+ j.volume as volume,
+ j.l_year as l_year,
+ j.s_nationkey as s_nationkey,
+ c.c_nationkey as c_nationkey
+from
+ $join2 as j
+join
+ `{path}customer` as c
+on
+ c.c_custkey = j.o_custkey
+);
+
+$join4 = (
+select
+ j.volume as volume,
+ j.l_year as l_year,
+ j.c_nationkey as c_nationkey,
+ j.s_nationkey as s_nationkey,
+ n.n_name as n_name
+from
+ $join3 as j
+join
+ `{path}nation` as n
+on
+ j.s_nationkey = n.n_nationkey
+);
+$join5 = (
+select
+ j.volume as volume,
+ j.l_year as l_year,
+ n.n_name as cust_nation,
+ j.n_name as supp_nation
+from
+ $join4 as j
+join
+ `{path}nation` as n
+on
+ j.c_nationkey = n.n_nationkey
+where (
+ (n.n_name = 'PERU' and j.n_name = 'MOZAMBIQUE')
+ or (n.n_name = 'MOZAMBIQUE' and j.n_name = 'PERU')
+)
+);
+
+select
+ supp_nation,
+ cust_nation,
+ l_year,
+ sum(volume) as revenue
+from
+ $join5 as shipping
+group by
+ supp_nation,
+ cust_nation,
+ l_year
+order by
+ supp_nation,
+ cust_nation,
+ l_year;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q8.sql b/ydb/library/benchmarks/queries/tpch/ydb/q8.sql
new file mode 100644
index 0000000000..b160ee8f53
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q8.sql
@@ -0,0 +1,109 @@
+-- TPC-H/TPC-R National Market Share Query (Q8)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ l.l_extendedprice * (1 - l.l_discount) as volume,
+ l.l_suppkey as l_suppkey,
+ l.l_orderkey as l_orderkey
+from
+ `{path}part` as p
+join
+ `{path}lineitem` as l
+on
+ p.p_partkey = l.l_partkey
+where
+ p.p_type = 'ECONOMY PLATED COPPER'
+);
+$join2 = (
+select
+ j.volume as volume,
+ j.l_orderkey as l_orderkey,
+ s.s_nationkey as s_nationkey
+from
+ $join1 as j
+join
+ `{path}supplier` as s
+on
+ s.s_suppkey = j.l_suppkey
+);
+$join3 = (
+select
+ j.volume as volume,
+ j.l_orderkey as l_orderkey,
+ n.n_name as nation
+from
+ $join2 as j
+join
+ `{path}nation` as n
+on
+ n.n_nationkey = j.s_nationkey
+);
+$join4 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ DateTime::GetYear(cast(o.o_orderdate as Timestamp)) as o_year,
+ o.o_custkey as o_custkey
+from
+ $join3 as j
+join
+ `{path}orders` as o
+on
+ o.o_orderkey = j.l_orderkey
+where cast(cast(o_orderdate as Timestamp) as Date) between Date('1995-01-01') and Date('1996-12-31')
+);
+$join5 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year,
+ c.c_nationkey as c_nationkey
+from
+ $join4 as j
+join
+ `{path}customer` as c
+on
+ c.c_custkey = j.o_custkey
+);
+$join6 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year,
+ n.n_regionkey as n_regionkey
+from
+ $join5 as j
+join
+ `{path}nation` as n
+on
+ n.n_nationkey = j.c_nationkey
+);
+$join7 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year
+from
+ $join6 as j
+join
+ `{path}region` as r
+on
+ r.r_regionkey = j.n_regionkey
+where
+ r.r_name = 'AFRICA'
+);
+
+select
+ o_year,
+ sum(case
+ when nation = 'MOZAMBIQUE' then volume
+ else 0
+ end) / sum(volume) as mkt_share
+from
+ $join7 as all_nations
+group by
+ o_year
+order by
+ o_year;
diff --git a/ydb/library/benchmarks/queries/tpch/ydb/q9.sql b/ydb/library/benchmarks/queries/tpch/ydb/q9.sql
new file mode 100644
index 0000000000..db930f080b
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/ydb/q9.sql
@@ -0,0 +1,58 @@
+-- TPC-H/TPC-R Product Type Profit Measure Query (Q9)
+-- Approved February 1998
+-- using 1680793381 as a seed to the RNG
+
+$p = (select p_partkey, p_name
+from
+ `{path}part`
+where FIND(p_name, 'rose') IS NOT NULL);
+
+$j1 = (select ps_partkey, ps_suppkey, ps_supplycost
+from
+ `{path}partsupp` as ps
+join $p as p
+on ps.ps_partkey = p.p_partkey);
+
+$j2 = (select l_suppkey, l_partkey, l_orderkey, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ `{path}lineitem` as l
+join $j1 as j
+on l.l_suppkey = j.ps_suppkey AND l.l_partkey = j.ps_partkey);
+
+$j3 = (select l_orderkey, s_nationkey, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ `{path}supplier` as s
+join $j2 as j
+on j.l_suppkey = s.s_suppkey);
+
+$j4 = (select o_orderdate, l_extendedprice, l_discount, ps_supplycost, l_quantity, s_nationkey
+from
+ `{path}orders` as o
+join $j3 as j
+on o.o_orderkey = j.l_orderkey);
+
+$j5 = (select n_name, o_orderdate, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ `{path}nation` as n
+join $j4 as j
+on j.s_nationkey = n.n_nationkey
+);
+
+$profit = (select
+ n_name as nation,
+ DateTime::GetYear(cast(o_orderdate as timestamp)) as o_year,
+ l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+from $j5);
+
+select
+ nation,
+ o_year,
+ sum(amount) as sum_profit
+from $profit
+group by
+ nation,
+ o_year
+order by
+ nation,
+ o_year desc;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q1.sql b/ydb/library/benchmarks/queries/tpch/yql/q1.sql
new file mode 100644
index 0000000000..ed346a5714
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q1.sql
@@ -0,0 +1,27 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Pricing Summary Report Query (Q1)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+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
+ CAST(l_shipdate AS Timestamp) <= (CAST('1998-12-01' AS Date) - Interval("P100D"))
+group by
+ l_returnflag,
+ l_linestatus
+order by
+ l_returnflag,
+ l_linestatus;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q10.sql b/ydb/library/benchmarks/queries/tpch/yql/q10.sql
new file mode 100644
index 0000000000..fbc9f01bba
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q10.sql
@@ -0,0 +1,88 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Returned Item Reporting Query (Q10)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1993-12-01");
+$join1 = (
+select
+ c.c_custkey as c_custkey,
+ c.c_name as c_name,
+ c.c_acctbal as c_acctbal,
+ c.c_address as c_address,
+ c.c_phone as c_phone,
+ c.c_comment as c_comment,
+ c.c_nationkey as c_nationkey,
+ o.o_orderkey as o_orderkey
+from
+ {{customer}} as c
+join
+ {{orders}} as o
+on
+ c.c_custkey = o.o_custkey
+where
+ cast(o.o_orderdate as timestamp) >= $border and
+ cast(o.o_orderdate as timestamp) < ($border + Interval("P90D"))
+);
+$join2 = (
+select
+ j.c_custkey as c_custkey,
+ j.c_name as c_name,
+ j.c_acctbal as c_acctbal,
+ j.c_address as c_address,
+ j.c_phone as c_phone,
+ j.c_comment as c_comment,
+ j.c_nationkey as c_nationkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_discount as l_discount
+from
+ $join1 as j
+join
+ {{lineitem}} as l
+on
+ l.l_orderkey = j.o_orderkey
+where
+ l.l_returnflag = 'R'
+);
+$join3 = (
+select
+ j.c_custkey as c_custkey,
+ j.c_name as c_name,
+ j.c_acctbal as c_acctbal,
+ j.c_address as c_address,
+ j.c_phone as c_phone,
+ j.c_comment as c_comment,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ n.n_name as n_name
+from
+ $join2 as j
+join
+ {{nation}} as n
+on
+ n.n_nationkey = j.c_nationkey
+);
+select
+ c_custkey,
+ c_name,
+ sum(l_extendedprice * (1 - l_discount)) as revenue,
+ c_acctbal,
+ n_name,
+ c_address,
+ c_phone,
+ c_comment
+from
+ $join3
+group by
+ c_custkey,
+ c_name,
+ c_acctbal,
+ c_phone,
+ n_name,
+ c_address,
+ c_comment
+order by
+ revenue desc
+limit 20;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q11.sql b/ydb/library/benchmarks/queries/tpch/yql/q11.sql
new file mode 100644
index 0000000000..ed9dd98ed9
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q11.sql
@@ -0,0 +1,64 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Important Stock Identification Query (Q11)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+PRAGMA dq.EnableDqReplicate = "1";
+PRAGMA DisableSimpleColumns;
+
+$join1 = (
+select
+ ps.ps_partkey as ps_partkey,
+ ps.ps_supplycost as ps_supplycost,
+ ps.ps_availqty as ps_availqty,
+ s.s_nationkey as s_nationkey
+from
+ {{partsupp}} as ps
+join
+ {{supplier}} as s
+on
+ ps.ps_suppkey = s.s_suppkey
+);
+$join2 = (
+select
+ j.ps_partkey as ps_partkey,
+ j.ps_supplycost as ps_supplycost,
+ j.ps_availqty as ps_availqty,
+ j.s_nationkey as s_nationkey
+from
+ $join1 as j
+join
+ {{nation}} as n
+on
+ n.n_nationkey = j.s_nationkey
+where
+ n.n_name = 'CANADA'
+);
+$threshold = (
+select
+ sum(ps_supplycost * ps_availqty) * 0.0001000000 as threshold
+from
+ $join2
+);
+$values = (
+select
+ ps_partkey,
+ sum(ps_supplycost * ps_availqty) as value
+from
+ $join2
+group by
+ ps_partkey
+);
+
+select
+ v.ps_partkey as ps_partkey,
+ v.value as value
+from
+ $values as v
+cross join
+ $threshold as t
+where
+ v.value > t.threshold
+order by
+ value desc;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q12.sql b/ydb/library/benchmarks/queries/tpch/yql/q12.sql
new file mode 100644
index 0000000000..1903a1d410
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q12.sql
@@ -0,0 +1,46 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Shipping Modes and Order Priority Query (Q12)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join = (
+ select
+ l.l_shipmode as l_shipmode,
+ o.o_orderpriority as o_orderpriority,
+ l.l_commitdate as l_commitdate,
+ l.l_shipdate as l_shipdate,
+ l.l_receiptdate as l_receiptdate
+ from
+ {{orders}} as o
+ join {{lineitem}} as l
+ on o.o_orderkey == l.l_orderkey
+);
+
+$border = Date("1994-01-01");
+
+select
+ l_shipmode,
+ sum(case
+ when o_orderpriority = '1-URGENT'
+ or o_orderpriority = '2-HIGH'
+ then 1
+ else 0
+ end) as high_line_count,
+ sum(case
+ when o_orderpriority <> '1-URGENT'
+ and o_orderpriority <> '2-HIGH'
+ then 1
+ else 0
+ end) as low_line_count
+from $join
+where
+ (l_shipmode = 'MAIL' or l_shipmode = 'TRUCK')
+ and l_commitdate < l_receiptdate
+ and l_shipdate < l_commitdate
+ and cast(l_receiptdate as timestamp) >= $border
+ and cast(l_receiptdate as timestamp) < ($border + Interval("P365D"))
+group by
+ l_shipmode
+order by
+ l_shipmode;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q13.sql b/ydb/library/benchmarks/queries/tpch/yql/q13.sql
new file mode 100644
index 0000000000..f40dbf0379
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q13.sql
@@ -0,0 +1,34 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Customer Distribution Query (Q13)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$orders = (
+ select
+ o_orderkey,
+ o_custkey
+ from
+ {{orders}}
+ where
+ o_comment NOT LIKE "%unusual%requests%"
+);
+select
+ c_count as c_count,
+ count(*) as custdist
+from
+ (
+ select
+ c.c_custkey as c_custkey,
+ count(o.o_orderkey) as c_count
+ from
+ {{customer}} as c left outer join $orders as o on
+ c.c_custkey = o.o_custkey
+ group by
+ c.c_custkey
+ ) as c_orders
+group by
+ c_count
+order by
+ custdist desc,
+ c_count desc;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q14.sql b/ydb/library/benchmarks/queries/tpch/yql/q14.sql
new file mode 100644
index 0000000000..3514333443
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q14.sql
@@ -0,0 +1,22 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Promotion Effect Query (Q14)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1994-08-01");
+select
+ 100.00 * sum(case
+ when StartsWith(p.p_type, 'PROMO')
+ then l.l_extendedprice * (1 - l.l_discount)
+ else 0
+ end) / sum(l.l_extendedprice * (1 - l.l_discount)) as promo_revenue
+from
+ {{lineitem}} as l
+join
+ {{part}} as p
+on
+ l.l_partkey = p.p_partkey
+where
+ cast(l.l_shipdate as timestamp) >= $border
+ and cast(l.l_shipdate as timestamp) < ($border + Interval("P31D"));
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q15.sql b/ydb/library/benchmarks/queries/tpch/yql/q15.sql
new file mode 100644
index 0000000000..68cb06f92b
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q15.sql
@@ -0,0 +1,57 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Top Supplier Query (Q15)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1997-03-01");
+$revenue0 = (
+ select
+ l_suppkey as supplier_no,
+ sum(l_extendedprice * (1 - l_discount)) as total_revenue,
+ cast(sum(l_extendedprice * (1 - l_discount)) as Uint64) as total_revenue_approx
+ from
+ {{lineitem}}
+ where
+ cast(l_shipdate as timestamp) >= $border
+ and cast(l_shipdate as timestamp) < ($border + Interval("P92D"))
+ group by
+ l_suppkey
+);
+$max_revenue = (
+select
+ max(total_revenue_approx) as max_revenue
+from
+ $revenue0
+);
+$join1 = (
+select
+ s.s_suppkey as s_suppkey,
+ s.s_name as s_name,
+ s.s_address as s_address,
+ s.s_phone as s_phone,
+ r.total_revenue as total_revenue,
+ r.total_revenue_approx as total_revenue_approx
+from
+ {{supplier}} as s
+join
+ $revenue0 as r
+on
+ s.s_suppkey = r.supplier_no
+);
+
+select
+ j.s_suppkey as s_suppkey,
+ j.s_name as s_name,
+ j.s_address as s_address,
+ j.s_phone as s_phone,
+ j.total_revenue as total_revenue
+from
+ $join1 as j
+join
+ $max_revenue as m
+on
+ j.total_revenue_approx = m.max_revenue
+order by
+ s_suppkey;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q16.sql b/ydb/library/benchmarks/queries/tpch/yql/q16.sql
new file mode 100644
index 0000000000..087a89bee2
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q16.sql
@@ -0,0 +1,45 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Parts/Supplier Relationship Query (Q16)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join = (
+select
+ ps.ps_suppkey as ps_suppkey,
+ ps.ps_partkey as ps_partkey
+from
+ {{partsupp}} as ps
+left join
+ {{supplier}} as w
+on
+ w.s_suppkey = ps.ps_suppkey
+where not (s_comment like "%Customer%Complaints%")
+);
+
+select
+ p.p_brand as p_brand,
+ p.p_type as p_type,
+ p.p_size as p_size,
+ count(distinct j.ps_suppkey) as supplier_cnt
+from
+ $join as j
+join
+ {{part}} as p
+on
+ p.p_partkey = j.ps_partkey
+where
+ p.p_brand <> 'Brand#33'
+ and (not StartsWith(p.p_type, 'PROMO POLISHED'))
+ 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)
+group by
+ p.p_brand,
+ p.p_type,
+ p.p_size
+order by
+ supplier_cnt desc,
+ p_brand,
+ p_type,
+ p_size
+;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q17.sql b/ydb/library/benchmarks/queries/tpch/yql/q17.sql
new file mode 100644
index 0000000000..33eb2f8b5a
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q17.sql
@@ -0,0 +1,42 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Small-Quantity-Order Revenue Query (Q17)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$threshold = (
+select
+ 0.2 * avg(l_quantity) as threshold,
+ l_partkey
+from
+ {{lineitem}}
+group by
+ l_partkey
+);
+
+$join1 = (
+select
+ p.p_partkey as p_partkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_quantity as l_quantity
+from
+ {{lineitem}} as l
+join
+ {{part}} as p
+on
+ p.p_partkey = l.l_partkey
+where
+ p.p_brand = 'Brand#35'
+ and p.p_container = 'LG DRUM'
+);
+
+select
+ sum(j.l_extendedprice) / 7.0 as avg_yearly
+from
+ $join1 as j
+join
+ $threshold as t
+on
+ j.p_partkey = t.l_partkey
+where
+ j.l_quantity < t.threshold;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q18.sql b/ydb/library/benchmarks/queries/tpch/yql/q18.sql
new file mode 100644
index 0000000000..2c28abbb3a
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q18.sql
@@ -0,0 +1,54 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Large Volume Customer Query (Q18)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$in = (
+select
+ l_orderkey,
+ sum(l_quantity) as sum_l_quantity
+from
+ {{lineitem}}
+group by
+ l_orderkey having
+ sum(l_quantity) > 315
+);
+
+$join1 = (
+select
+ c.c_name as c_name,
+ c.c_custkey as c_custkey,
+ o.o_orderkey as o_orderkey,
+ o.o_orderdate as o_orderdate,
+ o.o_totalprice as o_totalprice
+from
+ {{customer}} as c
+join
+ {{orders}} as o
+on
+ c.c_custkey = o.o_custkey
+);
+select
+ j.c_name as c_name,
+ j.c_custkey as c_custkey,
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.o_totalprice as o_totalprice,
+ sum(i.sum_l_quantity) as sum_l_quantity
+from
+ $join1 as j
+join
+ $in as i
+on
+ i.l_orderkey = j.o_orderkey
+group by
+ j.c_name,
+ j.c_custkey,
+ j.o_orderkey,
+ j.o_orderdate,
+ j.o_totalprice
+order by
+ o_totalprice desc,
+ o_orderdate
+limit 100;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q19.sql b/ydb/library/benchmarks/queries/tpch/yql/q19.sql
new file mode 100644
index 0000000000..ee73ef04cf
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q19.sql
@@ -0,0 +1,41 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Discounted Revenue Query (Q19)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+select
+ sum(l.l_extendedprice* (1 - l.l_discount)) as revenue
+from
+ {{lineitem}} as l
+join
+ {{part}} as p
+on
+ p.p_partkey = l.l_partkey
+where
+ (
+ p.p_brand = 'Brand#23'
+ and (p.p_container = 'SM CASE' or p.p_container = 'SM BOX' or p.p_container = 'SM PACK' or p.p_container = 'SM PKG')
+ and l.l_quantity >= 7 and l.l_quantity <= 7 + 10
+ and p.p_size between 1 and 5
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ )
+ or
+ (
+ p.p_brand = 'Brand#15'
+ and (p.p_container = 'MED BAG' or p.p_container = 'MED BOX' or p.p_container = 'MED PKG' or p.p_container = 'MED PACK')
+ and l.l_quantity >= 17 and l.l_quantity <= 17 + 10
+ and p.p_size between 1 and 10
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ )
+ or
+ (
+ p.p_brand = 'Brand#44'
+ and (p.p_container = 'LG CASE' or p.p_container = 'LG BOX' or p.p_container = 'LG PACK' or p.p_container = 'LG PKG')
+ and l.l_quantity >= 25 and l.l_quantity <= 25 + 10
+ and p.p_size between 1 and 15
+ and (l.l_shipmode = 'AIR' or l.l_shipmode = 'AIR REG')
+ and l.l_shipinstruct = 'DELIVER IN PERSON'
+ );
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q2.sql b/ydb/library/benchmarks/queries/tpch/yql/q2.sql
new file mode 100644
index 0000000000..5e228fd84a
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q2.sql
@@ -0,0 +1,69 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Minimum Cost Supplier Query (Q2)
+-- using 1680793381 as a seed to the RNG
+
+$r = (select r_regionkey from
+ {{region}}
+where r_name='AMERICA');
+
+$j1 = (select n_name,n_nationkey
+ from {{nation}} as n
+ join $r as r on
+ n.n_regionkey = r.r_regionkey);
+
+$j2 = (select s_acctbal,s_name,s_address,s_phone,s_comment,n_name,s_suppkey
+ from {{supplier}} as s
+ join $j1 as j on
+ s.s_nationkey = j.n_nationkey
+);
+
+$j3 = (select ps_partkey,ps_supplycost,s_acctbal,s_name,s_address,s_phone,s_comment,n_name
+ from {{partsupp}} as ps
+ join $j2 as j on
+ ps.ps_suppkey = j.s_suppkey
+);
+
+$min_ps_supplycost = (select min(ps_supplycost) as min_ps_supplycost,ps_partkey
+ from $j3
+ group by ps_partkey
+);
+
+$p = (select p_partkey,p_mfgr
+ from {{part}}
+ where
+ p_size = 10
+ and p_type like '%COPPER'
+);
+
+$j4 = (select s_acctbal,
+ s_name,
+ n_name,
+ p_partkey,
+ p_mfgr,
+ s_address,
+ s_phone,
+ s_comment
+ from $p as p
+ join $j3 as j on p.p_partkey = j.ps_partkey
+ join $min_ps_supplycost as m on p.p_partkey = m.ps_partkey
+ where min_ps_supplycost=ps_supplycost
+);
+
+select
+ s_acctbal,
+ s_name,
+ n_name,
+ p_partkey,
+ p_mfgr,
+ s_address,
+ s_phone,
+ s_comment
+from $j4
+order by
+ s_acctbal desc,
+ n_name,
+ s_name,
+ p_partkey
+limit 100;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q20.sql b/ydb/library/benchmarks/queries/tpch/yql/q20.sql
new file mode 100644
index 0000000000..11553a460a
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q20.sql
@@ -0,0 +1,84 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Potential Part Promotion Query (Q20)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1993-01-01");
+$threshold = (
+select
+ 0.5 * sum(l_quantity) as threshold,
+ l_partkey as l_partkey,
+ l_suppkey as l_suppkey
+from
+ {{lineitem}}
+where
+ cast(l_shipdate as timestamp) >= $border
+ and cast(l_shipdate as timestamp) < ($border + Interval("P365D"))
+group by
+ l_partkey, l_suppkey
+);
+
+$parts = (
+select
+ p_partkey
+from
+ {{part}}
+where
+ StartsWith(p_name, 'maroon')
+);
+
+$join1 = (
+select
+ ps.ps_suppkey as ps_suppkey,
+ ps.ps_availqty as ps_availqty,
+ ps.ps_partkey as ps_partkey
+from
+ {{partsupp}} as ps
+join any
+ $parts as p
+on
+ ps.ps_partkey = p.p_partkey
+);
+
+$join2 = (
+select
+ distinct(j.ps_suppkey) as ps_suppkey
+from
+ $join1 as j
+join any
+ $threshold as t
+on
+ j.ps_partkey = t.l_partkey and j.ps_suppkey = t.l_suppkey
+where
+ j.ps_availqty > t.threshold
+);
+
+$join3 = (
+select
+ j.ps_suppkey as ps_suppkey,
+ s.s_name as s_name,
+ s.s_address as s_address,
+ s.s_nationkey as s_nationkey
+from
+ $join2 as j
+join any
+ {{supplier}} as s
+on
+ j.ps_suppkey = s.s_suppkey
+);
+
+select
+ j.s_name as s_name,
+ j.s_address as s_address
+from
+ $join3 as j
+join
+ {{nation}} as n
+on
+ j.s_nationkey = n.n_nationkey
+where
+ n.n_name = 'VIETNAM'
+order by
+ s_name;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q21.sql b/ydb/library/benchmarks/queries/tpch/yql/q21.sql
new file mode 100644
index 0000000000..4f79a94c83
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q21.sql
@@ -0,0 +1,88 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Suppliers Who Kept Orders Waiting Query (Q21)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$exists = (
+ select
+ COUNT(*) > 0 as result,
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ {{lineitem}} as l1
+ join
+ {{lineitem}} as l2
+ on
+ l2.l_orderkey = l1.l_orderkey
+ where
+ l2.l_suppkey <> l1.l_suppkey
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+$not_exists_inverse = (
+ select
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ {{lineitem}} as l1
+ join
+ {{lineitem}} as l3
+ on
+ l3.l_orderkey = l1.l_orderkey
+ where
+ l3.l_suppkey <> l1.l_suppkey
+ and l3.l_receiptdate > l3.l_commitdate
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+$not_exists = (
+ select
+ l1.l_orderkey as l_orderkey,
+ l1.l_suppkey as l_suppkey
+ from
+ {{lineitem}} as l1
+ left only join
+ $not_exists_inverse AS nei
+ on
+ nei.l_orderkey = l1.l_orderkey and
+ nei.l_suppkey = l1.l_suppkey
+ group by
+ l1.l_orderkey, l1.l_suppkey
+);
+
+select
+ s.s_name as s_name,
+ count(*) as numwait
+from
+ {{supplier}} as s
+join
+ {{lineitem}} as l1
+on
+ s.s_suppkey = l1.l_suppkey
+join
+ {{orders}} as o
+on
+ o.o_orderkey = l1.l_orderkey
+join
+ {{nation}} as n
+on
+ s.s_nationkey = n.n_nationkey
+join
+ $exists as e
+ on e.l_orderkey == l1.l_orderkey and
+ e.l_suppkey == l1.l_suppkey
+join
+ $not_exists as ne
+ on ne.l_orderkey == l1.l_orderkey and
+ ne.l_suppkey == l1.l_suppkey
+where
+ o.o_orderstatus = 'F'
+ and l1.l_receiptdate > l1.l_commitdate
+ and n.n_name = 'EGYPT'
+group by
+ s.s_name
+order by
+ numwait desc,
+ s_name
+limit 100;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q22.sql b/ydb/library/benchmarks/queries/tpch/yql/q22.sql
new file mode 100644
index 0000000000..02fe5379f4
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q22.sql
@@ -0,0 +1,59 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Global Sales Opportunity Query (Q22)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$customers = (
+select
+ c_acctbal,
+ c_custkey,
+ Substring(c_phone, 0u, 2u) as cntrycode
+from
+ {{customer}}
+where (Substring(c_phone, 0u, 2u) = '31' or Substring(c_phone, 0u, 2u) = '29' or Substring(c_phone, 0u, 2u) = '30' or Substring(c_phone, 0u, 2u) = '26' or Substring(c_phone, 0u, 2u) = '28' or Substring(c_phone, 0u, 2u) = '25' or Substring(c_phone, 0u, 2u) = '15')
+);
+$avg = (
+select
+ avg(c_acctbal) as a
+from
+ $customers
+where
+ c_acctbal > 0.00
+);
+$join1 = (
+select
+ c.c_acctbal as c_acctbal,
+ c.c_custkey as c_custkey,
+ c.cntrycode as cntrycode
+from
+ $customers as c
+cross join
+ $avg as a
+where
+ c.c_acctbal > a.a
+);
+$join2 = (
+select
+ j.cntrycode as cntrycode,
+ c_custkey,
+ j.c_acctbal as c_acctbal
+from
+ $join1 as j
+left only join
+ {{orders}} as o
+on
+ o.o_custkey = j.c_custkey
+);
+
+select
+ cntrycode,
+ count(*) as numcust,
+ sum(c_acctbal) as totacctbal
+from
+ $join2 as custsale
+group by
+ cntrycode
+order by
+ cntrycode;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q3.sql b/ydb/library/benchmarks/queries/tpch/yql/q3.sql
new file mode 100644
index 0000000000..ec3ac17307
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q3.sql
@@ -0,0 +1,56 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Shipping Priority Query (Q3)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ c.c_mktsegment as c_mktsegment,
+ o.o_orderdate as o_orderdate,
+ o.o_shippriority as o_shippriority,
+ o.o_orderkey as o_orderkey
+from
+ {{customer}} as c
+join
+ {{orders}} as o
+on
+ c.c_custkey = o.o_custkey
+);
+
+$join2 = (
+select
+ j1.c_mktsegment as c_mktsegment,
+ j1.o_orderdate as o_orderdate,
+ j1.o_shippriority as o_shippriority,
+ l.l_orderkey as l_orderkey,
+ l.l_discount as l_discount,
+ l.l_shipdate as l_shipdate,
+ l.l_extendedprice as l_extendedprice
+from
+ $join1 as j1
+join
+ {{lineitem}} as l
+on
+ l.l_orderkey = j1.o_orderkey
+);
+
+select
+ l_orderkey,
+ sum(l_extendedprice * (1 - l_discount)) as revenue,
+ o_orderdate,
+ o_shippriority
+from
+ $join2
+where
+ c_mktsegment = 'MACHINERY'
+ and CAST(o_orderdate AS Timestamp) < Date('1995-03-08')
+ and CAST(l_shipdate AS Timestamp) > Date('1995-03-08')
+group by
+ l_orderkey,
+ o_orderdate,
+ o_shippriority
+order by
+ revenue desc,
+ o_orderdate
+limit 10;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q4.sql b/ydb/library/benchmarks/queries/tpch/yql/q4.sql
new file mode 100644
index 0000000000..c265ce4f08
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q4.sql
@@ -0,0 +1,30 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Order Priority Checking Query (Q4)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1994-03-01");
+
+$join = (select
+ o.o_orderpriority as o_orderpriority,
+ o.o_orderdate as o_orderdate,
+ l.l_commitdate as l_commitdate,
+ l.l_receiptdate as l_receiptdate
+ from
+ {{orders}} as o
+ join any {{lineitem}} as l
+ on o.o_orderkey = l.l_orderkey);
+
+select
+ o_orderpriority,
+ count(*) as order_count
+from $join
+where
+ CAST(o_orderdate AS Timestamp) >= $border
+ and CAST(o_orderdate AS Timestamp) < DateTime::MakeDate(DateTime::ShiftMonths($border, 3))
+ and l_commitdate < l_receiptdate
+group by
+ o_orderpriority
+order by
+ o_orderpriority;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q5.sql b/ydb/library/benchmarks/queries/tpch/yql/q5.sql
new file mode 100644
index 0000000000..81483caa8a
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q5.sql
@@ -0,0 +1,103 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Local Supplier Volume Query (Q5)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ o.o_orderkey as o_orderkey,
+ o.o_orderdate as o_orderdate,
+ c.c_nationkey as c_nationkey
+from
+ {{customer}} as c
+join
+ {{orders}} as o
+on
+ c.c_custkey = o.o_custkey
+);
+
+$join2 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ l.l_extendedprice as l_extendedprice,
+ l.l_discount as l_discount,
+ l.l_suppkey as l_suppkey
+from
+ $join1 as j
+join
+ {{lineitem}} as l
+on
+ l.l_orderkey = j.o_orderkey
+);
+
+$join3 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ s.s_nationkey as s_nationkey
+from
+ $join2 as j
+join
+ {{supplier}} as s
+on
+ j.l_suppkey = s.s_suppkey
+);
+$join4 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ j.s_nationkey as s_nationkey,
+ n.n_regionkey as n_regionkey,
+ n.n_name as n_name
+from
+ $join3 as j
+join
+ {{nation}} as n
+on
+ j.s_nationkey = n.n_nationkey
+ and j.c_nationkey = n.n_nationkey
+);
+$join5 = (
+select
+ j.o_orderkey as o_orderkey,
+ j.o_orderdate as o_orderdate,
+ j.c_nationkey as c_nationkey,
+ j.l_extendedprice as l_extendedprice,
+ j.l_discount as l_discount,
+ j.l_suppkey as l_suppkey,
+ j.s_nationkey as s_nationkey,
+ j.n_regionkey as n_regionkey,
+ j.n_name as n_name,
+ r.r_name as r_name
+from
+ $join4 as j
+join
+ {{region}} as r
+on
+ j.n_regionkey = r.r_regionkey
+);
+$border = Date("1995-01-01");
+select
+ n_name,
+ sum(l_extendedprice * (1 - l_discount)) as revenue
+from
+ $join5
+where
+ r_name = 'AFRICA'
+ and CAST(o_orderdate AS Timestamp) >= $border
+ and CAST(o_orderdate AS Timestamp) < ($border + Interval("P365D"))
+group by
+ n_name
+order by
+ revenue desc;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q6.sql b/ydb/library/benchmarks/queries/tpch/yql/q6.sql
new file mode 100644
index 0000000000..38a07b7124
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q6.sql
@@ -0,0 +1,17 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Forecasting Revenue Change Query (Q6)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$border = Date("1995-01-01");
+
+select
+ sum(l_extendedprice * l_discount) as revenue
+from
+ {{lineitem}}
+where
+ CAST(l_shipdate AS Timestamp) >= $border
+ and cast(l_shipdate as Timestamp) < ($border + Interval("P365D"))
+ and l_discount between 0.07 - 0.01 and 0.07 + 0.01
+ and l_quantity < 25;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q7.sql b/ydb/library/benchmarks/queries/tpch/yql/q7.sql
new file mode 100644
index 0000000000..988b343fc7
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q7.sql
@@ -0,0 +1,88 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Volume Shipping Query (Q7)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$n = select n_name, n_nationkey from {{nation}} as n
+ where n_name = 'PERU' or n_name = 'MOZAMBIQUE';
+
+$l = select
+ l_orderkey, l_suppkey,
+ DateTime::GetYear(cast(l_shipdate as timestamp)) as l_year,
+ l_extendedprice * (1 - l_discount) as volume
+from
+ {{lineitem}} as l
+where
+ cast(cast(l.l_shipdate as Timestamp) as Date)
+ between Date('1995-01-01') and Date('1996-12-31');
+
+$j1 = select
+ n_name as supp_nation,
+ s_suppkey
+from
+ {{supplier}} as supplier
+join
+ $n as n1
+on
+ supplier.s_nationkey = n1.n_nationkey;
+
+$j2 = select
+ n_name as cust_nation,
+ c_custkey
+from
+ {{customer}} as customer
+join
+ $n as n2
+on
+ customer.c_nationkey = n2.n_nationkey;
+
+$j3 = select
+ cust_nation, o_orderkey
+from
+ {{orders}} as orders
+join
+ $j2 as customer
+on
+ orders.o_custkey = customer.c_custkey;
+
+$j4 = select
+ cust_nation,
+ l_orderkey, l_suppkey,
+ l_year,
+ volume
+from
+ $l as lineitem
+join
+ $j3 as orders
+on
+ lineitem.l_orderkey = orders.o_orderkey;
+
+$j5 = select
+ supp_nation, cust_nation,
+ l_year, volume
+from
+ $j4 as lineitem
+join
+ $j1 as supplier
+on
+ lineitem.l_suppkey = supplier.s_suppkey
+where (supp_nation = 'PERU' and cust_nation = 'MOZAMBIQUE')
+ OR (supp_nation = 'MOZAMBIQUE' and cust_nation = 'PERU');
+
+select
+ supp_nation,
+ cust_nation,
+ l_year,
+ sum(volume) as revenue
+from
+ $j5 as shipping
+group by
+ supp_nation,
+ cust_nation,
+ l_year
+order by
+ supp_nation,
+ cust_nation,
+ l_year;
+
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q8.sql b/ydb/library/benchmarks/queries/tpch/yql/q8.sql
new file mode 100644
index 0000000000..2dd9884416
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q8.sql
@@ -0,0 +1,111 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R National Market Share Query (Q8)
+-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
+-- using 1680793381 as a seed to the RNG
+
+$join1 = (
+select
+ l.l_extendedprice * (1 - l.l_discount) as volume,
+ l.l_suppkey as l_suppkey,
+ l.l_orderkey as l_orderkey
+from
+ {{part}} as p
+join
+ {{lineitem}} as l
+on
+ p.p_partkey = l.l_partkey
+where
+ p.p_type = 'ECONOMY PLATED COPPER'
+);
+$join2 = (
+select
+ j.volume as volume,
+ j.l_orderkey as l_orderkey,
+ s.s_nationkey as s_nationkey
+from
+ $join1 as j
+join
+ {{supplier}} as s
+on
+ s.s_suppkey = j.l_suppkey
+);
+$join3 = (
+select
+ j.volume as volume,
+ j.l_orderkey as l_orderkey,
+ n.n_name as nation
+from
+ $join2 as j
+join
+ {{nation}} as n
+on
+ n.n_nationkey = j.s_nationkey
+);
+$join4 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ DateTime::GetYear(cast(o.o_orderdate as Timestamp)) as o_year,
+ o.o_custkey as o_custkey
+from
+ $join3 as j
+join
+ {{orders}} as o
+on
+ o.o_orderkey = j.l_orderkey
+where cast(cast(o_orderdate as Timestamp) as Date) between Date('1995-01-01') and Date('1996-12-31')
+);
+$join5 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year,
+ c.c_nationkey as c_nationkey
+from
+ $join4 as j
+join
+ {{customer}} as c
+on
+ c.c_custkey = j.o_custkey
+);
+$join6 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year,
+ n.n_regionkey as n_regionkey
+from
+ $join5 as j
+join
+ {{nation}} as n
+on
+ n.n_nationkey = j.c_nationkey
+);
+$join7 = (
+select
+ j.volume as volume,
+ j.nation as nation,
+ j.o_year as o_year
+from
+ $join6 as j
+join
+ {{region}} as r
+on
+ r.r_regionkey = j.n_regionkey
+where
+ r.r_name = 'AFRICA'
+);
+
+select
+ o_year,
+ sum(case
+ when nation = 'MOZAMBIQUE' then volume
+ else 0
+ end) / sum(volume) as mkt_share
+from
+ $join7 as all_nations
+group by
+ o_year
+order by
+ o_year;
diff --git a/ydb/library/benchmarks/queries/tpch/yql/q9.sql b/ydb/library/benchmarks/queries/tpch/yql/q9.sql
new file mode 100644
index 0000000000..5533c85bd0
--- /dev/null
+++ b/ydb/library/benchmarks/queries/tpch/yql/q9.sql
@@ -0,0 +1,60 @@
+{% include 'header.sql.jinja' %}
+
+-- TPC-H/TPC-R Product Type Profit Measure Query (Q9)
+-- Approved February 1998
+-- using 1680793381 as a seed to the RNG
+
+$p = (select p_partkey, p_name
+from
+ {{part}}
+where FIND(p_name, 'rose') IS NOT NULL);
+
+$j1 = (select ps_partkey, ps_suppkey, ps_supplycost
+from
+ {{partsupp}} as ps
+join $p as p
+on ps.ps_partkey = p.p_partkey);
+
+$j2 = (select l_suppkey, l_partkey, l_orderkey, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ {{lineitem}} as l
+join $j1 as j
+on l.l_suppkey = j.ps_suppkey AND l.l_partkey = j.ps_partkey);
+
+$j3 = (select l_orderkey, s_nationkey, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ {{supplier}} as s
+join $j2 as j
+on j.l_suppkey = s.s_suppkey);
+
+$j4 = (select o_orderdate, l_extendedprice, l_discount, ps_supplycost, l_quantity, s_nationkey
+from
+ {{orders}} as o
+join $j3 as j
+on o.o_orderkey = j.l_orderkey);
+
+$j5 = (select n_name, o_orderdate, l_extendedprice, l_discount, ps_supplycost, l_quantity
+from
+ {{nation}} as n
+join $j4 as j
+on j.s_nationkey = n.n_nationkey
+);
+
+$profit = (select
+ n_name as nation,
+ DateTime::GetYear(cast(o_orderdate as timestamp)) as o_year,
+ l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount
+from $j5);
+
+select
+ nation,
+ o_year,
+ sum(amount) as sum_profit
+from $profit
+group by
+ nation,
+ o_year
+order by
+ nation,
+ o_year desc;
+