Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix benchmark-ci #1772

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/include/planner/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class Planner {
static std::unique_ptr<LogicalPlan> planExplain(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);

static std::vector<std::unique_ptr<LogicalPlan>> getAllQueryPlans(
const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);

static std::vector<std::unique_ptr<LogicalPlan>> getAllExplainPlans(
const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
};

} // namespace planner
Expand Down
47 changes: 37 additions & 10 deletions src/planner/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "planner/logical_plan/logical_operator/logical_drop_property.h"
#include "planner/logical_plan/logical_operator/logical_drop_table.h"
#include "planner/logical_plan/logical_operator/logical_explain.h"
#include "planner/logical_plan/logical_operator/logical_in_query_call.h"
#include "planner/logical_plan/logical_operator/logical_rename_property.h"
#include "planner/logical_plan/logical_operator/logical_rename_table.h"
#include "planner/logical_plan/logical_operator/logical_standalone_call.h"
Expand Down Expand Up @@ -78,16 +77,16 @@ std::unique_ptr<LogicalPlan> Planner::getBestPlan(const Catalog& catalog,
std::vector<std::unique_ptr<LogicalPlan>> Planner::getAllPlans(const Catalog& catalog,
const NodesStatisticsAndDeletedIDs& nodesStatistics, const RelsStatistics& relsStatistics,
const BoundStatement& statement) {
// We enumerate all plans for our testing framework. This API should only be used for QUERY
// but not DDL or COPY.
assert(statement.getStatementType() == StatementType::QUERY);
auto planner = QueryPlanner(catalog, nodesStatistics, relsStatistics);
std::vector<std::unique_ptr<LogicalPlan>> plans;
for (auto& plan : planner.getAllPlans(statement)) {
// Avoid sharing operator across plans.
plans.push_back(plan->deepCopy());
// We enumerate all plans for our testing framework. This API should only be used for QUERY,
// EXPLAIN, but not DDL or COPY.
switch (statement.getStatementType()) {
case StatementType::QUERY:
return getAllQueryPlans(catalog, nodesStatistics, relsStatistics, statement);
case StatementType::EXPLAIN:
return getAllExplainPlans(catalog, nodesStatistics, relsStatistics, statement);
default:
throw NotImplementedException("Planner::getAllPlans");
}
return plans;
}

std::unique_ptr<LogicalPlan> Planner::planCreateNodeTable(const BoundStatement& statement) {
Expand Down Expand Up @@ -207,5 +206,33 @@ std::unique_ptr<LogicalPlan> Planner::planExplain(const Catalog& catalog,
return plan;
}

std::vector<std::unique_ptr<LogicalPlan>> Planner::getAllQueryPlans(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement) {
auto planner = QueryPlanner(catalog, nodesStatistics, relsStatistics);
std::vector<std::unique_ptr<LogicalPlan>> plans;
for (auto& plan : planner.getAllPlans(statement)) {
// Avoid sharing operator across plans.
plans.push_back(plan->deepCopy());
}
return plans;
}

std::vector<std::unique_ptr<LogicalPlan>> Planner::getAllExplainPlans(
const catalog::Catalog& catalog, const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement) {
auto& explainStatement = reinterpret_cast<const BoundExplain&>(statement);
auto statementToExplain = explainStatement.getStatementToExplain();
auto plans = getAllPlans(catalog, nodesStatistics, relsStatistics, *statementToExplain);
for (auto& plan : plans) {
auto logicalExplain = make_shared<LogicalExplain>(plan->getLastOperator(),
statement.getStatementResult()->getSingleExpressionToCollect(),
explainStatement.getExplainType(),
explainStatement.getStatementToExplain()->getStatementResult()->getColumns());
plan->setLastOperator(std::move(logicalExplain));
}
return plans;
}

} // namespace planner
} // namespace kuzu
2 changes: 2 additions & 0 deletions test/test_files/tinysnb/explain/explain.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

-LOG ExplainQuery
-STATEMENT EXPLAIN MATCH (p:npytable) RETURN p.id
-ENUMERATE
---- ok

-LOG ProfileDDL
Expand All @@ -37,4 +38,5 @@

-LOG ProfileQuery
-STATEMENT Profile MATCH (p:npytable) RETURN p.id
-ENUMERATE
---- ok
7 changes: 5 additions & 2 deletions tools/benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ void Benchmark::loadBenchmark(const std::string& benchmarkPath) {
auto queryConfigs = testing::TestHelper::parseTestFile(benchmarkPath);
assert(queryConfigs.size() == 1);
auto queryConfig = queryConfigs[0].get();
query = config.enableProfile ? "PROFILE " : "";
query += queryConfig->query;
query = queryConfig->query;
name = queryConfig->name;
expectedOutput = queryConfig->expectedTuples;
encodedJoin = queryConfig->encodedJoin;
Expand All @@ -33,6 +32,10 @@ std::unique_ptr<QueryResult> Benchmark::run() const {
return conn->query(query, encodedJoin);
}

std::unique_ptr<QueryResult> Benchmark::runWithProfile() const {
return conn->query("PROFILE " + query, encodedJoin);
}

void Benchmark::logQueryInfo(
std::ofstream& log, uint32_t runNum, std::vector<std::string>& actualOutput) const {
log << "Run Num: " << runNum << std::endl;
Expand Down
13 changes: 13 additions & 0 deletions tools/benchmark/benchmark_runner.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "benchmark_runner.h"

#include <filesystem>
#include <fstream>

#include "spdlog/spdlog.h"

Expand Down Expand Up @@ -62,6 +63,7 @@ void BenchmarkRunner::runBenchmark(Benchmark* benchmark) const {
spdlog::info("Warm up");
benchmark->run();
}
profileQueryIfEnabled(benchmark);
std::vector<double> runTimes(config->numRuns);
for (auto i = 0u; i < config->numRuns; ++i) {
auto queryResult = benchmark->run();
Expand All @@ -74,5 +76,16 @@ void BenchmarkRunner::runBenchmark(Benchmark* benchmark) const {
&runTimes[0], config->numRuns, config->numRuns /* numRunsToAverage */)));
}

void BenchmarkRunner::profileQueryIfEnabled(Benchmark* benchmark) const {
if (config->enableProfile && !config->outputPath.empty()) {
auto profileInfo = benchmark->runWithProfile();
std::ofstream profileFile(
config->outputPath + "/" + benchmark->name + "_profile.txt", std::ios_base::app);
profileFile << profileInfo->getNext()->toString() << std::endl;
profileFile.flush();
profileFile.close();
}
}

} // namespace benchmark
} // namespace kuzu
1 change: 1 addition & 0 deletions tools/benchmark/include/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Benchmark {
Benchmark(const std::string& benchmarkPath, main::Database* database, BenchmarkConfig& config);

std::unique_ptr<main::QueryResult> run() const;
std::unique_ptr<main::QueryResult> runWithProfile() const;
void log(uint32_t runNum, main::QueryResult& queryResult) const;

private:
Expand Down
2 changes: 2 additions & 0 deletions tools/benchmark/include/benchmark_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class BenchmarkRunner {

void runBenchmark(Benchmark* benchmark) const;

void profileQueryIfEnabled(Benchmark* benchmark) const;

public:
std::unique_ptr<BenchmarkConfig> config;
std::unique_ptr<main::Database> database;
Expand Down
Loading