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 0.2
10
11string getQuery(int queryID) {
12
13 string queries[42] = {
14 "l_quantity <= 1 + 10", // H0, BOUND_COMPARISON, COMPARE_LESSTHANOREQUALTO
15 "l_shipdate > date '1992-01-01'", // H1, BOUND_COMPARISON, COMPARE_GREATERTHAN
16 "l_receiptdate >= l_commitdate", // H2, BOUND_COMPARISON, COMPARE_GREATERTHANOREQUALTO
17 "l_shipinstruct < l_comment", // H3, BOUND_COMPARISON,
18
19 "l_commitdate = l_receiptdate", // H4, BOUND_COMPARISON, COMPARE_EQUAL
20 "l_orderkey != 0", // H5, BOUND_COMPARISON, COMPARE_NOTEQUAL
21 "l_discount = 1.0", // H6, BOUND_COMPARISON, COMPARE_EQUAL
22 "l_returnflag = 'R'", // H7, BOUND_COMPARISON, COMPARE_EQUAL
23 "l_shipinstruct != 'DELIVER IN PERSON'", // H8, BOUND_COMPARISON, COMPARE_NOTEQUAL
24
25 "l_returnflag IS NOT NULL", // H9, BOUND_OPERATOR, OPERATOR_IS_NOT_NULL
26 "l_quantity IS NULL", // H10, BOUND_OPERATOR,
27
28 "l_shipinstruct LIKE 'DE%I%ER%'", // H11, BOUND_FUNCTION, "~~"
29 "l_comment NOT LIKE '%str%'", // H12, BOUND_FUNCTION, "!~~"
30 "l_shipinstruct SIMILAR TO 'DE.*I.*ER.*'", // H13, BOUND_FUNCTION, "regexp_matches"
31 "l_comment NOT SIMILAR TO '.*str.*'", // H14, BOUND_FUNCTION, "regexp_matches", preceeded by NOT
32
33 "l_shipmode IN ('MAIL', 'SHIP')", // H15, BOUND_OPERATOR, COMPARE_IN, children - 1 is the cardinality, loop over
34 // children
35
36 "(CASE WHEN l_orderkey = 2 THEN 1 ELSE 0 END) = 1", // H16, BOUND_CASE, three children
37
38 "l_discount + l_tax", // H17, BOUND_FUNCTION, "+"
39 "l_tax - l_discount", // H18, BOUND_FUNCTION, "-"
40 "l_receiptdate - l_commitdate", // H19, BOUND_FUNCTION, "-"
41 "l_discount * l_tax", // H20, BOUND_FUNCTION, "*"
42 "l_discount / l_tax", // H21, BOUND_FUNCTION, "/"
43 "l_orderkey % 5", // H22, BOUND_FUNCTION, "%"
44 "l_orderkey & l_partkey", // H23, BOUND_FUNCTION, "&"
45 "l_orderkey # l_partkey", // H24, BOUND_FUNCTION, "#"
46 "l_orderkey >> l_partkey", // H25, BOUND_FUNCTION, ">>"
47 "l_orderkey << l_partkey", // H26, BOUND_FUNCTION, "<<"
48
49 "abs(l_extendedprice)", // H27, BOUND_FUNCTION, "abs"
50 "round(l_discount, 1)", // H28, BOUND_FUNCTION, "round"
51
52 "l_shipinstruct || l_returnflag = 'R'", // H29, BOUND_FUNCTION, "||"
53 "length(l_comment)", // H30, BOUND_FUNCTION, "length"
54 "lower(l_comment) = 'R'", // H31, BOUND_FUNCTION, "lower"
55 "upper(l_comment) = 'R'", // H32, BOUND_FUNCTION, "upper"
56 "substring(l_shipinstruct, 1, 7) = 'R'", // H33, BOUND_FUNCTION, "substring"
57
58 "date_part('year', l_commitdate)", // H34, BOUND_FUNCTION, "date_part"
59
60 "l_orderkey::VARCHAR = '1'", // H35, BOUND_CAST, OPERATOR_CAST
61 "l_orderkey::DOUBLE = 3.0", // H36, BOUND_CAST, OPERATOR_CAST
62
63 "l_comment SIMILAR TO '.*str.*'", // H37, BOUND_FUNCTION, used to estimate runtime of OPERATOR_NOT
64 "l_quantity < 10 OR l_quantity > 20", // H38, BOUND_CONJUNCTION, CONJUNCTION_OR
65 "(l_quantity < 10 AND l_shipdate > date '1992-01-01') OR l_quantity > 20", // H39, BOUND_CONJUNCTION,
66 // CONJUNCTION_AND
67 "EXTRACT(YEAR from l_shipdate) = 1995", // H40, BOUND_FUNCTION, "date_part"
68 "YEAR(l_shipdate) IN ('1995','1996')" // H41, BOUND_FUNCTION, "year"
69 };
70
71 string enable_profiling = "pragma enable_profiling='json';";
72 string query = "SELECT * FROM lineitem WHERE " + queries[queryID] + ";";
73 return enable_profiling + query;
74}
75
76#define HEURISTICS_QUERY_BODY(QNR) \
77 virtual void Load(DuckDBBenchmarkState *state) { \
78 tpch::dbgen(SF, state->db); \
79 } \
80 virtual string GetQuery() { \
81 return getQuery(QNR); \
82 } \
83 virtual string VerifyResult(QueryResult *result) { \
84 if (!result->success) { \
85 return result->error; \
86 } \
87 return string(); \
88 } \
89 virtual string BenchmarkInfo() { \
90 return "Executing heuristics query..."; \
91 }
92
93DUCKDB_BENCHMARK(ExpressionReorderingH0, "[expression_reordering]")
94HEURISTICS_QUERY_BODY(0);
95FINISH_BENCHMARK(ExpressionReorderingH0)
96
97DUCKDB_BENCHMARK(ExpressionReorderingH1, "[expression_reordering]")
98HEURISTICS_QUERY_BODY(1);
99FINISH_BENCHMARK(ExpressionReorderingH1)
100
101DUCKDB_BENCHMARK(ExpressionReorderingH2, "[expression_reordering]")
102HEURISTICS_QUERY_BODY(2);
103FINISH_BENCHMARK(ExpressionReorderingH2)
104
105DUCKDB_BENCHMARK(ExpressionReorderingH3, "[expression_reordering]")
106HEURISTICS_QUERY_BODY(3);
107FINISH_BENCHMARK(ExpressionReorderingH3)
108
109DUCKDB_BENCHMARK(ExpressionReorderingH4, "[expression_reordering]")
110HEURISTICS_QUERY_BODY(4);
111FINISH_BENCHMARK(ExpressionReorderingH4)
112
113DUCKDB_BENCHMARK(ExpressionReorderingH5, "[expression_reordering]")
114HEURISTICS_QUERY_BODY(5);
115FINISH_BENCHMARK(ExpressionReorderingH5)
116
117DUCKDB_BENCHMARK(ExpressionReorderingH6, "[expression_reordering]")
118HEURISTICS_QUERY_BODY(6);
119FINISH_BENCHMARK(ExpressionReorderingH6)
120
121DUCKDB_BENCHMARK(ExpressionReorderingH7, "[expression_reordering]")
122HEURISTICS_QUERY_BODY(7);
123FINISH_BENCHMARK(ExpressionReorderingH7)
124
125DUCKDB_BENCHMARK(ExpressionReorderingH8, "[expression_reordering]")
126HEURISTICS_QUERY_BODY(8);
127FINISH_BENCHMARK(ExpressionReorderingH8)
128
129DUCKDB_BENCHMARK(ExpressionReorderingH9, "[expression_reordering]")
130HEURISTICS_QUERY_BODY(9);
131FINISH_BENCHMARK(ExpressionReorderingH9)
132
133DUCKDB_BENCHMARK(ExpressionReorderingH10, "[expression_reordering]")
134HEURISTICS_QUERY_BODY(10);
135FINISH_BENCHMARK(ExpressionReorderingH10)
136
137DUCKDB_BENCHMARK(ExpressionReorderingH11, "[expression_reordering]")
138HEURISTICS_QUERY_BODY(11);
139FINISH_BENCHMARK(ExpressionReorderingH11)
140
141DUCKDB_BENCHMARK(ExpressionReorderingH12, "[expression_reordering]")
142HEURISTICS_QUERY_BODY(12);
143FINISH_BENCHMARK(ExpressionReorderingH12)
144
145DUCKDB_BENCHMARK(ExpressionReorderingH13, "[expression_reordering]")
146HEURISTICS_QUERY_BODY(13);
147FINISH_BENCHMARK(ExpressionReorderingH13)
148
149DUCKDB_BENCHMARK(ExpressionReorderingH14, "[expression_reordering]")
150HEURISTICS_QUERY_BODY(14);
151FINISH_BENCHMARK(ExpressionReorderingH14)
152
153DUCKDB_BENCHMARK(ExpressionReorderingH15, "[expression_reordering]")
154HEURISTICS_QUERY_BODY(15);
155FINISH_BENCHMARK(ExpressionReorderingH15)
156
157DUCKDB_BENCHMARK(ExpressionReorderingH16, "[expression_reordering]")
158HEURISTICS_QUERY_BODY(16);
159FINISH_BENCHMARK(ExpressionReorderingH16)
160
161DUCKDB_BENCHMARK(ExpressionReorderingH17, "[expression_reordering]")
162HEURISTICS_QUERY_BODY(17);
163FINISH_BENCHMARK(ExpressionReorderingH17)
164
165DUCKDB_BENCHMARK(ExpressionReorderingH18, "[expression_reordering]")
166HEURISTICS_QUERY_BODY(18);
167FINISH_BENCHMARK(ExpressionReorderingH18)
168
169DUCKDB_BENCHMARK(ExpressionReorderingH19, "[expression_reordering]")
170HEURISTICS_QUERY_BODY(19);
171FINISH_BENCHMARK(ExpressionReorderingH19)
172
173DUCKDB_BENCHMARK(ExpressionReorderingH20, "[expression_reordering]")
174HEURISTICS_QUERY_BODY(20);
175FINISH_BENCHMARK(ExpressionReorderingH20)
176
177DUCKDB_BENCHMARK(ExpressionReorderingH21, "[expression_reordering]")
178HEURISTICS_QUERY_BODY(21);
179FINISH_BENCHMARK(ExpressionReorderingH21)
180
181DUCKDB_BENCHMARK(ExpressionReorderingH22, "[expression_reordering]")
182HEURISTICS_QUERY_BODY(22);
183FINISH_BENCHMARK(ExpressionReorderingH22)
184
185DUCKDB_BENCHMARK(ExpressionReorderingH23, "[expression_reordering]")
186HEURISTICS_QUERY_BODY(23);
187FINISH_BENCHMARK(ExpressionReorderingH23)
188
189DUCKDB_BENCHMARK(ExpressionReorderingH24, "[expression_reordering]")
190HEURISTICS_QUERY_BODY(24);
191FINISH_BENCHMARK(ExpressionReorderingH24)
192
193DUCKDB_BENCHMARK(ExpressionReorderingH25, "[expression_reordering]")
194HEURISTICS_QUERY_BODY(25);
195FINISH_BENCHMARK(ExpressionReorderingH25)
196
197DUCKDB_BENCHMARK(ExpressionReorderingH26, "[expression_reordering]")
198HEURISTICS_QUERY_BODY(26);
199FINISH_BENCHMARK(ExpressionReorderingH26)
200
201DUCKDB_BENCHMARK(ExpressionReorderingH27, "[expression_reordering]")
202HEURISTICS_QUERY_BODY(27);
203FINISH_BENCHMARK(ExpressionReorderingH27)
204
205DUCKDB_BENCHMARK(ExpressionReorderingH28, "[expression_reordering]")
206HEURISTICS_QUERY_BODY(28);
207FINISH_BENCHMARK(ExpressionReorderingH28)
208
209DUCKDB_BENCHMARK(ExpressionReorderingH29, "[expression_reordering]")
210HEURISTICS_QUERY_BODY(29);
211FINISH_BENCHMARK(ExpressionReorderingH29)
212
213DUCKDB_BENCHMARK(ExpressionReorderingH30, "[expression_reordering]")
214HEURISTICS_QUERY_BODY(30);
215FINISH_BENCHMARK(ExpressionReorderingH30)
216
217DUCKDB_BENCHMARK(ExpressionReorderingH31, "[expression_reordering]")
218HEURISTICS_QUERY_BODY(31);
219FINISH_BENCHMARK(ExpressionReorderingH31)
220
221DUCKDB_BENCHMARK(ExpressionReorderingH32, "[expression_reordering]")
222HEURISTICS_QUERY_BODY(32);
223FINISH_BENCHMARK(ExpressionReorderingH32)
224
225DUCKDB_BENCHMARK(ExpressionReorderingH33, "[expression_reordering]")
226HEURISTICS_QUERY_BODY(33);
227FINISH_BENCHMARK(ExpressionReorderingH33)
228
229DUCKDB_BENCHMARK(ExpressionReorderingH34, "[expression_reordering]")
230HEURISTICS_QUERY_BODY(34);
231FINISH_BENCHMARK(ExpressionReorderingH34)
232
233DUCKDB_BENCHMARK(ExpressionReorderingH35, "[expression_reordering]")
234HEURISTICS_QUERY_BODY(35);
235FINISH_BENCHMARK(ExpressionReorderingH35)
236
237DUCKDB_BENCHMARK(ExpressionReorderingH36, "[expression_reordering]")
238HEURISTICS_QUERY_BODY(36);
239FINISH_BENCHMARK(ExpressionReorderingH36)
240
241DUCKDB_BENCHMARK(ExpressionReorderingH37, "[expression_reordering]")
242HEURISTICS_QUERY_BODY(37);
243FINISH_BENCHMARK(ExpressionReorderingH37)
244
245DUCKDB_BENCHMARK(ExpressionReorderingH38, "[expression_reordering]")
246HEURISTICS_QUERY_BODY(38);
247FINISH_BENCHMARK(ExpressionReorderingH38)
248
249DUCKDB_BENCHMARK(ExpressionReorderingH39, "[expression_reordering]")
250HEURISTICS_QUERY_BODY(39);
251FINISH_BENCHMARK(ExpressionReorderingH39)
252
253DUCKDB_BENCHMARK(ExpressionReorderingH40, "[expression_reordering]")
254HEURISTICS_QUERY_BODY(40);
255FINISH_BENCHMARK(ExpressionReorderingH40)
256
257DUCKDB_BENCHMARK(ExpressionReorderingH41, "[expression_reordering]")
258HEURISTICS_QUERY_BODY(41);
259FINISH_BENCHMARK(ExpressionReorderingH41)
260