Skip to content

Commit

Permalink
GEODE-9632: fix for queries with multy operations and indexes (#7824)
Browse files Browse the repository at this point in the history
  • Loading branch information
mivanac authored Jul 29, 2022
1 parent e2f7fe0 commit 0ecd6f6
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,15 @@ public SelectResults auxFilterEvaluate(ExecutionContext context,
List sortedConditionsList =
getCondtionsSortedOnIncreasingEstimatedIndexResultSize(context);

Boolean applyLimit = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_LIMIT_AT_INDEX);

boolean modifiedApplyLimits = false;
if (applyLimit != null && applyLimit && sortedConditionsList.size() > 1
&& _operator == LITERAL_and) {
context.cachePut(CAN_APPLY_LIMIT_AT_INDEX, Boolean.FALSE);
modifiedApplyLimits = true;
}

// Sort the operands in increasing order of resultset size
Iterator i = sortedConditionsList.iterator();
// SortedSet intersectionSet = new TreeSet(new SelectResultsComparator());
Expand All @@ -285,6 +294,12 @@ public SelectResults auxFilterEvaluate(ExecutionContext context,
// RangeJunction or a CompiledComparison. But if the parent Object is a
// RangeJunction then the Filter is a RangeJunctionEvaluator
SelectResults filterResults = null;

if (modifiedApplyLimits && sortedConditionsList.size() == 1) {
context.cachePut(CAN_APPLY_LIMIT_AT_INDEX, Boolean.TRUE);
modifiedApplyLimits = false;
}

Filter filter = (Filter) i.next();
boolean isConditioningNeeded = filter.isConditioningNeededForIndex(
indpndntItr.length == 1 ? indpndntItr[0] : null, context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,15 @@ public SelectResults auxFilterEvaluate(ExecutionContext context,
List sortedConditionsList =
getCondtionsSortedOnIncreasingEstimatedIndexResultSize(context);

Boolean applyLimit = (Boolean) context.cacheGet(CompiledValue.CAN_APPLY_LIMIT_AT_INDEX);

boolean modifiedApplyLimits = false;
if (applyLimit != null && applyLimit && sortedConditionsList.size() > 1
&& _operator == LITERAL_and) {
context.cachePut(CAN_APPLY_LIMIT_AT_INDEX, Boolean.FALSE);
modifiedApplyLimits = true;
}

// Sort the operands in increasing order of resultset size
Iterator sortedConditionsItr = sortedConditionsList.iterator();
while (sortedConditionsItr.hasNext()) {
Expand All @@ -293,6 +302,12 @@ public SelectResults auxFilterEvaluate(ExecutionContext context,
// recursion being ended by evaluating auxIterEvaluate if any. The passing
// of IntermediateResult in filterEvalaute causes AND junction evaluation
// to be corrupted , if the intermediateResultset contains some value.

if (modifiedApplyLimits && sortedConditionsList.size() == 1) {
context.cachePut(CAN_APPLY_LIMIT_AT_INDEX, Boolean.TRUE);
modifiedApplyLimits = false;
}

SelectResults filterResults =
((Filter) sortedConditionsItr.next()).filterEvaluate(context, null);
if (_operator == LITERAL_and) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package org.apache.geode.cache.query.internal.index;

import static java.util.Objects.hash;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -44,6 +46,7 @@
import org.apache.geode.internal.cache.RegionEntry;
import org.apache.geode.internal.cache.Token;
import org.apache.geode.internal.cache.persistence.query.CloseableIterator;
import org.apache.geode.pdx.internal.PdxInstanceImpl;

/**
* The in-memory index storage
Expand Down Expand Up @@ -867,6 +870,48 @@ public String toString() {
+ Integer.toHexString(System.identityHashCode(this)) + ' ' + key
+ ' ' + value;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof CachedEntryWrapper)) {
return false;
}
CachedEntryWrapper object = (CachedEntryWrapper) obj;
if (!getKey().equals(object.getKey())) {
if (!(getKey() instanceof PdxInstanceImpl)) {
return false;
}
if (!(object.getKey() instanceof PdxInstanceImpl)) {
return false;
}
PdxInstanceImpl pdxkey1 = (PdxInstanceImpl) getKey();
PdxInstanceImpl pdxkey2 = (PdxInstanceImpl) object.getKey();
if (!pdxkey1.equals(pdxkey2)) {
return false;
}
}
if (!getValue().equals(object.getValue())) {
if (!(getValue() instanceof PdxInstanceImpl)) {
return false;
}
if (!(object.getValue() instanceof PdxInstanceImpl)) {
return false;
}
PdxInstanceImpl pdxvalue1 = (PdxInstanceImpl) getValue();
PdxInstanceImpl pdxvalue2 = (PdxInstanceImpl) object.getValue();
if (!pdxvalue1.equals(pdxvalue2)) {
return false;
}
}

return true;
}

@Override
public int hashCode() {
return hash(key, value);
}

}

}
Loading

0 comments on commit 0ecd6f6

Please sign in to comment.