Skip to content

Commit

Permalink
MONDRIAN - enhance nativizeSet so that it can utilize the approxRowCo…
Browse files Browse the repository at this point in the history
…unt on a level instead of querying for cardinality every time.

[git-p4: depot-paths = "//open/mondrian/": change = 13215]
  • Loading branch information
Matt Campbell authored and Matt Campbell committed Dec 8, 2009
1 parent 6808269 commit 8e97f79
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/mondrian/olap/fun/NativizeSetFunDef.java
Expand Up @@ -311,7 +311,7 @@ private boolean isHighCardinality(
Level hierarchyLevel =
Util.lookupHierarchyLevel(hierarchy, levelName);
long levelCardinality =
schema.getLevelCardinality(hierarchyLevel, false, true);
getLevelCardinality(schema, hierarchyLevel);
estimatedCardinality *= levelCardinality;
if (estimatedCardinality >= nativizeMinThreshold) {
LOGGER.info(
Expand All @@ -338,6 +338,17 @@ private boolean isHighCardinality(
return isHighCardinality;
}

private long getLevelCardinality(SchemaReader schema, Level level) {
if (cardinalityIsKnown(level)) {
return level.getApproxRowCount();
}
return schema.getLevelCardinality(level, false, true);
}

private boolean cardinalityIsKnown(Level level) {
return level.getApproxRowCount() > 0;
}

private Iterable<?> evaluateJoinExpression(
Evaluator evaluator, String crossJoinExpression)
{
Expand Down
28 changes: 28 additions & 0 deletions testsrc/main/mondrian/olap/fun/NativizeSetFunDefTest.java
Expand Up @@ -1368,6 +1368,34 @@ public void testLeafMembersOfParentChildDimensionAreNativelyEvaluated() {
+ ")) on 0 from hr");
}

public void testCardinalityQueriesOnlyExecuteOnce() {
SqlPattern[] patterns = {
new SqlPattern(
Dialect.DatabaseProduct.ORACLE,
"select count(*) as \"c0\" "
+ "from (select "
+ "distinct \"customer\".\"gender\" as \"c0\" "
+ "from \"customer\" \"customer\") \"init\"",
108),
new SqlPattern(
Dialect.DatabaseProduct.ACCESS,
"select count(*) as `c0` "
+ "from (select "
+ "distinct `customer`.`gender` as `c0` "
+ "from `customer` as `customer`) as `init`",
108)
};
String mdxQuery =
"select"
+ " non empty"
+ " NativizeSet(Crossjoin("
+ "[Gender].[Gender].members,[Marital Status].[Marital Status].members"
+ ")) on 0 from Sales";
getConnection().execute(getConnection().parseQuery(mdxQuery));
assertQuerySqlOrNot(
getTestContext(), mdxQuery, patterns, true, false, false);
}

// ~ ====== Helper methods =================================================

private void checkNotNative(String mdx) {
Expand Down

0 comments on commit 8e97f79

Please sign in to comment.