-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create the optimizer framework (#219)
Create the optimizer framework
- Loading branch information
Showing
7 changed files
with
57 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "QueryOptimizer.h" | ||
|
||
#include <vector> | ||
|
||
// Run the optimization pases on subqueries. | ||
// After this step, every subquery should be maximally optimized, | ||
// So I believe there's no need to run this in a loop. | ||
Query simplify_subqueries(Query &&q) { | ||
// q_optimize ensures QueryType is not PRIMITIVE already | ||
std::vector<Query> newqueries; | ||
for (auto &&query : q.as_queries()) { | ||
newqueries.emplace_back(q_optimize(std::move(query))); | ||
} | ||
if (q.get_type() == QueryType::MIN_OF) { | ||
return q_min_of(q.as_count(), std::move(newqueries)); | ||
} | ||
return std::move(Query(q.get_type(), std::move(newqueries))); | ||
} | ||
|
||
Query q_optimize(Query &&q) { | ||
if (q.get_type() == QueryType::PRIMITIVE) { | ||
// Nothing to improve here. | ||
return std::move(q); | ||
} | ||
|
||
q = simplify_subqueries(std::move(q)); | ||
|
||
// Optimization passes will be added here later. | ||
|
||
return std::move(q); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "Query.h" | ||
|
||
// Optimizes a query, and returns the optimized version. | ||
// Optimizations try to simplify the expression in various ways to make the | ||
// execution faster - for example by enabling short-circuiting in some places. | ||
Query q_optimize(Query &&query); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters