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

GEODE-9632: fix for queries with multy operations and indexes #7824

Merged
merged 2 commits into from Jul 29, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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);
}

}

}