| 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 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 | |
| 40 | DUCKDB_BENCHMARK(TPCHEmptyStartup, "[startup]" ) |
| 41 | TPCHStartup("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 | } |
| 47 | FINISH_BENCHMARK(TPCHEmptyStartup) |
| 48 | |
| 49 | DUCKDB_BENCHMARK(TPCHCount, "[startup]" ) |
| 50 | TPCHStartup("SELECT COUNT(*) FROM lineitem" ) NormalConfig() string VerifyResult(QueryResult *result) override { |
| 51 | if (!result->success) { |
| 52 | return result->error; |
| 53 | } |
| 54 | return string(); |
| 55 | } |
| 56 | FINISH_BENCHMARK(TPCHCount) |
| 57 | |
| 58 | DUCKDB_BENCHMARK(TPCHSimpleAggr, "[startup]" ) |
| 59 | TPCHStartup("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 | } |
| 66 | FINISH_BENCHMARK(TPCHSimpleAggr) |
| 67 | |
| 68 | DUCKDB_BENCHMARK(TPCHQ1, "[startup]" ) |
| 69 | TPCHStartup(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 | } |
| 75 | FINISH_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 | |
| 84 | DUCKDB_BENCHMARK(TPCHEmptyStartupDirectIO, "[startup]" ) |
| 85 | TPCHStartup("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 | } |
| 91 | FINISH_BENCHMARK(TPCHEmptyStartupDirectIO) |
| 92 | |
| 93 | DUCKDB_BENCHMARK(TPCHCountDirectIO, "[startup]" ) |
| 94 | TPCHStartup("SELECT COUNT(*) FROM lineitem" ) DirectIOConfig() string VerifyResult(QueryResult *result) override { |
| 95 | if (!result->success) { |
| 96 | return result->error; |
| 97 | } |
| 98 | return string(); |
| 99 | } |
| 100 | FINISH_BENCHMARK(TPCHCountDirectIO) |
| 101 | |
| 102 | DUCKDB_BENCHMARK(TPCHSimpleAggrDirectIO, "[startup]" ) |
| 103 | TPCHStartup("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 | } |
| 110 | FINISH_BENCHMARK(TPCHSimpleAggrDirectIO) |
| 111 | |
| 112 | DUCKDB_BENCHMARK(TPCHQ1DirectIO, "[startup]" ) |
| 113 | TPCHStartup(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 | } |
| 119 | FINISH_BENCHMARK(TPCHQ1DirectIO) |
| 120 | |