From 295c4484f89014235c35c7f432c5a778b703fa4f Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Tue, 10 Oct 2006 05:43:48 +0000 Subject: Removed broken (and useless) delegate merging optimization. --- .../com/amazon/carbonado/qe/FilteringScore.java | 28 ++++++++++++++++++++ .../amazon/carbonado/qe/IndexedQueryAnalyzer.java | 24 ++++++++++++++--- .../amazon/carbonado/qe/UnionQueryAnalyzer.java | 30 ++-------------------- 3 files changed, 50 insertions(+), 32 deletions(-) (limited to 'src/main/java/com/amazon') diff --git a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java index d872ec6..22a8c86 100644 --- a/src/main/java/com/amazon/carbonado/qe/FilteringScore.java +++ b/src/main/java/com/amazon/carbonado/qe/FilteringScore.java @@ -429,6 +429,34 @@ public class FilteringScore { return reduce(getRangeEndFilters(), RelOp.LE); } + /** + * Returns the count of all handled property filters. + */ + public int getHandledCount() { + return getIdentityCount() + mRangeStartFilters.size() + mRangeEndFilters.size(); + } + + /** + * Returns the composite handled filter, or null if no matches at all. + */ + public Filter getHandledFilter() { + Filter identity = getIdentityFilter(); + Filter rangeStart = buildCompositeFilter(getRangeStartFilters()); + Filter rangeEnd = buildCompositeFilter(getRangeEndFilters()); + + return and(and(identity, rangeStart), rangeEnd); + } + + private Filter and(Filter a, Filter b) { + if (a == null) { + return b; + } + if (b == null) { + return a; + } + return a.and(b); + } + /** * Returns true if there is both a range start and range end. */ diff --git a/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java b/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java index 219400c..73837a0 100644 --- a/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java +++ b/src/main/java/com/amazon/carbonado/qe/IndexedQueryAnalyzer.java @@ -428,13 +428,19 @@ public class IndexedQueryAnalyzer { return this; } + // Assuming canMergeRemainder returned true, each handled filter + // and the combined filter are all identical. This is just a safeguard. + Filter handledFilter = + orFilters(getCompositeScore().getFilteringScore().getHandledFilter(), + other.getCompositeScore().getFilteringScore().getHandledFilter()); + Filter remainderFilter = - mergeFilters(getRemainderFilter(), other.getRemainderFilter()); + orFilters(getRemainderFilter(), other.getRemainderFilter()); OrderingList remainderOrdering = getRemainderOrdering().concat(other.getRemainderOrdering()).reduce(); - Filter filter = mergeFilters(getFilter(), remainderFilter); + Filter filter = andFilters(handledFilter, remainderFilter); return new Result (filter, mScore, mLocalIndex, mForeignIndex, mForeignProperty, @@ -447,10 +453,20 @@ public class IndexedQueryAnalyzer { * doesn't usually make sense to call this method. */ public Result mergeRemainderFilter(Filter filter) { - return setRemainderFilter(mergeFilters(getRemainderFilter(), filter)); + return setRemainderFilter(orFilters(getRemainderFilter(), filter)); + } + + private Filter andFilters(Filter a, Filter b) { + if (a == null) { + return b; + } + if (b == null) { + return a; + } + return a.and(b).reduce(); } - private Filter mergeFilters(Filter a, Filter b) { + private Filter orFilters(Filter a, Filter b) { if (a == null) { return b; } diff --git a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java index b06edba..3e7a0a3 100644 --- a/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java +++ b/src/main/java/com/amazon/carbonado/qe/UnionQueryAnalyzer.java @@ -325,7 +325,7 @@ public class UnionQueryAnalyzer implements QueryExecutorFact } private Direction findHandledDirection(IndexedQueryAnalyzer.Result result, - OrderedProperty unspecified) + OrderedProperty unspecified) { ChainedProperty chained = unspecified.getChainedProperty(); OrderingScore score = result.getCompositeScore().getOrderingScore(); @@ -431,22 +431,6 @@ public class UnionQueryAnalyzer implements QueryExecutorFact return mergedResults; } - Storage storageDelegate(IndexedQueryAnalyzer.Result result) - throws SupportException, RepositoryException - { - StorableIndex localIndex = result.getLocalIndex(); - StorageAccess localAccess = mRepoAccess.storageAccessFor(getStorableType()); - - if (localIndex != null) { - return localAccess.storageDelegate(localIndex); - } - - StorableIndex foreignIndex = result.getForeignIndex(); - StorageAccess foreignAccess = mRepoAccess.storageAccessFor(foreignIndex.getStorableType()); - - return foreignAccess.storageDelegate(foreignIndex); - } - public class Result { private final List.Result> mSubResults; private final OrderingList mTotalOrdering; @@ -646,8 +630,6 @@ public class UnionQueryAnalyzer implements QueryExecutorFact IndexedQueryAnalyzer.Result subResult = mIndexAnalyzer.analyze(subFilter, mOrdering); - Storage subResultStorage = storageDelegate(subResult); - // Rather than blindly add to mSubResults, try to merge with // another result. This in turn reduces the number of cursors // needed by the union. @@ -655,15 +637,7 @@ public class UnionQueryAnalyzer implements QueryExecutorFact int size = mSubResults.size(); for (int i=0; i.Result existing = mSubResults.get(i); - boolean canMerge = existing.canMergeRemainder(subResult); - if (!canMerge) { - Storage existingStorage = storageDelegate(existing); - if (existingStorage != null && existingStorage == subResultStorage) { - // Merge common delegates together. - canMerge = true; - } - } - if (canMerge) { + if (existing.canMergeRemainder(subResult)) { mSubResults.set(i, existing.mergeRemainder(subResult)); return; } -- cgit v1.2.3