| 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 | DUCKDB_BENCHMARK(LineitemSimpleAggregate, "[aggregate]") | 
|---|
| 12 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 13 | // load the data into the tpch schema | 
|---|
| 14 | tpch::dbgen(SF, state->db); | 
|---|
| 15 | } | 
|---|
| 16 | string GetQuery() override { | 
|---|
| 17 | return "SELECT SUM(l_quantity) FROM lineitem"; | 
|---|
| 18 | } | 
|---|
| 19 | string VerifyResult(QueryResult *result) override { | 
|---|
| 20 | if (!result->success) { | 
|---|
| 21 | return result->error; | 
|---|
| 22 | } | 
|---|
| 23 | return string(); | 
|---|
| 24 | } | 
|---|
| 25 | string BenchmarkInfo() override { | 
|---|
| 26 | return "Execute the query \"SELECT SUM(l_quantity) FROM lineitem\" on SF1"; | 
|---|
| 27 | } | 
|---|
| 28 | FINISH_BENCHMARK(LineitemSimpleAggregate) | 
|---|
| 29 |  | 
|---|
| 30 | DUCKDB_BENCHMARK(LineitemCount, "[aggregate]") | 
|---|
| 31 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 32 | // load the data into the tpch schema | 
|---|
| 33 | tpch::dbgen(SF, state->db); | 
|---|
| 34 | } | 
|---|
| 35 | string GetQuery() override { | 
|---|
| 36 | return "SELECT COUNT(*) FROM lineitem"; | 
|---|
| 37 | } | 
|---|
| 38 | string VerifyResult(QueryResult *result) override { | 
|---|
| 39 | if (!result->success) { | 
|---|
| 40 | return result->error; | 
|---|
| 41 | } | 
|---|
| 42 | return string(); | 
|---|
| 43 | } | 
|---|
| 44 | string BenchmarkInfo() override { | 
|---|
| 45 | return "Execute the query \"SELECT COUNT(*) FROM lineitem\" on SF1"; | 
|---|
| 46 | } | 
|---|
| 47 | FINISH_BENCHMARK(LineitemCount) | 
|---|
| 48 |  | 
|---|
| 49 | DUCKDB_BENCHMARK(LineitemGroupAggregate, "[aggregate]") | 
|---|
| 50 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 51 | // load the data into the tpch schema | 
|---|
| 52 | tpch::dbgen(SF, state->db); | 
|---|
| 53 | } | 
|---|
| 54 | string GetQuery() override { | 
|---|
| 55 | return "SELECT l_quantity, SUM(l_quantity) FROM lineitem GROUP BY l_quantity"; | 
|---|
| 56 | } | 
|---|
| 57 | string VerifyResult(QueryResult *result) override { | 
|---|
| 58 | if (!result->success) { | 
|---|
| 59 | return result->error; | 
|---|
| 60 | } | 
|---|
| 61 | return string(); | 
|---|
| 62 | } | 
|---|
| 63 | string BenchmarkInfo() override { | 
|---|
| 64 | return "Execute the query \"SELECT l_quantity, SUM(l_quantity) FROM lineitem GROUP BY l_quantity\" on SF1"; | 
|---|
| 65 | } | 
|---|
| 66 | FINISH_BENCHMARK(LineitemGroupAggregate) | 
|---|
| 67 |  | 
|---|
| 68 | DUCKDB_BENCHMARK(LineitemGroupStringAggregate, "[aggregate]") | 
|---|
| 69 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 70 | // load the data into the tpch schema | 
|---|
| 71 | tpch::dbgen(SF, state->db); | 
|---|
| 72 | } | 
|---|
| 73 | string GetQuery() override { | 
|---|
| 74 | return "SELECT SUM(l_quantity) FROM lineitem GROUP BY l_returnflag"; | 
|---|
| 75 | } | 
|---|
| 76 | string VerifyResult(QueryResult *result) override { | 
|---|
| 77 | if (!result->success) { | 
|---|
| 78 | return result->error; | 
|---|
| 79 | } | 
|---|
| 80 | return string(); | 
|---|
| 81 | } | 
|---|
| 82 | string BenchmarkInfo() override { | 
|---|
| 83 | return "Execute the query \"SELECT SUM(l_quantity) FROM lineitem GROUP BY l_returnflag\" on SF1"; | 
|---|
| 84 | } | 
|---|
| 85 | FINISH_BENCHMARK(LineitemGroupStringAggregate) | 
|---|
| 86 |  | 
|---|
| 87 | DUCKDB_BENCHMARK(LineitemJoinAggregate, "[aggregate]") | 
|---|
| 88 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 89 | // load the data into the tpch schema | 
|---|
| 90 | tpch::dbgen(SF, state->db); | 
|---|
| 91 | } | 
|---|
| 92 | string 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 | } | 
|---|
| 99 | string VerifyResult(QueryResult *result) override { | 
|---|
| 100 | if (!result->success) { | 
|---|
| 101 | return result->error; | 
|---|
| 102 | } | 
|---|
| 103 | return string(); | 
|---|
| 104 | } | 
|---|
| 105 | string BenchmarkInfo() override { | 
|---|
| 106 | return "Execute the query \""+ GetQuery() + "\" on SF1"; | 
|---|
| 107 | } | 
|---|
| 108 | FINISH_BENCHMARK(LineitemJoinAggregate) | 
|---|
| 109 |  | 
|---|
| 110 | DUCKDB_BENCHMARK(LineitemJoinAggregateWithFilter, "[aggregate]") | 
|---|
| 111 | void Load(DuckDBBenchmarkState *state) override { | 
|---|
| 112 | // load the data into the tpch schema | 
|---|
| 113 | tpch::dbgen(SF, state->db); | 
|---|
| 114 | } | 
|---|
| 115 | string 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 | } | 
|---|
| 122 | string VerifyResult(QueryResult *result) override { | 
|---|
| 123 | if (!result->success) { | 
|---|
| 124 | return result->error; | 
|---|
| 125 | } | 
|---|
| 126 | return string(); | 
|---|
| 127 | } | 
|---|
| 128 | string BenchmarkInfo() override { | 
|---|
| 129 | return "Execute the query \""+ GetQuery() + "\" on SF1"; | 
|---|
| 130 | } | 
|---|
| 131 | FINISH_BENCHMARK(LineitemJoinAggregateWithFilter) | 
|---|
| 132 |  | 
|---|
| 133 | DUCKDB_BENCHMARK(TPCHQ1IntKeys, "[aggregate]") | 
|---|
| 134 | void 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 | } | 
|---|
| 144 | string GetQuery() override { | 
|---|
| 145 | return tpch::get_query(1); | 
|---|
| 146 | } | 
|---|
| 147 | string VerifyResult(QueryResult *result) override { | 
|---|
| 148 | if (!result->success) { | 
|---|
| 149 | return result->error; | 
|---|
| 150 | } | 
|---|
| 151 | return string(); | 
|---|
| 152 | } | 
|---|
| 153 | string BenchmarkInfo() override { | 
|---|
| 154 | return "Execute the query \""+ GetQuery() + "\" on SF1"; | 
|---|
| 155 | } | 
|---|
| 156 | FINISH_BENCHMARK(TPCHQ1IntKeys) | 
|---|
| 157 |  | 
|---|