1#include "benchmark_runner.hpp"
2#include "duckdb_benchmark_macro.hpp"
3#include "duckdb/main/appender.hpp"
4
5#include <random>
6
7using namespace duckdb;
8using namespace std;
9
10#define POINT_QUERY_ROW_COUNT 100000000
11#define POINT_QUERY_ENTRY 50000
12
13DUCKDB_BENCHMARK(PointQueryWithoutIndex, "[micro]")
14virtual void Load(DuckDBBenchmarkState *state) {
15 state->conn.Query("CREATE TABLE integers(i INTEGER, j INTEGER);");
16 Appender appender(state->conn, "integers"); // insert the elements into the database
17 for (size_t i = 0; i < POINT_QUERY_ROW_COUNT; i++) {
18 appender.BeginRow();
19 appender.Append<int32_t>(i);
20 appender.Append<int32_t>(i + 2);
21 appender.EndRow();
22 }
23}
24
25virtual string GetQuery() {
26 return "SELECT j FROM integers WHERE i=" + to_string(POINT_QUERY_ENTRY);
27}
28
29virtual string VerifyResult(QueryResult *result) {
30 if (!result->success) {
31 return result->error;
32 }
33 auto &materialized = (MaterializedQueryResult &)*result;
34 if (materialized.collection.count != 1) {
35 return "Incorrect amount of rows in result";
36 }
37 if (materialized.names.size() != 1) {
38 return "Incorrect amount of columns";
39 }
40 if (materialized.GetValue<int32_t>(0, 0) != POINT_QUERY_ENTRY + 2) {
41 return "Incorrect result returned, expected " + to_string(POINT_QUERY_ENTRY + 2);
42 }
43 return string();
44}
45
46virtual string BenchmarkInfo() {
47 return StringUtil::Format("Runs the following query: \"" + GetQuery() + "\" without an index");
48}
49FINISH_BENCHMARK(PointQueryWithoutIndex)
50
51DUCKDB_BENCHMARK(PointQueryWithIndexART, "[micro]")
52virtual void Load(DuckDBBenchmarkState *state) {
53 state->conn.Query("CREATE TABLE integers(i INTEGER, j INTEGER);");
54 Appender appender(state->conn, "integers"); // insert the elements into the database
55 for (size_t i = 0; i < POINT_QUERY_ROW_COUNT; i++) {
56 appender.BeginRow();
57 appender.Append<int32_t>(i);
58 appender.Append<int32_t>(i + 2);
59 appender.EndRow();
60 }
61 appender.Close();
62 state->conn.Query("CREATE INDEX i_index ON integers using art(i)");
63}
64
65virtual string GetQuery() {
66 return "SELECT j FROM integers WHERE i=" + to_string(POINT_QUERY_ENTRY);
67}
68
69virtual string VerifyResult(QueryResult *result) {
70 if (!result->success) {
71 return result->error;
72 }
73 auto &materialized = (MaterializedQueryResult &)*result;
74 if (materialized.collection.count != 1) {
75 return "Incorrect amount of rows in result";
76 }
77 if (materialized.names.size() != 1) {
78 return "Incorrect amount of columns";
79 }
80 if (materialized.GetValue<int32_t>(0, 0) != POINT_QUERY_ENTRY + 2) {
81 return "Incorrect result returned, expected " + to_string(POINT_QUERY_ENTRY + 2);
82 }
83 return string();
84}
85
86virtual string BenchmarkInfo() {
87 return StringUtil::Format("Runs the following query: \"" + GetQuery() + "\" with an ART index");
88}
89FINISH_BENCHMARK(PointQueryWithIndexART)
90