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 RANGE_QUERY_ROW_COUNT pow(10, 7)
11#define SUM_RESULT 100
12
13DUCKDB_BENCHMARK(DataSkipping, "[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 < RANGE_QUERY_ROW_COUNT; i++) {
18 appender.BeginRow();
19 appender.Append<int32_t>(i);
20 appender.Append<int32_t>(i);
21 appender.EndRow();
22 }
23 appender.Close();
24}
25virtual std::string GetQuery() {
26 return "SELECT sum(j) FROM integers WHERE i = 100";
27}
28
29virtual std::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 (result->names.size() != 1) {
38 return "Incorrect amount of columns";
39 }
40 if (materialized.GetValue<int64_t>(0, 0) != SUM_RESULT) {
41 return "Incorrect result returned, expected " + to_string(SUM_RESULT);
42 }
43 return std::string();
44}
45
46virtual std::string BenchmarkInfo() {
47 return StringUtil::Format("Runs the following query: \"" + GetQuery() + "\" without an index");
48}
49FINISH_BENCHMARK(DataSkipping)
50