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

opt2: inline_suboperations #221

Merged
merged 1 commit into from
Oct 1, 2024
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
22 changes: 22 additions & 0 deletions libursa/QueryOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ Query flatten_trivial_operations(Query &&q, bool *changed) {
return std::move(q);
}

// This optimization inlines eliglible suboperations:
// AND(AND(a, b), AND(c, d), e) --> AND(a, b, c, d, e)
// OR(OR(a, b), OR(c, d), e) --> OR(a, b, c, d, e)
Query inline_suboperations(Query &&q, bool *changed) {
if (q.get_type() != QueryType::AND && q.get_type() != QueryType::OR) {
return std::move(q);
}
std::vector<Query> newqueries;
for (auto &&query : q.as_queries()) {
if (query.get_type() == q.get_type()) {
for (auto &&subquery : query.as_queries()) {
newqueries.emplace_back(std::move(subquery));
}
*changed = true;
} else {
newqueries.emplace_back(std::move(query));
}
}
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.
Expand All @@ -43,6 +64,7 @@ Query q_optimize(Query &&q) {
while (changed) {
changed = false;
q = flatten_trivial_operations(std::move(q), &changed);
q = inline_suboperations(std::move(q), &changed);
}

return std::move(q);
Expand Down
2 changes: 1 addition & 1 deletion libursa/Version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ constexpr std::string_view ursadb_format_version = "1.5.0";
// Project version.
// Consider updating the version tag when doing PRs.
// clang-format off
constexpr std::string_view ursadb_version_string = "@PROJECT_VERSION@+opt1";
constexpr std::string_view ursadb_version_string = "@PROJECT_VERSION@+opt2";
// clang-format on
Loading