diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2006-10-10 05:43:48 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2006-10-10 05:43:48 +0000 |
commit | 295c4484f89014235c35c7f432c5a778b703fa4f (patch) | |
tree | a687d15e378bd084e1af6d4ad50d295c06723c95 /src/main/java/com/amazon/carbonado/qe | |
parent | 394ff9d981487e230816945718d67855c0c05a49 (diff) |
Removed broken (and useless) delegate merging optimization.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/qe')
3 files changed, 50 insertions, 32 deletions
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 @@ -430,6 +430,34 @@ public class FilteringScore<S extends Storable> { }
/**
+ * 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<S> getHandledFilter() {
+ Filter<S> identity = getIdentityFilter();
+ Filter<S> rangeStart = buildCompositeFilter(getRangeStartFilters());
+ Filter<S> rangeEnd = buildCompositeFilter(getRangeEndFilters());
+
+ return and(and(identity, rangeStart), rangeEnd);
+ }
+
+ private Filter<S> and(Filter<S> a, Filter<S> 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.
*/
public boolean hasRangeMatch() {
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<S extends Storable> { return this;
}
+ // Assuming canMergeRemainder returned true, each handled filter
+ // and the combined filter are all identical. This is just a safeguard.
+ Filter<S> handledFilter =
+ orFilters(getCompositeScore().getFilteringScore().getHandledFilter(),
+ other.getCompositeScore().getFilteringScore().getHandledFilter());
+
Filter<S> remainderFilter =
- mergeFilters(getRemainderFilter(), other.getRemainderFilter());
+ orFilters(getRemainderFilter(), other.getRemainderFilter());
OrderingList<S> remainderOrdering =
getRemainderOrdering().concat(other.getRemainderOrdering()).reduce();
- Filter<S> filter = mergeFilters(getFilter(), remainderFilter);
+ Filter<S> filter = andFilters(handledFilter, remainderFilter);
return new Result
(filter, mScore, mLocalIndex, mForeignIndex, mForeignProperty,
@@ -447,10 +453,20 @@ public class IndexedQueryAnalyzer<S extends Storable> { * doesn't usually make sense to call this method.
*/
public Result mergeRemainderFilter(Filter<S> filter) {
- return setRemainderFilter(mergeFilters(getRemainderFilter(), filter));
+ return setRemainderFilter(orFilters(getRemainderFilter(), filter));
+ }
+
+ private Filter<S> andFilters(Filter<S> a, Filter<S> b) {
+ if (a == null) {
+ return b;
+ }
+ if (b == null) {
+ return a;
+ }
+ return a.and(b).reduce();
}
- private Filter<S> mergeFilters(Filter<S> a, Filter<S> b) {
+ private Filter<S> orFilters(Filter<S> a, Filter<S> 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<S extends Storable> implements QueryExecutorFact }
private Direction findHandledDirection(IndexedQueryAnalyzer<S>.Result result,
- OrderedProperty unspecified)
+ OrderedProperty<S> unspecified)
{
ChainedProperty<S> chained = unspecified.getChainedProperty();
OrderingScore<S> score = result.getCompositeScore().getOrderingScore();
@@ -431,22 +431,6 @@ public class UnionQueryAnalyzer<S extends Storable> implements QueryExecutorFact return mergedResults;
}
- Storage storageDelegate(IndexedQueryAnalyzer<S>.Result result)
- throws SupportException, RepositoryException
- {
- StorableIndex<S> localIndex = result.getLocalIndex();
- StorageAccess<S> 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<IndexedQueryAnalyzer<S>.Result> mSubResults;
private final OrderingList<S> mTotalOrdering;
@@ -646,8 +630,6 @@ public class UnionQueryAnalyzer<S extends Storable> implements QueryExecutorFact IndexedQueryAnalyzer<S>.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<S extends Storable> implements QueryExecutorFact int size = mSubResults.size();
for (int i=0; i<size; i++) {
IndexedQueryAnalyzer<S>.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;
}
|