Skip to content

Commit

Permalink
[7.x] QL: Improve removal of items during iteration (#71193) (#71272)
Browse files Browse the repository at this point in the history
Clean-up the range optimization rule by avoid the use of indices during
iteration and removal (since it skips an element each time)
Remove redundant ternary calls
  • Loading branch information
costin authored Apr 3, 2021
1 parent cbdc048 commit ae890e4
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ private Expression propagate(And and) {
for (BinaryComparison eq : equals) {
Object eqValue = eq.right().fold();

for (int i = 0; i < ranges.size(); i++) {
Range range = ranges.get(i);
for (Iterator<Range> iterator = ranges.iterator(); iterator.hasNext(); ) {
Range range = iterator.next();

if (range.value().semanticEquals(eq.left())) {
// if equals is outside the interval, evaluate the whole expression to FALSE
Expand Down Expand Up @@ -373,7 +373,7 @@ private Expression propagate(And and) {
}

// it's in the range and thus, remove it
ranges.remove(i);
iterator.remove();
changed = true;
}
}
Expand Down Expand Up @@ -789,8 +789,7 @@ private static boolean findExistingRange(Range main, List<Range> ranges, boolean
if (conjunctive) {
// can tighten range
if (lower || upper) {
ranges.remove(i);
ranges.add(i,
ranges.set(i,
new Range(main.source(), main.value(),
lower ? main.lower() : other.lower(),
lower ? main.includeLower() : other.includeLower(),
Expand All @@ -806,13 +805,12 @@ private static boolean findExistingRange(Range main, List<Range> ranges, boolean
else {
// can loosen range
if (lower && upper) {
ranges.remove(i);
ranges.add(i,
ranges.set(i,
new Range(main.source(), main.value(),
lower ? main.lower() : other.lower(),
lower ? main.includeLower() : other.includeLower(),
upper ? main.upper() : other.upper(),
upper ? main.includeUpper() : other.includeUpper(),
main.lower(),
main.includeLower(),
main.upper(),
main.includeUpper(),
main.zoneId()));
return true;
}
Expand Down Expand Up @@ -844,8 +842,7 @@ private boolean findConjunctiveComparisonInRange(BinaryComparison main, List<Ran
boolean lower = comp > 0 || lowerEq;

if (lower) {
ranges.remove(i);
ranges.add(i,
ranges.set(i,
new Range(other.source(), other.value(),
main.right(), lowerEq ? false : main instanceof GreaterThanOrEqual,
other.upper(), other.includeUpper(), other.zoneId()));
Expand All @@ -865,8 +862,7 @@ private boolean findConjunctiveComparisonInRange(BinaryComparison main, List<Ran
boolean upper = comp < 0 || upperEq;

if (upper) {
ranges.remove(i);
ranges.add(i, new Range(other.source(), other.value(),
ranges.set(i, new Range(other.source(), other.value(),
other.lower(), other.includeLower(),
main.right(), upperEq ? false : main instanceof LessThanOrEqual, other.zoneId()));
}
Expand Down

0 comments on commit ae890e4

Please sign in to comment.