From 44d92c8a53c286f288bc0d97b706f44ef8aa1068 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 2 Apr 2007 14:15:27 +0000 Subject: Weak matches changed to extra matches. --- .../com/amazon/carbonado/qe/FilteringScore.java | 83 ++++++++++++---------- 1 file changed, 44 insertions(+), 39 deletions(-) (limited to 'src/main/java/com/amazon/carbonado') diff --git a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java index 1af294c..5ea6009 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java @@ -206,17 +206,23 @@ public class FilteringScore { indexProperties[indexPropPos].getDirection() == Direction.DESCENDING; } - List> weakMatchFilters = null; - if (!filterList.isEmpty()) { - // Any remainder property which is provided by the index is a weak match. + List> extraMatchFilters = null; + + boolean checkForExtraMatches = !filterList.isEmpty() + && (identityFilters.size() > 0 + || rangeStartFilters.size() > 0 + || rangeEndFilters.size() > 0); + + if (checkForExtraMatches) { + // Any remainder property which is provided by the index is an extra match. for (PropertyFilter subFilter : filterList) { ChainedProperty filterProp = subFilter.getChainedProperty(); for (OrderedProperty indexProp : indexProperties) { if (indexProp.getChainedProperty().equals(filterProp)) { - if (weakMatchFilters == null) { - weakMatchFilters = new ArrayList>(); + if (extraMatchFilters == null) { + extraMatchFilters = new ArrayList>(); } - weakMatchFilters.add(subFilter); + extraMatchFilters.add(subFilter); } } } @@ -231,7 +237,7 @@ public class FilteringScore { arrangementScore, preferenceScore, filterList, - weakMatchFilters, + extraMatchFilters, shouldReverseRange); } @@ -292,14 +298,14 @@ public class FilteringScore { private final BigInteger mPreferenceScore; private final List> mRemainderFilters; - private final List> mWeakMatchFilters; + private final List> mExtraMatchFilters; private final boolean mShouldReverseRange; private transient Filter mIdentityFilter; private transient Filter mRemainderFilter; - private transient Filter mWeakMatchFilter; - private transient Filter mWeakMatchRemainderFilter; + private transient Filter mExtraMatchFilter; + private transient Filter mExtraMatchRemainderFilter; private FilteringScore(boolean indexClustered, boolean indexUnique, @@ -310,7 +316,7 @@ public class FilteringScore { int arrangementScore, BigInteger preferenceScore, List> remainderFilters, - List> weakMatchFilters, + List> extraMatchFilters, boolean shouldReverseRange) { mIndexClustered = indexClustered; @@ -322,7 +328,7 @@ public class FilteringScore { mArrangementScore = arrangementScore; mPreferenceScore = preferenceScore; mRemainderFilters = prepareList(remainderFilters); - mWeakMatchFilters = prepareList(weakMatchFilters); + mExtraMatchFilters = prepareList(extraMatchFilters); mShouldReverseRange = shouldReverseRange; } @@ -541,45 +547,46 @@ public class FilteringScore { } /** - * Returns number of property filters which are weakly supported by the - * evaluated index. This count is no more than the remainder count. + * Returns number of extra property filters which are supported by the + * evaluated index. This count is no more than the remainder count. If + * hasAnyMatches returns false, then the extra match count is zero. */ - public int getWeakMatchCount() { - return mWeakMatchFilters.size(); + public int getExtraMatchCount() { + return mExtraMatchFilters.size(); } /** - * Returns the filters which are weakly supported by the evaluated index, + * Returns the extra filters which are supported by the evaluated index, * which is a subset of the remainder filters. */ - public List> getWeakMatchFilters() { - return mWeakMatchFilters; + public List> getExtraMatchFilters() { + return mExtraMatchFilters; } /** - * Returns the composite weak match filter supported by the evaluated - * index, or null if no weak match. + * Returns the composite extra match filter supported by the evaluated + * index, or null if no extra match. */ - public Filter getWeakMatchFilter() { - if (mWeakMatchFilter == null) { - mWeakMatchFilter = buildCompositeFilter(getWeakMatchFilters()); + public Filter getExtraMatchFilter() { + if (mExtraMatchFilter == null) { + mExtraMatchFilter = buildCompositeFilter(getExtraMatchFilters()); } - return mWeakMatchFilter; + return mExtraMatchFilter; } /** - * Returns the composite remainder filter without including the weak match + * Returns the composite remainder filter without including the extra match * filter. Returns null if no remainder. */ - public Filter getWeakMatchRemainderFilter() { - if (mWeakMatchRemainderFilter == null) { + public Filter getExtraMatchRemainderFilter() { + if (mExtraMatchRemainderFilter == null) { List> remainderFilters = mRemainderFilters; - List> weakMatchFilters = mWeakMatchFilters; - if (weakMatchFilters.size() < remainderFilters.size()) { + List> extraMatchFilters = mExtraMatchFilters; + if (extraMatchFilters.size() < remainderFilters.size()) { Filter composite = null; for (int i=0; i subFilter = remainderFilters.get(i); - if (!weakMatchFilters.contains(subFilter)) { + if (!extraMatchFilters.contains(subFilter)) { if (composite == null) { composite = subFilter; } else { @@ -587,10 +594,10 @@ public class FilteringScore { } } } - mWeakMatchRemainderFilter = composite; + mExtraMatchRemainderFilter = composite; } } - return mWeakMatchRemainderFilter; + return mExtraMatchRemainderFilter; } /** @@ -664,7 +671,7 @@ public class FilteringScore { ", hasRangeStart=" + hasRangeStart() + ", hasRangeEnd=" + hasRangeEnd() + ", remainderCount=" + getRemainderCount() + - ", weakMatchCount=" + getWeakMatchCount() + + ", extraMatchCount=" + getExtraMatchCount() + '}'; } @@ -796,15 +803,13 @@ public class FilteringScore { return 1; } - /* FIXME: utilize weak matches in index scans - // Favor index which contains more weak matches. - if (first.getWeakMatchCount() > second.getWeakMatchCount()) { + // Favor index which contains more extra matches. + if (first.getExtraMatchCount() > second.getExtraMatchCount()) { return -1; } - if (first.getWeakMatchCount() < second.getWeakMatchCount()) { + if (first.getExtraMatchCount() < second.getExtraMatchCount()) { return 1; } - */ // Favor index with fewer properties, under the assumption that fewer // properties means smaller sized records that need to be read in. -- cgit v1.2.3