1 | #include "benchmark_runner.hpp" |
2 | #include "compare_result.hpp" |
3 | #include "dbgen.hpp" |
4 | #include "duckdb_benchmark_macro.hpp" |
5 | |
6 | using namespace duckdb; |
7 | using namespace std; |
8 | |
9 | #define SF 0.2 |
10 | |
11 | string 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 | |
93 | DUCKDB_BENCHMARK(ExpressionReorderingH0, "[expression_reordering]" ) |
94 | HEURISTICS_QUERY_BODY(0); |
95 | FINISH_BENCHMARK(ExpressionReorderingH0) |
96 | |
97 | DUCKDB_BENCHMARK(ExpressionReorderingH1, "[expression_reordering]" ) |
98 | HEURISTICS_QUERY_BODY(1); |
99 | FINISH_BENCHMARK(ExpressionReorderingH1) |
100 | |
101 | DUCKDB_BENCHMARK(ExpressionReorderingH2, "[expression_reordering]" ) |
102 | HEURISTICS_QUERY_BODY(2); |
103 | FINISH_BENCHMARK(ExpressionReorderingH2) |
104 | |
105 | DUCKDB_BENCHMARK(ExpressionReorderingH3, "[expression_reordering]" ) |
106 | HEURISTICS_QUERY_BODY(3); |
107 | FINISH_BENCHMARK(ExpressionReorderingH3) |
108 | |
109 | DUCKDB_BENCHMARK(ExpressionReorderingH4, "[expression_reordering]" ) |
110 | HEURISTICS_QUERY_BODY(4); |
111 | FINISH_BENCHMARK(ExpressionReorderingH4) |
112 | |
113 | DUCKDB_BENCHMARK(ExpressionReorderingH5, "[expression_reordering]" ) |
114 | HEURISTICS_QUERY_BODY(5); |
115 | FINISH_BENCHMARK(ExpressionReorderingH5) |
116 | |
117 | DUCKDB_BENCHMARK(ExpressionReorderingH6, "[expression_reordering]" ) |
118 | HEURISTICS_QUERY_BODY(6); |
119 | FINISH_BENCHMARK(ExpressionReorderingH6) |
120 | |
121 | DUCKDB_BENCHMARK(ExpressionReorderingH7, "[expression_reordering]" ) |
122 | HEURISTICS_QUERY_BODY(7); |
123 | FINISH_BENCHMARK(ExpressionReorderingH7) |
124 | |
125 | DUCKDB_BENCHMARK(ExpressionReorderingH8, "[expression_reordering]" ) |
126 | HEURISTICS_QUERY_BODY(8); |
127 | FINISH_BENCHMARK(ExpressionReorderingH8) |
128 | |
129 | DUCKDB_BENCHMARK(ExpressionReorderingH9, "[expression_reordering]" ) |
130 | HEURISTICS_QUERY_BODY(9); |
131 | FINISH_BENCHMARK(ExpressionReorderingH9) |
132 | |
133 | DUCKDB_BENCHMARK(ExpressionReorderingH10, "[expression_reordering]" ) |
134 | HEURISTICS_QUERY_BODY(10); |
135 | FINISH_BENCHMARK(ExpressionReorderingH10) |
136 | |
137 | DUCKDB_BENCHMARK(ExpressionReorderingH11, "[expression_reordering]" ) |
138 | HEURISTICS_QUERY_BODY(11); |
139 | FINISH_BENCHMARK(ExpressionReorderingH11) |
140 | |
141 | DUCKDB_BENCHMARK(ExpressionReorderingH12, "[expression_reordering]" ) |
142 | HEURISTICS_QUERY_BODY(12); |
143 | FINISH_BENCHMARK(ExpressionReorderingH12) |
144 | |
145 | DUCKDB_BENCHMARK(ExpressionReorderingH13, "[expression_reordering]" ) |
146 | HEURISTICS_QUERY_BODY(13); |
147 | FINISH_BENCHMARK(ExpressionReorderingH13) |
148 | |
149 | DUCKDB_BENCHMARK(ExpressionReorderingH14, "[expression_reordering]" ) |
150 | HEURISTICS_QUERY_BODY(14); |
151 | FINISH_BENCHMARK(ExpressionReorderingH14) |
152 | |
153 | DUCKDB_BENCHMARK(ExpressionReorderingH15, "[expression_reordering]" ) |
154 | HEURISTICS_QUERY_BODY(15); |
155 | FINISH_BENCHMARK(ExpressionReorderingH15) |
156 | |
157 | DUCKDB_BENCHMARK(ExpressionReorderingH16, "[expression_reordering]" ) |
158 | HEURISTICS_QUERY_BODY(16); |
159 | FINISH_BENCHMARK(ExpressionReorderingH16) |
160 | |
161 | DUCKDB_BENCHMARK(ExpressionReorderingH17, "[expression_reordering]" ) |
162 | HEURISTICS_QUERY_BODY(17); |
163 | FINISH_BENCHMARK(ExpressionReorderingH17) |
164 | |
165 | DUCKDB_BENCHMARK(ExpressionReorderingH18, "[expression_reordering]" ) |
166 | HEURISTICS_QUERY_BODY(18); |
167 | FINISH_BENCHMARK(ExpressionReorderingH18) |
168 | |
169 | DUCKDB_BENCHMARK(ExpressionReorderingH19, "[expression_reordering]" ) |
170 | HEURISTICS_QUERY_BODY(19); |
171 | FINISH_BENCHMARK(ExpressionReorderingH19) |
172 | |
173 | DUCKDB_BENCHMARK(ExpressionReorderingH20, "[expression_reordering]" ) |
174 | HEURISTICS_QUERY_BODY(20); |
175 | FINISH_BENCHMARK(ExpressionReorderingH20) |
176 | |
177 | DUCKDB_BENCHMARK(ExpressionReorderingH21, "[expression_reordering]" ) |
178 | HEURISTICS_QUERY_BODY(21); |
179 | FINISH_BENCHMARK(ExpressionReorderingH21) |
180 | |
181 | DUCKDB_BENCHMARK(ExpressionReorderingH22, "[expression_reordering]" ) |
182 | HEURISTICS_QUERY_BODY(22); |
183 | FINISH_BENCHMARK(ExpressionReorderingH22) |
184 | |
185 | DUCKDB_BENCHMARK(ExpressionReorderingH23, "[expression_reordering]" ) |
186 | HEURISTICS_QUERY_BODY(23); |
187 | FINISH_BENCHMARK(ExpressionReorderingH23) |
188 | |
189 | DUCKDB_BENCHMARK(ExpressionReorderingH24, "[expression_reordering]" ) |
190 | HEURISTICS_QUERY_BODY(24); |
191 | FINISH_BENCHMARK(ExpressionReorderingH24) |
192 | |
193 | DUCKDB_BENCHMARK(ExpressionReorderingH25, "[expression_reordering]" ) |
194 | HEURISTICS_QUERY_BODY(25); |
195 | FINISH_BENCHMARK(ExpressionReorderingH25) |
196 | |
197 | DUCKDB_BENCHMARK(ExpressionReorderingH26, "[expression_reordering]" ) |
198 | HEURISTICS_QUERY_BODY(26); |
199 | FINISH_BENCHMARK(ExpressionReorderingH26) |
200 | |
201 | DUCKDB_BENCHMARK(ExpressionReorderingH27, "[expression_reordering]" ) |
202 | HEURISTICS_QUERY_BODY(27); |
203 | FINISH_BENCHMARK(ExpressionReorderingH27) |
204 | |
205 | DUCKDB_BENCHMARK(ExpressionReorderingH28, "[expression_reordering]" ) |
206 | HEURISTICS_QUERY_BODY(28); |
207 | FINISH_BENCHMARK(ExpressionReorderingH28) |
208 | |
209 | DUCKDB_BENCHMARK(ExpressionReorderingH29, "[expression_reordering]" ) |
210 | HEURISTICS_QUERY_BODY(29); |
211 | FINISH_BENCHMARK(ExpressionReorderingH29) |
212 | |
213 | DUCKDB_BENCHMARK(ExpressionReorderingH30, "[expression_reordering]" ) |
214 | HEURISTICS_QUERY_BODY(30); |
215 | FINISH_BENCHMARK(ExpressionReorderingH30) |
216 | |
217 | DUCKDB_BENCHMARK(ExpressionReorderingH31, "[expression_reordering]" ) |
218 | HEURISTICS_QUERY_BODY(31); |
219 | FINISH_BENCHMARK(ExpressionReorderingH31) |
220 | |
221 | DUCKDB_BENCHMARK(ExpressionReorderingH32, "[expression_reordering]" ) |
222 | HEURISTICS_QUERY_BODY(32); |
223 | FINISH_BENCHMARK(ExpressionReorderingH32) |
224 | |
225 | DUCKDB_BENCHMARK(ExpressionReorderingH33, "[expression_reordering]" ) |
226 | HEURISTICS_QUERY_BODY(33); |
227 | FINISH_BENCHMARK(ExpressionReorderingH33) |
228 | |
229 | DUCKDB_BENCHMARK(ExpressionReorderingH34, "[expression_reordering]" ) |
230 | HEURISTICS_QUERY_BODY(34); |
231 | FINISH_BENCHMARK(ExpressionReorderingH34) |
232 | |
233 | DUCKDB_BENCHMARK(ExpressionReorderingH35, "[expression_reordering]" ) |
234 | HEURISTICS_QUERY_BODY(35); |
235 | FINISH_BENCHMARK(ExpressionReorderingH35) |
236 | |
237 | DUCKDB_BENCHMARK(ExpressionReorderingH36, "[expression_reordering]" ) |
238 | HEURISTICS_QUERY_BODY(36); |
239 | FINISH_BENCHMARK(ExpressionReorderingH36) |
240 | |
241 | DUCKDB_BENCHMARK(ExpressionReorderingH37, "[expression_reordering]" ) |
242 | HEURISTICS_QUERY_BODY(37); |
243 | FINISH_BENCHMARK(ExpressionReorderingH37) |
244 | |
245 | DUCKDB_BENCHMARK(ExpressionReorderingH38, "[expression_reordering]" ) |
246 | HEURISTICS_QUERY_BODY(38); |
247 | FINISH_BENCHMARK(ExpressionReorderingH38) |
248 | |
249 | DUCKDB_BENCHMARK(ExpressionReorderingH39, "[expression_reordering]" ) |
250 | HEURISTICS_QUERY_BODY(39); |
251 | FINISH_BENCHMARK(ExpressionReorderingH39) |
252 | |
253 | DUCKDB_BENCHMARK(ExpressionReorderingH40, "[expression_reordering]" ) |
254 | HEURISTICS_QUERY_BODY(40); |
255 | FINISH_BENCHMARK(ExpressionReorderingH40) |
256 | |
257 | DUCKDB_BENCHMARK(ExpressionReorderingH41, "[expression_reordering]" ) |
258 | HEURISTICS_QUERY_BODY(41); |
259 | FINISH_BENCHMARK(ExpressionReorderingH41) |
260 | |