Skip to content

Commit

Permalink
mondrian: cache expression result only if the aggregate cache has not…
Browse files Browse the repository at this point in the history
… changed.Otherwise the result could be invalid after loading additional aggregates.

[git-p4: depot-paths = "//open/mondrian/": change = 9394]
  • Loading branch information
Rushan Chen committed Jun 2, 2007
1 parent fb250c3 commit b2364dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 16 additions & 3 deletions src/main/mondrian/rolap/RolapEvaluator.java
Expand Up @@ -656,10 +656,23 @@ public Object getCachedResult(ExpCacheDescriptor cacheDescriptor) {
Object key = getExpResultCacheKey(cacheDescriptor);
Object result = root.expResultCache.get(key);
if (result == null) {
int aggregateCacheMissCountBefore = cellReader.getMissCount();
result = cacheDescriptor.evaluate(this);
root.expResultCache.put(key, result == null ? nullResult : result);
} else if (result == nullResult) {
result = null;
int aggregateCacheMissCountAfter = cellReader.getMissCount();

// Only cache the evaluation result if the evaluation did not
// use any missing aggregates. If missing aggregates are seen,
// the aggregateCacheMissCount will increase.
if (aggregateCacheMissCountBefore == aggregateCacheMissCountAfter) {
if (result == null) {
result = nullResult;
}
root.expResultCache.put(key, result);
}
} else {
if (result == nullResult) {
result = null;
}
}
return result;
}
Expand Down
16 changes: 2 additions & 14 deletions src/main/mondrian/rolap/RolapResult.java
Expand Up @@ -568,11 +568,8 @@ protected void loadMembers(List<Member[]> nonAllMembers,

if (!batchingReader.loadAggregations(query)) {
break;
} else {
// Clear expression cache if new aggregates are loaded.
evaluator.clearExpResultCache();
}

if (attempt++ > maxEvalDepth) {
throw Util.newInternal(
"Failed to load all aggregations after " +
Expand Down Expand Up @@ -764,7 +761,7 @@ private void executeBody(Query query) {
int count = 0;
while (true) {

evaluator.setCellReader(this.batchingReader);
evaluator.setCellReader(batchingReader);
executeStripe(query.axes.length - 1,
(RolapEvaluator) evaluator.push());

Expand All @@ -774,9 +771,6 @@ private void executeBody(Query query) {
// We got all of the cells we needed, so the result must be
// correct.
return;
} else {
// Clear expression cache if new aggregates are loaded.
evaluator.clearExpResultCache();
}

if (count++ > maxEvalDepth) {
Expand Down Expand Up @@ -818,9 +812,6 @@ private Object evaluateExp(Calc calc, Evaluator evaluator) {

if (!batchingReader.loadAggregations(evaluator.getQuery())) {
break;
} else {
// Clear expression cache if new aggregates are loaded.
ev.clearExpResultCache();
}

if (attempt++ > maxEvalDepth) {
Expand All @@ -835,9 +826,6 @@ private Object evaluateExp(Calc calc, Evaluator evaluator) {
// 'dirty' flag so that the caller knows that it must re-evaluate them.
if (dirty) {
batchingReader.setDirty(true);

// Clear expression cache if new aggregates are loaded.
((RolapEvaluator)evaluator).clearExpResultCache();
}

RolapEvaluator ev = (RolapEvaluator) evaluator.push();
Expand Down

0 comments on commit b2364dc

Please sign in to comment.