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

Eliminate nondeterminism in Condition ordering #2378

Merged
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: 5 additions & 5 deletions src/ram/transform/MakeIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ Own<Condition> MakeIndexTransformer::constructPattern(const std::vector<std::str
// Define a comparator which orders all of the conditions nicely
// 1. Equalities come before inequalities
// 2. Conditions are ordered by the index of the constraint i.e. t0.0 comes before t0.1
auto cmp = [&](auto& c1, auto& c2) -> bool {
auto cmp = [&](const auto& c1, const auto& c2) -> bool {
auto* cond1 = as<Constraint>(c1);
auto* cond2 = as<Constraint>(c2);
// place non-conditions at the end
if (!cond1 && !cond2) {
return c1.get() < c2.get();
return false;
}
if (cond1 && !cond2) {
return true;
Expand All @@ -221,7 +221,7 @@ Own<Condition> MakeIndexTransformer::constructPattern(const std::vector<std::str
bool rhsIndexable = isIndexableConstraint(cond2->getOperator());

if (!lhsIndexable && !rhsIndexable) {
return c1.get() < c2.get();
return false;
}
if (lhsIndexable && !rhsIndexable) {
return true;
Expand All @@ -248,7 +248,7 @@ Own<Condition> MakeIndexTransformer::constructPattern(const std::vector<std::str
bool rhsUndefined = isUndefValue(p2.first.get()) && isUndefValue(p2.second.get());

if (lhsUndefined && rhsUndefined) {
return c1.get() < c2.get();
return false;
}

if (!lhsUndefined && rhsUndefined) {
Expand All @@ -263,7 +263,7 @@ Own<Condition> MakeIndexTransformer::constructPattern(const std::vector<std::str
return attr1 < attr2;
};

std::sort(conditionList.begin(), conditionList.end(), cmp);
std::stable_sort(conditionList.begin(), conditionList.end(), cmp);

// Build query pattern and remaining condition
bool seenInequality = false;
Expand Down
7 changes: 4 additions & 3 deletions src/ram/transform/ReorderConditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ bool ReorderConditionsTransformer::transform(TranslationUnit& tu) {
for (auto& cond : condList) {
sortedConds.emplace_back(cond->cloning());
}
std::sort(sortedConds.begin(), sortedConds.end(), [&](Own<Condition>& a, Own<Condition>& b) {
return rca.getComplexity(a.get()) < rca.getComplexity(b.get());
});
std::stable_sort(sortedConds.begin(), sortedConds.end(),
[&](const Own<Condition>& a, const Own<Condition>& b) {
return rca.getComplexity(a.get()) < rca.getComplexity(b.get());
});
auto sorted_node = toCondition(sortedConds);

if (sorted_node != node) {
Expand Down