1#include "benchmark_runner.hpp"
2#include "compare_result.hpp"
3#include "dbgen.hpp"
4#include "duckdb_benchmark_macro.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9#define SF 1
10
11DUCKDB_BENCHMARK(LineitemSimpleAggregate, "[aggregate]")
12void Load(DuckDBBenchmarkState *state) override {
13 // load the data into the tpch schema
14 tpch::dbgen(SF, state->db);
15}
16string GetQuery() override {
17 return "SELECT SUM(l_quantity) FROM lineitem";
18}
19string VerifyResult(QueryResult *result) override {
20 if (!result->success) {
21 return result->error;
22 }
23 return string();
24}
25string BenchmarkInfo() override {
26 return "Execute the query \"SELECT SUM(l_quantity) FROM lineitem\" on SF1";
27}
28FINISH_BENCHMARK(LineitemSimpleAggregate)
29
30DUCKDB_BENCHMARK(LineitemCount, "[aggregate]")
31void Load(DuckDBBenchmarkState *state) override {
32 // load the data into the tpch schema
33 tpch::dbgen(SF, state->db);
34}
35string GetQuery() override {
36 return "SELECT COUNT(*) FROM lineitem";
37}
38string VerifyResult(QueryResult *result) override {
39 if (!result->success) {
40 return result->error;
41 }
42 return string();
43}
44string BenchmarkInfo() override {
45 return "Execute the query \"SELECT COUNT(*) FROM lineitem\" on SF1";
46}
47FINISH_BENCHMARK(LineitemCount)
48
49DUCKDB_BENCHMARK(LineitemGroupAggregate, "[aggregate]")
50void Load(DuckDBBenchmarkState *state) override {
51 // load the data into the tpch schema
52 tpch::dbgen(SF, state->db);
53}
54string GetQuery() override {
55 return "SELECT l_quantity, SUM(l_quantity) FROM lineitem GROUP BY l_quantity";
56}
57string VerifyResult(QueryResult *result) override {
58 if (!result->success) {
59 return result->error;
60 }
61 return string();
62}
63string BenchmarkInfo() override {
64 return "Execute the query \"SELECT l_quantity, SUM(l_quantity) FROM lineitem GROUP BY l_quantity\" on SF1";
65}
66FINISH_BENCHMARK(LineitemGroupAggregate)
67
68DUCKDB_BENCHMARK(LineitemGroupStringAggregate, "[aggregate]")
69void Load(DuckDBBenchmarkState *state) override {
70 // load the data into the tpch schema
71 tpch::dbgen(SF, state->db);
72}
73string GetQuery() override {
74 return "SELECT SUM(l_quantity) FROM lineitem GROUP BY l_returnflag";
75}
76string VerifyResult(QueryResult *result) override {
77 if (!result->success) {
78 return result->error;
79 }
80 return string();
81}
82string BenchmarkInfo() override {
83 return "Execute the query \"SELECT SUM(l_quantity) FROM lineitem GROUP BY l_returnflag\" on SF1";
84}
85FINISH_BENCHMARK(LineitemGroupStringAggregate)
86
87DUCKDB_BENCHMARK(LineitemJoinAggregate, "[aggregate]")
88void Load(DuckDBBenchmarkState *state) override {
89 // load the data into the tpch schema
90 tpch::dbgen(SF, state->db);
91}
92string GetQuery() override {
93 return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, "
94 "sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + "
95 "l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS "
96 "avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey GROUP BY l_returnflag, "
97 "l_linestatus ORDER BY l_returnflag, l_linestatus";
98}
99string VerifyResult(QueryResult *result) override {
100 if (!result->success) {
101 return result->error;
102 }
103 return string();
104}
105string BenchmarkInfo() override {
106 return "Execute the query \"" + GetQuery() + "\" on SF1";
107}
108FINISH_BENCHMARK(LineitemJoinAggregate)
109
110DUCKDB_BENCHMARK(LineitemJoinAggregateWithFilter, "[aggregate]")
111void Load(DuckDBBenchmarkState *state) override {
112 // load the data into the tpch schema
113 tpch::dbgen(SF, state->db);
114}
115string GetQuery() override {
116 return "SELECT l_returnflag, l_linestatus, sum(l_quantity) AS sum_qty, sum(l_extendedprice) AS sum_base_price, "
117 "sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, sum(l_extendedprice * (1 - l_discount) * (1 + "
118 "l_tax)) AS sum_charge, avg(l_quantity) AS avg_qty, avg(l_extendedprice) AS avg_price, avg(l_discount) AS "
119 "avg_disc, count(*) AS count_order FROM lineitem, orders WHERE l_orderkey=o_orderkey AND l_shipdate <= "
120 "cast('1998-09-02' AS date) GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus";
121}
122string VerifyResult(QueryResult *result) override {
123 if (!result->success) {
124 return result->error;
125 }
126 return string();
127}
128string BenchmarkInfo() override {
129 return "Execute the query \"" + GetQuery() + "\" on SF1";
130}
131FINISH_BENCHMARK(LineitemJoinAggregateWithFilter)
132
133DUCKDB_BENCHMARK(TPCHQ1IntKeys, "[aggregate]")
134void Load(DuckDBBenchmarkState *state) override {
135 // load the data into the tpch schema
136 tpch::dbgen(SF, state->db, DEFAULT_SCHEMA, "_normal");
137 Connection conn(state->db);
138 conn.Query("CREATE TABLE lineitem AS select l_orderkey, l_partkey, l_suppkey, l_linenumber, l_quantity, "
139 "l_extendedprice, l_discount, l_tax, case l_returnflag when 'N' then 0 when 'R' then 1 when 'A' "
140 "then 2 else NULL end l_returnflag, case l_linestatus when 'F' then 0 when 'O' then 1 else NULL end "
141 "l_linestatus, l_shipdate, l_commitdate, l_receiptdate, l_shipinstruct, l_shipmode, "
142 "l_comment from lineitem_normal");
143}
144string GetQuery() override {
145 return tpch::get_query(1);
146}
147string VerifyResult(QueryResult *result) override {
148 if (!result->success) {
149 return result->error;
150 }
151 return string();
152}
153string BenchmarkInfo() override {
154 return "Execute the query \"" + GetQuery() + "\" on SF1";
155}
156FINISH_BENCHMARK(TPCHQ1IntKeys)
157