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
11#define TPCHStartup(QUERY) \
12 string db_path = "duckdb_benchmark_db.db"; \
13 void Load(DuckDBBenchmarkState *state) override { \
14 DeleteDatabase(db_path); \
15 { \
16 DuckDB db(db_path); \
17 tpch::dbgen(SF, db); \
18 } \
19 { \
20 auto config = GetConfig(); \
21 config->checkpoint_wal_size = 0; \
22 DuckDB db(db_path, config.get()); \
23 } \
24 } \
25 void RunBenchmark(DuckDBBenchmarkState *state) override { \
26 auto config = GetConfig(); \
27 DuckDB db(db_path, config.get()); \
28 Connection con(db); \
29 state->result = con.Query(QUERY); \
30 } \
31 string BenchmarkInfo() override { \
32 return string("Start a TPC-H SF1 database and run ") + QUERY + string(" in the database"); \
33 }
34
35#define NormalConfig() \
36 unique_ptr<DBConfig> GetConfig() { \
37 return make_unique<DBConfig>(); \
38 }
39
40DUCKDB_BENCHMARK(TPCHEmptyStartup, "[startup]")
41TPCHStartup("SELECT * FROM lineitem WHERE 1=0") NormalConfig() string VerifyResult(QueryResult *result) override {
42 if (!result->success) {
43 return result->error;
44 }
45 return string();
46}
47FINISH_BENCHMARK(TPCHEmptyStartup)
48
49DUCKDB_BENCHMARK(TPCHCount, "[startup]")
50TPCHStartup("SELECT COUNT(*) FROM lineitem") NormalConfig() string VerifyResult(QueryResult *result) override {
51 if (!result->success) {
52 return result->error;
53 }
54 return string();
55}
56FINISH_BENCHMARK(TPCHCount)
57
58DUCKDB_BENCHMARK(TPCHSimpleAggr, "[startup]")
59TPCHStartup("SELECT SUM(l_extendedprice) FROM lineitem") NormalConfig() string
60 VerifyResult(QueryResult *result) override {
61 if (!result->success) {
62 return result->error;
63 }
64 return string();
65}
66FINISH_BENCHMARK(TPCHSimpleAggr)
67
68DUCKDB_BENCHMARK(TPCHQ1, "[startup]")
69TPCHStartup(tpch::get_query(1)) NormalConfig() string VerifyResult(QueryResult *result) override {
70 if (!result->success) {
71 return result->error;
72 }
73 return compare_csv(*result, tpch::get_answer(SF, 1), true);
74}
75FINISH_BENCHMARK(TPCHQ1)
76
77#define DirectIOConfig() \
78 unique_ptr<DBConfig> GetConfig() { \
79 auto config = make_unique<DBConfig>(); \
80 config->use_direct_io = true; \
81 return config; \
82 }
83
84DUCKDB_BENCHMARK(TPCHEmptyStartupDirectIO, "[startup]")
85TPCHStartup("SELECT * FROM lineitem WHERE 1=0") DirectIOConfig() string VerifyResult(QueryResult *result) override {
86 if (!result->success) {
87 return result->error;
88 }
89 return string();
90}
91FINISH_BENCHMARK(TPCHEmptyStartupDirectIO)
92
93DUCKDB_BENCHMARK(TPCHCountDirectIO, "[startup]")
94TPCHStartup("SELECT COUNT(*) FROM lineitem") DirectIOConfig() string VerifyResult(QueryResult *result) override {
95 if (!result->success) {
96 return result->error;
97 }
98 return string();
99}
100FINISH_BENCHMARK(TPCHCountDirectIO)
101
102DUCKDB_BENCHMARK(TPCHSimpleAggrDirectIO, "[startup]")
103TPCHStartup("SELECT SUM(l_extendedprice) FROM lineitem") DirectIOConfig() string
104 VerifyResult(QueryResult *result) override {
105 if (!result->success) {
106 return result->error;
107 }
108 return string();
109}
110FINISH_BENCHMARK(TPCHSimpleAggrDirectIO)
111
112DUCKDB_BENCHMARK(TPCHQ1DirectIO, "[startup]")
113TPCHStartup(tpch::get_query(1)) DirectIOConfig() string VerifyResult(QueryResult *result) override {
114 if (!result->success) {
115 return result->error;
116 }
117 return compare_csv(*result, tpch::get_answer(SF, 1), true);
118}
119FINISH_BENCHMARK(TPCHQ1DirectIO)
120