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 ROW_COUNT 100000000
11#define UPPERBOUND 100000000
12#define SUCCESS 0
13
14DUCKDB_BENCHMARK(IndexCreationART, "[micro]")
15virtual void Load(DuckDBBenchmarkState *state) {
16 state->conn.Query("CREATE TABLE integers(i INTEGER);");
17 Appender appender(state->conn, "integers"); // insert the elements into the database
18 for (size_t i = 0; i < ROW_COUNT; i++) {
19 appender.BeginRow();
20 appender.Append<int32_t>(rand() % UPPERBOUND);
21 appender.EndRow();
22 }
23}
24
25virtual string GetQuery() {
26 return "CREATE INDEX i_index ON integers using art(i)";
27}
28
29virtual void Cleanup(DuckDBBenchmarkState *state) {
30 state->conn.Query("DROP INDEX i_index;");
31}
32
33virtual string VerifyResult(QueryResult *result) {
34 if (!result->success) {
35 return result->error;
36 }
37 auto &materialized = (MaterializedQueryResult &)*result;
38 if (materialized.collection.count != 1) {
39 return "Incorrect amount of rows in result";
40 }
41 if (materialized.names.size() != 1) {
42 return "Incorrect amount of columns";
43 }
44 if (materialized.GetValue<int32_t>(0, 0) != SUCCESS) {
45 return "Incorrect result returned, expected " + to_string(SUCCESS);
46 }
47 return string();
48}
49
50virtual string BenchmarkInfo() {
51 return StringUtil::Format("Creates an ART Index on a Uniform Random Column");
52}
53
54FINISH_BENCHMARK(IndexCreationART)
55