Author: shawkins
Date: 2011-07-22 15:03:28 -0400 (Fri, 22 Jul 2011)
New Revision: 3329
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-1645 re-enabling agg rewrite optimization
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-22
18:50:01 UTC (rev 3328)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-07-22
19:03:28 UTC (rev 3329)
@@ -2362,7 +2362,8 @@
expression.setAggregateFunction(Type.MAX);
}
}
- if (rewriteAggs && expression.getExpression() != null &&
EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
+ if ((expression.getAggregateFunction() == Type.MAX ||
expression.getAggregateFunction() == Type.MIN)
+ && rewriteAggs && expression.getExpression() != null &&
EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
return expression.getExpression();
}
return expression;
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2011-07-22
18:50:01 UTC (rev 3328)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2011-07-22
19:03:28 UTC (rev 3329)
@@ -254,16 +254,14 @@
return false;
}
switch (getAggregateFunction()) {
- case COUNT:
- case AVG:
- case STDDEV_POP:
- case STDDEV_SAMP:
- case VAR_POP:
- case VAR_SAMP:
- case SUM:
- return true;
+ case MAX:
+ case MIN:
+ case ANY:
+ case SOME:
+ case EVERY:
+ return false;
}
- return false;
+ return true;
}
public static boolean
areAggregatesCardinalityDependent(Collection<AggregateSymbol> aggs) {
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-22
18:50:01 UTC (rev 3328)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2011-07-22
19:03:28 UTC (rev 3329)
@@ -2465,5 +2465,8 @@
helpTestRewriteCommand("select max(1) from pm1.g1 group by e1",
"SELECT 1 FROM pm1.g1 GROUP BY e1");
}
+ @Test public void testRewriteConstantAgg2() throws Exception {
+ helpTestRewriteCommand("select count(2) from pm1.g1 group by e1",
"SELECT COUNT(2) FROM pm1.g1 GROUP BY e1");
+ }
}