teiid SVN: r3066 - trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-05 15:07:59 -0400 (Tue, 05 Apr 2011)
New Revision: 3066
Modified:
trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
Log:
TEIID-1533 fixing method name
Modified: trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java
===================================================================
--- trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2011-04-05 17:46:53 UTC (rev 3065)
+++ trunk/connectors/translator-ldap/src/main/java/org/teiid/translator/ldap/LDAPExecutionFactory.java 2011-04-05 19:07:59 UTC (rev 3066)
@@ -56,7 +56,7 @@
public LDAPExecutionFactory() {
this.setMaxInCriteriaSize(1000);
- this.setMaxDependentPredicates(25); //no spec limit on query size, AD is 10MB for the query
+ this.setMaxDependentInPredicates(25); //no spec limit on query size, AD is 10MB for the query
}
@TranslatorProperty(display="Default Search Base DN", description="Default Base DN for LDAP Searches")
13 years, 9 months
teiid SVN: r3065 - in trunk: connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc and 5 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-05 13:46:53 -0400 (Tue, 05 Apr 2011)
New Revision: 3065
Modified:
trunk/api/src/main/java/org/teiid/language/Literal.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestSQLConversionVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java
Log:
TEIID-1546 adding logic to be more selective to what is marked as a bind value
Modified: trunk/api/src/main/java/org/teiid/language/Literal.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Literal.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/api/src/main/java/org/teiid/language/Literal.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -35,6 +35,7 @@
private Class<?> type;
private boolean bindValue;
private boolean multiValued;
+ private boolean isBindEligible;
public Literal(Object value, Class<?> type) {
this.value = value;
@@ -76,5 +77,19 @@
public void setType(Class<?> type) {
this.type = type;
}
+
+ /**
+ * Set by the optimizer if the literal was created by the evaluation of another expression.
+ * Setting to true will not always result in the value being handled as a bind value.
+ * That can be forced {@link #isBindValue()}
+ * @return
+ */
+ public boolean isBindEligible() {
+ return isBindEligible;
+ }
+
+ public void setBindEligible(boolean isBindEligible) {
+ this.isBindEligible = isBindEligible;
+ }
}
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -193,7 +193,7 @@
* @see org.teiid.language.visitor.SQLStringVisitor#visit(org.teiid.language.Literal)
*/
public void visit(Literal obj) {
- if (this.prepared && (replaceWithBinding || TranslatedCommand.isBindEligible(obj) || obj.isBindValue())) {
+ if (this.prepared && ((replaceWithBinding && obj.isBindEligible()) || TranslatedCommand.isBindEligible(obj) || obj.isBindValue())) {
buffer.append(UNDEFINED_PARAM);
preparedValues.add(obj);
} else {
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestSQLConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestSQLConversionVisitor.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestSQLConversionVisitor.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -22,7 +22,7 @@
package org.teiid.translator.jdbc;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -35,8 +35,8 @@
import org.teiid.dqp.internal.datamgr.TstLanguageBridgeFactory;
import org.teiid.language.LanguageObject;
import org.teiid.metadata.RuntimeMetadata;
+import org.teiid.translator.ExecutionContext;
import org.teiid.translator.TranslatorException;
-import org.teiid.translator.ExecutionContext;
/**
*/
@@ -311,28 +311,28 @@
@Test public void testPreparedStatementCreationWithUpdate() {
helpTestVisitor(getTestVDB(),
- "update parts set part_weight = 'a' where part_weight < 5", //$NON-NLS-1$
+ "update parts set part_weight = 'a' || 'b' where part_weight < 50/10", //$NON-NLS-1$
"UPDATE PARTS SET PART_WEIGHT = ? WHERE PARTS.PART_WEIGHT < ?", //$NON-NLS-1$
true);
}
@Test public void testPreparedStatementCreationWithInsert() {
helpTestVisitor(getTestVDB(),
- "insert into parts (part_weight) values (5)", //$NON-NLS-1$
+ "insert into parts (part_weight) values (50/10)", //$NON-NLS-1$
"INSERT INTO PARTS (PART_WEIGHT) VALUES (?)", //$NON-NLS-1$
true);
}
@Test public void testPreparedStatementCreationWithSelect() {
helpTestVisitor(getTestVDB(),
- "select part_name from parts where part_id not in ('x', 'y') and part_weight < 6", //$NON-NLS-1$
- "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID NOT IN (?, ?) AND PARTS.PART_WEIGHT < ?", //$NON-NLS-1$
+ "select part_name from parts where part_id not in ('x' || 'a', 'y' || 'b') and part_weight < '6'", //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_ID NOT IN (?, ?) AND PARTS.PART_WEIGHT < '6'", //$NON-NLS-1$
true);
}
@Test public void testPreparedStatementCreationWithLike() {
helpTestVisitor(getTestVDB(),
- "select part_name from parts where part_name like '%foo'", //$NON-NLS-1$
+ "select part_name from parts where part_name like '%foo' || '_'", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_NAME LIKE ?", //$NON-NLS-1$
true);
}
@@ -361,7 +361,7 @@
@Test public void testPreparedStatementCreationWithCase() {
helpTestVisitor(getTestVDB(),
- "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME='a' THEN 'b' ELSE 'c' END", //$NON-NLS-1$
+ "SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME='a' || 'b' THEN 'b' ELSE 'c' END", //$NON-NLS-1$
"SELECT PARTS.PART_NAME FROM PARTS WHERE PARTS.PART_WEIGHT = CASE WHEN PARTS.PART_NAME = ? THEN 'b' ELSE 'c' END", //$NON-NLS-1$
true);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -493,6 +493,7 @@
Literal result = new Literal(constant.getValue(), constant.getType());
result.setBindValue(constant.isMultiValued());
result.setMultiValued(constant.isMultiValued());
+ result.setBindEligible(constant.isBindEligible());
return result;
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -382,13 +382,13 @@
for (int i = 0; i < numberOfSets; i++) {
if (maxSize == 1 || i + 1 == state.replacement.size()) {
- orCrits.add(new CompareCriteria(crit.getExpression(), CompareCriteria.EQ, new Constant(iter.next())));
+ orCrits.add(new CompareCriteria(crit.getExpression(), CompareCriteria.EQ, newConstant(iter.next())));
} else {
List<Constant> vals = new ArrayList<Constant>(Math.min(state.replacement.size(), maxSize));
for (int j = 0; j < maxSize && iter.hasNext(); j++) {
Object val = iter.next();
- vals.add(new Constant(val));
+ vals.add(newConstant(val));
}
SetCriteria sc = new SetCriteria();
@@ -402,5 +402,11 @@
}
return new CompoundCriteria(CompoundCriteria.OR, orCrits);
}
+
+ private Constant newConstant(Object val) {
+ Constant c = new Constant(val);
+ c.setBindEligible(true);
+ return c;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -46,6 +46,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
@@ -172,8 +173,8 @@
*/
public class QueryRewriter {
- public static final CompareCriteria TRUE_CRITERIA = new CompareCriteria(new Constant(new Integer(1), DataTypeManager.DefaultDataClasses.INTEGER), CompareCriteria.EQ, new Constant(new Integer(1), DataTypeManager.DefaultDataClasses.INTEGER));
- public static final CompareCriteria FALSE_CRITERIA = new CompareCriteria(new Constant(new Integer(1), DataTypeManager.DefaultDataClasses.INTEGER), CompareCriteria.EQ, new Constant(new Integer(0), DataTypeManager.DefaultDataClasses.INTEGER));
+ public static final CompareCriteria TRUE_CRITERIA = new CompareCriteria(new Constant(1, DataTypeManager.DefaultDataClasses.INTEGER), CompareCriteria.EQ, new Constant(1, DataTypeManager.DefaultDataClasses.INTEGER));
+ public static final CompareCriteria FALSE_CRITERIA = new CompareCriteria(new Constant(1, DataTypeManager.DefaultDataClasses.INTEGER), CompareCriteria.EQ, new Constant(0, DataTypeManager.DefaultDataClasses.INTEGER));
public static final CompareCriteria UNKNOWN_CRITERIA = new CompareCriteria(new Constant(null, DataTypeManager.DefaultDataClasses.STRING), CompareCriteria.NE, new Constant(null, DataTypeManager.DefaultDataClasses.STRING));
private static final Map<String, String> ALIASED_FUNCTIONS = new HashMap<String, String>();
@@ -2280,7 +2281,9 @@
}
return expression;
}
+ boolean isBindEligible = true;
if(expression instanceof Function) {
+ isBindEligible = !isConstantConvert(expression);
expression = rewriteFunction((Function) expression);
} else if (expression instanceof CaseExpression) {
expression = rewriteCaseExpression((CaseExpression)expression);
@@ -2319,13 +2322,35 @@
return expression;
}
+ return evaluate(expression, isBindEligible);
+ }
+
+ private Constant evaluate(Expression expression, boolean isBindEligible)
+ throws ExpressionEvaluationException, BlockedException,
+ TeiidComponentException {
Object value = evaluator.evaluate(expression, Collections.emptyList());
if (value instanceof Constant) {
return (Constant)value; //multi valued substitution
}
- return new Constant(value, expression.getType());
+ Constant result = new Constant(value, expression.getType());
+ result.setBindEligible(isBindEligible);
+ return result;
}
+ private boolean isConstantConvert(Expression ex) {
+ if (ex instanceof Constant) {
+ return true;
+ }
+ if (!(ex instanceof Function)) {
+ return false;
+ }
+ Function f = (Function)ex;
+ if (!FunctionLibrary.isConvert(f)) {
+ return false;
+ }
+ return isConstantConvert(f.getArg(0));
+ }
+
private Expression rewriteExpression(AggregateSymbol expression) {
if (expression.isBoolean()) {
if (expression.getAggregateFunction() == Type.EVERY) {
@@ -2691,7 +2716,8 @@
if (!processing) {
param.setExpression(rewriteExpressionDirect(param.getExpression()));
} else if (!(param.getExpression() instanceof Constant)) {
- param.setExpression(new Constant(this.evaluator.evaluate(param.getExpression(), null), param.getClassType()));
+ boolean isBindEligible = !isConstantConvert(param.getExpression());
+ param.setExpression(evaluate(param.getExpression(), isBindEligible));
}
}
return storedProcedure;
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java 2011-04-05 16:58:20 UTC (rev 3064)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/Constant.java 2011-04-05 17:46:53 UTC (rev 3065)
@@ -44,6 +44,7 @@
private Object value;
private Class<?> type;
private boolean multiValued;
+ private boolean bindEligible;
/**
* Construct a typed constant. The specified value is not verified to be a value
@@ -52,7 +53,7 @@
* @param value Constant value, may be null
* @param type Type for the constant, should never be null
*/
- public Constant(Object value, Class type) {
+ public Constant(Object value, Class<?> type) {
// Set value
this.value = DataTypeManager.convertToRuntimeType(value);
@@ -194,6 +195,7 @@
public Object clone() {
Constant copy = new Constant(getValue(), getType());
copy.multiValued = multiValued;
+ copy.bindEligible = bindEligible;
return copy;
}
@@ -219,4 +221,12 @@
return ((Comparable)this.value).compareTo(o.getValue());
}
+ public boolean isBindEligible() {
+ return bindEligible;
+ }
+
+ public void setBindEligible(boolean bindEligible) {
+ this.bindEligible = bindEligible;
+ }
+
}
13 years, 9 months
teiid SVN: r3064 - in trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc: access and 2 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-04-05 12:58:20 -0400 (Tue, 05 Apr 2011)
New Revision: 3064
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SimpleJDBCExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
Log:
TEIID-1533: fixing the mismatched name to the translator property
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
@@ -151,7 +151,7 @@
setSupportsSelectDistinct(true);
setSupportsInnerJoins(true);
setMaxInCriteriaSize(DEFAULT_MAX_IN_CRITERIA);
- setMaxDependentPredicates(DEFAULT_MAX_DEPENDENT_PREDICATES);
+ setMaxDependentInPredicates(DEFAULT_MAX_DEPENDENT_PREDICATES);
}
@Override
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SimpleJDBCExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SimpleJDBCExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SimpleJDBCExecutionFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
@@ -41,7 +41,7 @@
setSupportsFullOuterJoins(false);
setSupportsOrderBy(false);
setMaxInCriteriaSize(250);
- setMaxDependentPredicates(10);
+ setMaxDependentInPredicates(10);
}
@Override
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
@@ -40,7 +40,7 @@
setSupportsOrderBy(false);
setDatabaseVersion("2003"); //$NON-NLS-1$
setMaxInCriteriaSize(JDBCExecutionFactory.DEFAULT_MAX_IN_CRITERIA);
- setMaxDependentPredicates(10); //sql length length is 64k
+ setMaxDependentInPredicates(10); //sql length length is 64k
}
@Override
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
@@ -51,7 +51,7 @@
public SQLServerExecutionFactory() {
setDatabaseVersion(V_2005);
setMaxInCriteriaSize(JDBCExecutionFactory.DEFAULT_MAX_IN_CRITERIA);
- setMaxDependentPredicates(JDBCExecutionFactory.DEFAULT_MAX_DEPENDENT_PREDICATES);
+ setMaxDependentInPredicates(JDBCExecutionFactory.DEFAULT_MAX_DEPENDENT_PREDICATES);
}
@Override
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2011-04-05 16:58:20 UTC (rev 3064)
@@ -65,7 +65,7 @@
setDatabaseVersion(TWELVE_5);
setSupportsFullOuterJoins(false);
setMaxInCriteriaSize(250);
- setMaxDependentPredicates(10);
+ setMaxDependentInPredicates(10);
}
public void start() throws TranslatorException {
13 years, 9 months
teiid SVN: r3063 - trunk/api/src/main/java/org/teiid/translator.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2011-04-05 12:53:17 -0400 (Tue, 05 Apr 2011)
New Revision: 3063
Modified:
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
Log:
TEIID-1533: fixing the mismatched name to the translator property
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-04-05 16:24:58 UTC (rev 3062)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2011-04-05 16:53:17 UTC (rev 3063)
@@ -679,7 +679,7 @@
return maxDependentInPredicates;
}
- public void setMaxDependentPredicates(int maxDependentInPredicates) {
+ public void setMaxDependentInPredicates(int maxDependentInPredicates) {
this.maxDependentInPredicates = maxDependentInPredicates;
}
13 years, 9 months
teiid SVN: r3062 - in trunk/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-05 12:24:58 -0400 (Tue, 05 Apr 2011)
New Revision: 3062
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
Log:
TEIID-1545 expanding the order by optimization to compensate for unrelated sorts and pushdown of order by regardless of the use of limits
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-04-05 14:48:29 UTC (rev 3061)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2011-04-05 16:24:58 UTC (rev 3062)
@@ -211,7 +211,7 @@
if (NewCalculateCostUtil.usesKey(sourceNode, expressions, metadata)) {
joinNode.setProperty(joinNode.getFirstChild() == childNode ? NodeConstants.Info.IS_LEFT_DISTINCT : NodeConstants.Info.IS_RIGHT_DISTINCT, true);
}
- if (attemptPush && RuleRaiseAccess.canRaiseOverSort(sourceNode, metadata, capFinder, sortNode, null)) {
+ if (attemptPush && RuleRaiseAccess.canRaiseOverSort(sourceNode, metadata, capFinder, sortNode, null, false)) {
sourceNode.getFirstChild().addAsParent(sortNode);
if (needsCorrection) {
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java 2011-04-05 14:48:29 UTC (rev 3061)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java 2011-04-05 16:24:58 UTC (rev 3062)
@@ -58,10 +58,10 @@
AnalysisRecord analysisRecord, CommandContext context)
throws QueryPlannerException, QueryMetadataException,
TeiidComponentException {
- return optimizeSorts(false, plan, plan);
+ return optimizeSorts(false, plan, plan, metadata, capabilitiesFinder, analysisRecord);
}
- private PlanNode optimizeSorts(boolean parentBlocking, PlanNode node, PlanNode root) {
+ private PlanNode optimizeSorts(boolean parentBlocking, PlanNode node, PlanNode root, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord record) throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
node = NodeEditor.findNodePreOrder(node,
NodeConstants.Types.SORT
| NodeConstants.Types.DUP_REMOVE
@@ -79,10 +79,8 @@
}
if (mergeSortWithDupRemoval(node)) {
node.setProperty(NodeConstants.Info.IS_DUP_REMOVAL, true);
- } else if (node.getParent() != null) {
- //if we are not distinct and there is a limit, the projection could be deferred
- PlanNode parent = node.getParent();
- root = checkForProjectOptimization(node, root, parent);
+ } else {
+ root = checkForProjectOptimization(node, root, metadata, capFinder, record);
}
List<SingleElementSymbol> orderColumns = ((OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER)).getSortKeys();
PlanNode possibleSort = NodeEditor.findNodePreOrder(node, NodeConstants.Types.GROUP, NodeConstants.Types.SOURCE | NodeConstants.Types.ACCESS);
@@ -207,21 +205,32 @@
break;
}
for (PlanNode child : node.getChildren()) {
- root = optimizeSorts(parentBlocking, child, root);
+ root = optimizeSorts(parentBlocking, child, root, metadata, capFinder, record);
}
return root;
}
- private PlanNode checkForProjectOptimization(PlanNode node, PlanNode root,
- PlanNode parent) {
- if (parent.getType() != NodeConstants.Types.TUPLE_LIMIT) {
- return root;
- }
+ private PlanNode checkForProjectOptimization(PlanNode node, PlanNode root,
+ QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord record) throws QueryMetadataException, TeiidComponentException, QueryPlannerException {
PlanNode projectNode = node.getFirstChild();
- //if (child.getType() == NodeConstants.Types.ACCESS) {
- //TODO: there should be a cost based evaluation if this looks like ACCESS->PROJECT and we attempt to raise project expressions
- //}
- if (projectNode.getType() != NodeConstants.Types.PROJECT || projectNode.getFirstChild() == null) {
+ PlanNode parent = node.getParent();
+ boolean raiseAccess = false;
+ //special check for unrelated order by compensation
+ if (projectNode.getType() == NodeConstants.Types.ACCESS && RuleRaiseAccess.canRaiseOverSort(projectNode.getFirstChild(), metadata, capFinder, node, record, true)) {
+ projectNode = NodeEditor.findNodePreOrder(projectNode, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE);
+ if (projectNode == null) {
+ return root; //shouldn't happen
+ }
+ raiseAccess = true;
+ } else if (projectNode.getType() == NodeConstants.Types.PROJECT && projectNode.getFirstChild() != null) {
+ raiseAccess = projectNode.getFirstChild().getType() == NodeConstants.Types.ACCESS
+ && RuleRaiseAccess.canRaiseOverSort(projectNode.getFirstChild(), metadata, capFinder, node, record, false);
+
+ //if we can't raise the access node and this doesn't have a limit, there's no point in optimizing
+ if (!raiseAccess && (parent == null || parent.getType() != NodeConstants.Types.TUPLE_LIMIT)) {
+ return root;
+ }
+ } else {
return root;
}
List<SingleElementSymbol> childOutputCols = (List<SingleElementSymbol>) projectNode.getFirstChild().getProperty(Info.OUTPUT_COLS);
@@ -230,13 +239,21 @@
if (!childOutputCols.containsAll(orderByKeys)) {
return root;
}
- //move the project before the ordered limit
- NodeEditor.removeChildNode(node, projectNode);
- if (parent.getParent() != null) {
- parent.addAsParent(node);
+ NodeEditor.removeChildNode(projectNode.getParent(), projectNode);
+ if (parent != null && parent.getType() == NodeConstants.Types.TUPLE_LIMIT && parent.getParent() != null) {
+ parent.addAsParent(projectNode);
} else {
- root = projectNode;
- projectNode.addFirstChild(parent);
+ if (parent == null) {
+ root = projectNode;
+ }
+ if (parent != null && parent.getType() == NodeConstants.Types.TUPLE_LIMIT) {
+ if (root == parent) {
+ root = projectNode;
+ }
+ projectNode.addFirstChild(parent);
+ } else {
+ projectNode.addFirstChild(node);
+ }
}
List<SingleElementSymbol> orderByOutputSymbols = (List<SingleElementSymbol>) node.getProperty(Info.OUTPUT_COLS);
if (node.hasBooleanProperty(Info.UNRELATED_SORT)) {
@@ -250,7 +267,16 @@
projectNode.setProperty(Info.OUTPUT_COLS, orderByOutputSymbols);
projectNode.setProperty(Info.PROJECT_COLS, orderByOutputSymbols);
node.setProperty(Info.OUTPUT_COLS, childOutputCols);
- parent.setProperty(Info.OUTPUT_COLS, childOutputCols);
+ if (parent != null) {
+ parent.setProperty(Info.OUTPUT_COLS, childOutputCols);
+ }
+ if (raiseAccess) {
+ PlanNode accessNode = node.getFirstChild();
+ root = RuleRaiseAccess.raiseAccessNode(root, accessNode, metadata, capFinder, true, record);
+ if (accessNode.getParent().getType() == NodeConstants.Types.TUPLE_LIMIT) {
+ root = RulePushLimit.raiseAccessOverLimit(root, accessNode, metadata, capFinder, accessNode.getParent());
+ }
+ }
return root;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2011-04-05 14:48:29 UTC (rev 3061)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2011-04-05 16:24:58 UTC (rev 3062)
@@ -154,7 +154,7 @@
}
case NodeConstants.Types.SORT:
{
- if (canRaiseOverSort(accessNode, metadata, capFinder, parentNode, record)) {
+ if (canRaiseOverSort(accessNode, metadata, capFinder, parentNode, record, false)) {
return performRaise(rootNode, accessNode, parentNode);
}
return null;
@@ -333,7 +333,7 @@
static boolean canRaiseOverSort(PlanNode accessNode,
QueryMetadataInterface metadata,
CapabilitiesFinder capFinder,
- PlanNode parentNode, AnalysisRecord record) throws QueryMetadataException,
+ PlanNode parentNode, AnalysisRecord record, boolean compensateForUnrelated) throws QueryMetadataException,
TeiidComponentException {
// Find the model for this node by getting ACCESS node's model
Object modelID = getModelIDFromAccess(accessNode, metadata);
@@ -395,11 +395,10 @@
return false;
}
- /* If we have an unrelated sort it cannot be pushed down if it's not supported by the source
- *
- * TODO: we should be able to work this
- */
- if (parentNode.hasBooleanProperty(NodeConstants.Info.UNRELATED_SORT) && !CapabilitiesUtil.supports(Capability.QUERY_ORDERBY_UNRELATED, modelID, metadata, capFinder)) {
+ if (parentNode.hasBooleanProperty(NodeConstants.Info.UNRELATED_SORT)
+ && !CapabilitiesUtil.supports(Capability.QUERY_ORDERBY_UNRELATED, modelID, metadata, capFinder)
+ && NodeEditor.findParent(accessNode, NodeConstants.Types.PROJECT, NodeConstants.Types.SOURCE) == null
+ && !compensateForUnrelated) {
return false;
}
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-04-05 14:48:29 UTC (rev 3061)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2011-04-05 16:24:58 UTC (rev 3062)
@@ -56,6 +56,7 @@
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.relational.AccessNode;
import org.teiid.query.processor.relational.DependentAccessNode;
+import org.teiid.query.processor.relational.EnhancedSortMergeJoinStrategy;
import org.teiid.query.processor.relational.GroupingNode;
import org.teiid.query.processor.relational.JoinNode;
import org.teiid.query.processor.relational.JoinStrategy;
@@ -63,7 +64,6 @@
import org.teiid.query.processor.relational.NestedLoopJoinStrategy;
import org.teiid.query.processor.relational.NestedTableJoinStrategy;
import org.teiid.query.processor.relational.NullNode;
-import org.teiid.query.processor.relational.EnhancedSortMergeJoinStrategy;
import org.teiid.query.processor.relational.PlanExecutionNode;
import org.teiid.query.processor.relational.ProjectIntoNode;
import org.teiid.query.processor.relational.ProjectNode;
@@ -1557,33 +1557,6 @@
}
/**
- * Tests that query transformation order by is discarded by
- * user order by, and that user order by is discarded because
- * of the function in the query transformation
- */
- @Test public void testPushOrderByThroughFrame3() {
- ProcessorPlan plan = helpPlan("SELECT e, e2 FROM vm1.g16 ORDER BY e2", FakeMetadataFactory.example1Cached(), //$NON-NLS-1$
- new String[] { "SELECT e1, e2 FROM pm3.g1"}); //$NON-NLS-1$
-
- checkNodeTypes(plan, new int[] {
- 1, // Access
- 0, // DependentAccess
- 0, // DependentSelect
- 0, // DependentProject
- 0, // DupRemove
- 0, // Grouping
- 0, // NestedLoopJoinStrategy
- 0, // MergeJoinStrategy
- 0, // Null
- 0, // PlanExecution
- 1, // Project
- 0, // Select
- 1, // Sort
- 0 // UnionAll
- });
- }
-
- /**
* Tests that a user's order by does not get pushed to the source
* if there is a UNION in the query transformation
*/
@@ -3610,11 +3583,11 @@
checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
}
- @Test public void testBQT9500_126() {
+ @Test public void testBQT9500_126() throws Exception {
String sql = "SELECT IntKey, LongNum, expr FROM (SELECT IntKey, LongNum, concat(LongNum, 'abc') FROM BQT2.SmallA ) AS x ORDER BY IntKey"; //$NON-NLS-1$
ProcessorPlan plan = helpPlan(sql, FakeMetadataFactory.exampleBQTCached(),
new String[] {
- "SELECT IntKey, LongNum FROM BQT2.SmallA" }); //$NON-NLS-1$
+ "SELECT g_0.IntKey AS c_0, g_0.LongNum AS c_1 FROM BQT2.SmallA AS g_0 ORDER BY c_0" }, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
checkNodeTypes(plan, new int[] {
1, // Access
@@ -3629,7 +3602,7 @@
0, // PlanExecution
1, // Project
0, // Select
- 1, // Sort
+ 0, // Sort
0 // UnionAll
});
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java 2011-04-05 14:48:29 UTC (rev 3061)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java 2011-04-05 16:24:58 UTC (rev 3062)
@@ -26,10 +26,12 @@
import static org.teiid.query.optimizer.TestOptimizer.*;
import org.junit.Test;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.TestOptimizer.DupRemoveSortNode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.processor.relational.LimitNode;
import org.teiid.query.processor.relational.ProjectNode;
@@ -176,7 +178,7 @@
@Test public void testProjectionRaisingWithLimit() {
// Create query
- String sql = "select e1, (select e1 from pm2.g1 where e2 = x.e2) from pm1.g1 as x order by e2 limit 2"; //$NON-NLS-1$
+ String sql = "select e1, (select e1 from pm2.g1 where e2 = x.e2) from pm1.g1 as x order by e1 limit 2"; //$NON-NLS-1$
RelationalPlan plan = (RelationalPlan)helpPlan(sql, FakeMetadataFactory.example1Cached(), null, new DefaultCapabilitiesFinder(),
new String[] {"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1"}, TestOptimizer.SHOULD_SUCCEED); //$NON-NLS-1$
@@ -193,5 +195,42 @@
assertTrue(plan.getRootNode() instanceof LimitNode);
}
+
+ @Test public void testProjectionRaisingWithAccess() throws Exception {
+ // Create query
+ String sql = "select e1, (select e1 from pm2.g1 where e2 = x.e2) as z from pm1.g1 as x order by e1"; //$NON-NLS-1$
+ helpPlan(sql, FakeMetadataFactory.example1Cached(), null, TestOptimizer.getGenericFinder(),
+ new String[] {"SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ }
+
+ @Test public void testProjectionRaisingForUnrelatedWithLimit() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+ String sql = "select (select e1 from pm2.g1 where e2 = x.e2) as z from pm1.g1 as x order by e1 limit 1"; //$NON-NLS-1$
+
+ helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT pm1.g1.e1, pm1.g1.e2 FROM pm1.g1 ORDER BY pm1.g1.e1 LIMIT 1"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ }
+
+ @Test public void testProjectionRaisingForUnrelated() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+ String sql = "select e2 from pm1.g1 as x order by e1"; //$NON-NLS-1$
+
+ helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT pm1.g1.e2, pm1.g1.e1 FROM pm1.g1 ORDER BY pm1.g1.e1"}, ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ }
+
+
}
13 years, 9 months
teiid SVN: r3061 - in trunk/engine/src: test/java/org/teiid/query/optimizer/relational/rules and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-05 10:48:29 -0400 (Tue, 05 Apr 2011)
New Revision: 3061
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
Log:
TEIID-1533 ensuring that larger tables when used by themselves have a better ndv estimate
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2011-04-05 02:39:40 UTC (rev 3060)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2011-04-05 14:48:29 UTC (rev 3061)
@@ -805,17 +805,18 @@
}
if (ndv == UNKNOWN_VALUE) {
- ndv = 3;
if (multiGroup) {
if (usesKey) {
ndv = (float)Math.ceil(Math.sqrt(childCost));
} else {
ndv = (float)Math.ceil(Math.sqrt(childCost)/4);
}
- ndv = Math.max(ndv, 1);
} else if (usesKey) {
ndv = childCost;
+ } else {
+ ndv = (float)Math.ceil(Math.sqrt(childCost)/2);
}
+ ndv = Math.max(ndv, 1);
}
boolean isNegatedPredicateCriteria = false;
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java 2011-04-05 02:39:40 UTC (rev 3060)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCalculateCostUtil.java 2011-04-05 14:48:29 UTC (rev 3061)
@@ -133,7 +133,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 NOT LIKE '#_'"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 200, metadata);
+ helpTestEstimateCost(critString, 300, 233, metadata);
}
/**
@@ -166,7 +166,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IS NULL"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 100, metadata);
+ helpTestEstimateCost(critString, 300, 33, metadata);
}
/**
@@ -177,7 +177,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IS NOT NULL"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 200, metadata);
+ helpTestEstimateCost(critString, 300, 266, metadata);
}
/**
@@ -235,7 +235,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 IN ('2', '3')"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 200, metadata);
+ helpTestEstimateCost(critString, 300, 66, metadata);
}
/**
@@ -247,7 +247,7 @@
QueryMetadataInterface metadata = FakeMetadataFactory.example4();
String critString = "pm2.g3.e1 NOT IN ('2', '3')"; //$NON-NLS-1$
- helpTestEstimateCost(critString, 300, 100, metadata);
+ helpTestEstimateCost(critString, 300, 233, metadata);
}
/**
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java 2011-04-05 02:39:40 UTC (rev 3060)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestRuleChooseDependent.java 2011-04-05 14:48:29 UTC (rev 3061)
@@ -64,6 +64,7 @@
import org.teiid.query.unittest.FakeMetadataObject;
import org.teiid.query.util.CommandContext;
+@SuppressWarnings("unchecked")
public class TestRuleChooseDependent {
/* Make Left Side Dependent */
@@ -566,7 +567,7 @@
atomicCrit2a,
atomicJoinCrits2,
crits,
- expected, -1, 57734);
+ expected, -1, 7930);
}
/**
Modified: trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java 2011-04-05 02:39:40 UTC (rev 3060)
+++ trunk/engine/src/test/java/org/teiid/query/processor/xml/TestXMLPlanningEnhancements.java 2011-04-05 14:48:29 UTC (rev 3061)
@@ -488,7 +488,7 @@
String expectedDoc = TestXMLProcessor.readFile("TestXMLProcessor-FullSuppliers.xml"); //$NON-NLS-1$
- XMLPlan xmlPlan = (XMLPlan)TestXMLProcessor.helpTestProcess("SELECT * FROM xmltest.docJoin", expectedDoc, metadata, dataMgr); //$NON-NLS-1$
+ XMLPlan xmlPlan = (XMLPlan)TestXMLProcessor.helpTestProcess("SELECT * FROM xmltest.docJoin", metadata, dataMgr, null, TestOptimizer.getGenericFinder(false), expectedDoc); //$NON-NLS-1$
Map stats = XMLProgramUtil.getProgramStats(xmlPlan.getOriginalProgram());
List list = (List)stats.get(ExecSqlInstruction.class);
13 years, 9 months
teiid SVN: r3060 - in trunk/engine/src: test/java/org/teiid/dqp/internal/process and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-04 22:39:40 -0400 (Mon, 04 Apr 2011)
New Revision: 3060
Added:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidator.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRoleAuthorizationValidator.java
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1327 created an AuthorizationValidator interface
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidator.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidator.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.sql.lang.Command;
+
+/**
+ * Defines a validator that checks for proper authorization.
+ */
+public interface AuthorizationValidator {
+
+ void validate(Command command, QueryMetadataInterface metadata,
+ DQPWorkContext workContext) throws QueryValidatorException, TeiidComponentException;
+
+ boolean hasRole(String roleName, DQPWorkContext workContext);
+}
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/AuthorizationValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -54,6 +54,8 @@
private CacheConfiguration resultsetCacheConfig;
private int maxODBCLobSizeAllowed = 5*1024*1024; // 5 MB
private int userRequestSourceConcurrency = DEFAULT_USER_REQUEST_SOURCE_CONCURRENCY;
+
+ private AuthorizationValidator authorizationValidator;
@ManagementProperty(description="Max active plans (default 20). Increase this value, and max threads, on highly concurrent systems - but ensure that the underlying pools can handle the increased load without timeouts.")
public int getMaxActivePlans() {
@@ -209,4 +211,13 @@
public void setMaxODBCLobSizeAllowed(int lobSize) {
this.maxODBCLobSizeAllowed = lobSize;
}
+
+ public AuthorizationValidator getAuthorizationValidator() {
+ return authorizationValidator;
+ }
+
+ public void setAuthorizationValidator(
+ AuthorizationValidator authorizationValidator) {
+ this.authorizationValidator = authorizationValidator;
+ }
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -191,6 +191,8 @@
private CacheFactory cacheFactory;
private SessionAwareCache<CachedResults> matTables;
+
+ private AuthorizationValidator authorizationValidator;
/**
* perform a full shutdown and wait for 10 seconds for all threads to finish
@@ -319,9 +321,9 @@
ClientState state = this.getClientState(workContext.getSessionId(), true);
request.initialize(requestMsg, bufferManager,
dataTierMgr, transactionService, state.sessionTables,
- workContext, this.config.getUseDataRoles(), this.prepPlanCache);
+ workContext, this.prepPlanCache);
request.setResultSetCacheEnabled(this.rsCache != null);
- request.setAllowCreateTemporaryTablesByDefault(this.config.isAllowCreateTemporaryTablesByDefault());
+ request.setAuthorizationValidator(this.authorizationValidator);
request.setUserRequestConcurrency(this.getUserRequestSourceConcurrency());
ResultsFuture<ResultsMessage> resultsFuture = new ResultsFuture<ResultsMessage>();
RequestWorkItem workItem = new RequestWorkItem(this, requestMsg, request, resultsFuture.getResultsReceiver(), requestID, workContext);
@@ -666,7 +668,10 @@
public void start(DQPConfiguration config) {
this.config = config;
-
+ this.authorizationValidator = config.getAuthorizationValidator();
+ if (this.authorizationValidator == null) {
+ this.authorizationValidator = new DataRoleAuthorizationValidator(config.getUseDataRoles(), config.isAllowCreateTemporaryTablesByDefault());
+ }
this.chunkSize = config.getLobChunkSizeInKB() * 1024;
//get buffer manager
Added: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRoleAuthorizationValidator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRoleAuthorizationValidator.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRoleAuthorizationValidator.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.dqp.internal.process;
+
+import org.teiid.api.exception.query.QueryValidatorException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.sql.lang.Command;
+
+/**
+ * The default Teiid authorization validator
+ */
+public class DataRoleAuthorizationValidator implements AuthorizationValidator {
+
+ private boolean useEntitlements;
+ private boolean allowCreateTemporaryTablesByDefault;
+
+ public DataRoleAuthorizationValidator(boolean useEntitlements,
+ boolean allowCreateTemporaryTablesByDefault) {
+ this.useEntitlements = useEntitlements;
+ this.allowCreateTemporaryTablesByDefault = allowCreateTemporaryTablesByDefault;
+ }
+
+ @Override
+ public void validate(Command command, QueryMetadataInterface metadata, DQPWorkContext workContext) throws QueryValidatorException, TeiidComponentException {
+ if (useEntitlements && !workContext.getVDB().getDataPolicies().isEmpty()) {
+ AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(workContext.getAllowedDataPolicies(), workContext.getUserName());
+ visitor.setAllowCreateTemporaryTablesDefault(allowCreateTemporaryTablesByDefault);
+ Request.validateWithVisitor(visitor, metadata, command);
+ }
+ }
+
+ @Override
+ public boolean hasRole(String roleName, DQPWorkContext workContext) {
+ if (!useEntitlements) {
+ return true;
+ }
+ return workContext.getAllowedDataPolicies().containsKey(roleName);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataRoleAuthorizationValidator.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -130,12 +130,11 @@
protected Command userCommand;
protected boolean returnsUpdateCount;
- protected boolean useEntitlements;
private TempTableStore globalTables;
private SessionAwareCache<PreparedPlan> planCache;
private boolean resultSetCacheEnabled = true;
- private boolean allowCreateTemporaryTablesByDefault;
private int userRequestConcurrency;
+ private AuthorizationValidator authorizationValidator;
void initialize(RequestMessage requestMsg,
BufferManager bufferManager,
@@ -143,7 +142,6 @@
TransactionService transactionService,
TempTableStore tempTableStore,
DQPWorkContext workContext,
- boolean useEntitlements,
SessionAwareCache<PreparedPlan> planCache) {
this.requestMsg = requestMsg;
@@ -157,7 +155,6 @@
this.workContext = workContext;
this.requestId = workContext.getRequestID(this.requestMsg.getExecutionId());
this.connectorManagerRepo = workContext.getVDB().getAttachment(ConnectorManagerRepository.class);
- this.useEntitlements = useEntitlements && !workContext.getVDB().getDataPolicies().isEmpty();
this.planCache = planCache;
}
@@ -171,11 +168,11 @@
this.resultSetCacheEnabled = resultSetCacheEnabled;
}
- public void setAllowCreateTemporaryTablesByDefault(
- boolean allowCreateTemporaryTablesByDefault) {
- this.allowCreateTemporaryTablesByDefault = allowCreateTemporaryTablesByDefault;
+ public void setAuthorizationValidator(
+ AuthorizationValidator authorizationValidator) {
+ this.authorizationValidator = authorizationValidator;
}
-
+
/**
* if the metadata has not been supplied via setMetadata, this method will create the appropriate state
*
@@ -250,13 +247,10 @@
context.setSecurityFunctionEvaluator(new SecurityFunctionEvaluator() {
@Override
public boolean hasRole(String roleType, String roleName) throws TeiidComponentException {
- if (!useEntitlements) {
- return true;
- }
if (!DATA_ROLE.equalsIgnoreCase(roleType)) {
return false;
}
- return workContext.getAllowedDataPolicies().containsKey(roleName);
+ return authorizationValidator.hasRole(roleName, workContext);
}
});
context.setTempTableStore(tempTableStore);
@@ -472,11 +466,7 @@
}
protected void validateAccess(Command command) throws QueryValidatorException, TeiidComponentException {
- if (useEntitlements) {
- AuthorizationValidationVisitor visitor = new AuthorizationValidationVisitor(this.workContext.getAllowedDataPolicies(), this.workContext.getUserName());
- visitor.setAllowCreateTemporaryTablesDefault(this.allowCreateTemporaryTablesByDefault);
- validateWithVisitor(visitor, this.metadata, command);
- }
+ this.authorizationValidator.validate(command, metadata, workContext);
}
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -60,9 +60,6 @@
private static final int SESSION_ID = 6;
- private static boolean DEBUG = false;
-
-
static void helpTestProcessing(String preparedSql, List values, List[] expected, ProcessorDataManager dataManager, QueryMetadataInterface metadata, boolean callableStatement, VDBMetaData vdb) throws Exception {
helpTestProcessing(preparedSql, values, expected, dataManager, metadata, callableStatement, false, vdb);
}
@@ -246,9 +243,9 @@
ConnectorManagerRepository repo = Mockito.mock(ConnectorManagerRepository.class);
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
- serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, false, prepPlanCache);
-
+ serverRequest.initialize(request, BufferManagerFactory.getStandaloneBufferManager(), null, new FakeTransactionService(), null, workContext, prepPlanCache);
serverRequest.setMetadata(capFinder, metadata, null);
+ serverRequest.setAuthorizationValidator(new DataRoleAuthorizationValidator(false, true));
serverRequest.processRequest();
assertNotNull(serverRequest.processPlan);
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestRequest.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -70,7 +70,6 @@
public void testValidateEntitlement() throws Exception {
QueryMetadataInterface metadata = FakeMetadataFactory.example1Cached();
-
Request request = new Request();
Command command = QueryParser.getQueryParser().parseCommand(QUERY);
QueryResolver.resolveCommand(command, metadata);
@@ -78,8 +77,9 @@
RequestMessage message = new RequestMessage();
DQPWorkContext workContext = FakeMetadataFactory.buildWorkContext(metadata, FakeMetadataFactory.example1VDB());
- request.initialize(message, null, null,new FakeTransactionService(),null, workContext, false, null);
+ request.initialize(message, null, null,new FakeTransactionService(),null, workContext, null);
request.initMetadata();
+ request.setAuthorizationValidator(new DataRoleAuthorizationValidator(true, true));
request.validateAccess(command);
}
@@ -132,8 +132,8 @@
Mockito.stub(repo.getConnectorManager(Mockito.anyString())).toReturn(new AutoGenDataService());
request.initialize(message, Mockito.mock(BufferManager.class),
- new FakeDataManager(), new FakeTransactionService(), null, workContext, false, null);
-
+ new FakeDataManager(), new FakeTransactionService(), null, workContext, null);
+ request.setAuthorizationValidator(new DataRoleAuthorizationValidator(false, true));
request.processRequest();
return request;
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-04-04 22:35:34 UTC (rev 3059)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-04-05 02:39:40 UTC (rev 3060)
@@ -7650,5 +7650,5 @@
helpProcess(plan, dataManager, expected);
}
- private static final boolean DEBUG = true;
+ private static final boolean DEBUG = false;
}
13 years, 9 months
teiid SVN: r3059 - in trunk: engine/src/main/java/org/teiid/common/buffer and 7 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-04 18:35:34 -0400 (Mon, 04 Apr 2011)
New Revision: 3059
Modified:
trunk/build/kits/jboss-container/teiid-releasenotes.html
trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java
trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java
Log:
TEIID-1533 adding cost based back off of dependent joins
Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html 2011-04-04 22:35:34 UTC (rev 3059)
@@ -41,13 +41,14 @@
<LI><B>InterSystems Cache</B> - InterSystems Cache database translator is now available to use as supported source under Teiid.
<LI><B>userRequestSourceConcurrency</B> - was added to control the number of concurrent source queries allowed for each user request.
<LI><B>Memory Management Improvements</B> - maxReserveBatchColumns and maxProcessingBatchesColumns will be default be determined automatically and will more reliably prevent memory issues. See the admin guide for more.
- <LI><B>Subquery optimization control</B> - added the MJ and NO_UNNEST hints and the org.teiid.subqueryUnnestDefault system property to control the optimization of subqueries to traditional joins or to a merge join implemenation of a semijoin or antijoin.
+ <LI><B>Subquery optimization control</B> - added the MJ and NO_UNNEST hints and the org.teiid.subqueryUnnestDefault system property to control the optimization of subqueries to traditional joins or to a merge join implementation of a semijoin or antijoin.
<LI><B>Local connection threads</B> - local connection calling threads will be used to process work rather than using an engine thread. This helps decouple the configuration of maxThreads.
<LI><B>Dependent Join Improvements</B> - several major improvements were made to increase performance and develop better plans.
<UL>
<LI><B>Improved Planning</B> - the decision to create a dependent join is now considered earlier in planning and is much more effective for dependent joins involving multiple unrelated independent tables.
<LI><B>IN predicate splitting</B> - the planner can now split large dependent IN predicates into multiple IN predicates, which is controlled by the translator property MaxDepdendentInPredicates. This allows for much larger dependent joins to be performed as a single query.
- <LI><B>Dependent query parallization</B> - when multiple dependent queries are still required, then they will be run in parallel (up to MaxUserSourceRequestConcurrency), rather than sequentially.
+ <LI><B>Dependent query parallization</B> - when multiple dependent queries are still required, then they will be run in parallel (up to MaxUserSourceRequestConcurrency), rather than sequentially.
+ <LI><B>Cost based back-off</B> - for cost based dependent joins if the number of independent values is too large, then the join will be performed as normal.
</UL>
<LI><B>Enhanced Sort Join</B> - the partitioned merge join was replaced with an enhanced sort join. The enhanced sort join will use the actual row counts from each side of the relation to perform a index based join if one side is small enough, a partial sort of the larger side and a repeated merge join if the tuples are unbalanced but one side is not small enough to form an index, or a standard sort merge join if the tuples are balanced.
</UL>
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -195,8 +195,12 @@
}
List key = extractKey(tuple);
int level = 0;
- if (mode != InsertMode.ORDERED || sizeHint == -1) {
- level = randomLevel();
+ if (mode != InsertMode.ORDERED) {
+ if (sizeHint > -1) {
+ level = Math.min(sizeHint, randomLevel());
+ } else {
+ level = randomLevel();
+ }
} else if (!places.isEmpty() && places.getLast().values.getTuples().size() == pageSize) {
int row = rowCount.get();
while (row != 0 && row%pageSize == 0) {
@@ -228,6 +232,18 @@
return null;
}
+ public int getExpectedHeight(int sizeHint) {
+ if (sizeHint == 0) {
+ return 0;
+ }
+ int logSize = 1;
+ while (sizeHint > this.pageSize) {
+ logSize++;
+ sizeHint/=this.pageSize;
+ }
+ return logSize;
+ }
+
List extractKey(List tuple) {
if (tuple.size() > keyLength) {
return new ArrayList(tuple.subList(0, keyLength));
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -307,7 +307,7 @@
if(modelID != null){
depAccessNode.setMaxSetSize(CapabilitiesUtil.getMaxInCriteriaSize(modelID, metadata, capFinder));
- depAccessNode.setMaxPredicates(CapabilitiesUtil.getMaxDependentPredicatesSize(modelID, metadata, capFinder));
+ depAccessNode.setMaxPredicates(CapabilitiesUtil.getMaxDependentPredicates(modelID, metadata, capFinder));
}
processNode = depAccessNode;
aNode = depAccessNode;
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -321,7 +321,7 @@
return value;
}
- public static int getMaxDependentPredicatesSize(Object modelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
+ public static int getMaxDependentPredicates(Object modelID, QueryMetadataInterface metadata, CapabilitiesFinder capFinder)
throws QueryMetadataException, TeiidComponentException {
return getProperty(Capability.MAX_DEPENDENT_PREDICATES, modelID, metadata, capFinder);
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -365,7 +365,7 @@
if (leftExpressions.isEmpty()) {
return null;
}
- return NewCalculateCostUtil.computeCostForDepJoin(indNode, depNode, leftExpressions, rightExpressions, metadata, capFinder, context);
+ return NewCalculateCostUtil.computeCostForDepJoin(indNode, depNode, leftExpressions, rightExpressions, metadata, capFinder, context).expectedCardinality;
}
/**
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -97,6 +97,12 @@
NDV,
NNV
}
+
+ public static class DependentCostAnalysis {
+ Float[] maxNdv;
+ Float[] expectedNdv;
+ Float expectedCardinality;
+ }
@SuppressWarnings("serial")
private static class ColStats extends LinkedHashMap<Expression, float[]> {
@@ -1112,7 +1118,7 @@
* @throws QueryPlannerException
*
*/
- public static Float computeCostForDepJoin(PlanNode joinNode, boolean leftIndependent, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context)
+ public static DependentCostAnalysis computeCostForDepJoin(PlanNode joinNode, boolean leftIndependent, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, CommandContext context)
throws TeiidComponentException, QueryMetadataException, QueryPlannerException {
PlanNode independentNode = leftIndependent?joinNode.getFirstChild():joinNode.getLastChild();
@@ -1125,8 +1131,8 @@
independentExpressions, dependentExpressions, metadata,
capFinder, context);
}
-
- public static Float computeCostForDepJoin(PlanNode independentNode,
+
+ public static DependentCostAnalysis computeCostForDepJoin(PlanNode independentNode,
PlanNode dependentNode, List independentExpressions,
List dependentExpressions, QueryMetadataInterface metadata,
CapabilitiesFinder capFinder, CommandContext context)
@@ -1134,9 +1140,13 @@
float independentCardinality = computeCostForTree(independentNode, metadata);
float dependentCardinality = computeCostForTree(dependentNode, metadata);
-
+
+ DependentCostAnalysis dca = new DependentCostAnalysis();
+ dca.maxNdv = new Float[independentExpressions.size()];
+ dca.expectedNdv = new Float[independentExpressions.size()];
+
if (independentCardinality == UNKNOWN_VALUE || dependentCardinality == UNKNOWN_VALUE) {
- return null;
+ return dca; //no cost information to be determined
}
float processorBatchSize = BufferManager.DEFAULT_PROCESSOR_BATCH_SIZE;
@@ -1153,56 +1163,9 @@
float indSymbolNDV = getNDVEstimate(independentNode, metadata, independentCardinality, indElements, true);
Expression depExpr = (Expression)dependentExpressions.get(i);
- LinkedList<PlanNode> critNodes = new LinkedList<PlanNode>();
- LinkedList<PlanNode> initialTargets = new LinkedList<PlanNode>();
-
LinkedList<Expression> depExpressions = new LinkedList<Expression>();
- LinkedList<PlanNode> targets = new LinkedList<PlanNode>();
- critNodes.add(RelationalPlanner.createSelectNode(new DependentSetCriteria(depExpr, null), false));
- initialTargets.add(dependentNode);
- while (!critNodes.isEmpty()) {
- PlanNode critNode = critNodes.remove();
- PlanNode initial = initialTargets.remove();
- if (critNode.getGroups().isEmpty()) {
- //TODO: we need to project constants up through a plan to avoid this case
- continue;
- }
- PlanNode sourceNode = FrameUtil.findOriginatingNode(initial, critNode.getGroups());
- PlanNode target = sourceNode;
- if (initial != sourceNode) {
- target = rpsc.examinePath(initial, sourceNode, metadata, capFinder);
- }
- if (target != sourceNode || (sourceNode.getType() == NodeConstants.Types.SOURCE && sourceNode.getChildCount() == 0)) {
- targets.add(target);
- DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
- depExpressions.add(dsc.getExpression());
- continue;
- }
- if (sourceNode.getType() == NodeConstants.Types.SOURCE) {
- PlanNode child = sourceNode.getFirstChild();
- child = FrameUtil.findOriginatingNode(child, child.getGroups());
- if (child != null && child.getType() == NodeConstants.Types.SET_OP) {
- targets.add(target);
- DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
- depExpressions.add(dsc.getExpression());
- //TODO: we need better handling for set op situations
- continue;
- }
- if (!rpsc.pushAcrossFrame(sourceNode, critNode, metadata)) {
- targets.add(target);
- DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
- depExpressions.add(dsc.getExpression());
- }
- List<PlanNode> createdNodes = rpsc.getCreatedNodes();
- for (PlanNode planNode : createdNodes) {
- critNodes.add(planNode);
- initialTargets.add(planNode.getFirstChild());
- NodeEditor.removeChildNode(planNode.getParent(), planNode);
- }
- rpsc.getCreatedNodes().clear();
- }
- //the source must be a null or project node, which we don't care about
- }
+ LinkedList<PlanNode> targets = determineTargets(dependentNode,
+ metadata, capFinder, rpsc, depExpr, depExpressions);
Iterator<Expression> exprIter = depExpressions.iterator();
for (Iterator<PlanNode> targetIter = targets.iterator(); targetIter.hasNext();) {
@@ -1216,6 +1179,11 @@
setCriteriaBatchSize = CapabilitiesUtil.getMaxInCriteriaSize(RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder);
if (setCriteriaBatchSize < 1) {
setCriteriaBatchSize = indSymbolNDV;
+ } else {
+ int numberOfSets = CapabilitiesUtil.getMaxDependentPredicates(RuleRaiseAccess.getModelIDFromAccess(accessNode, metadata), metadata, capFinder);
+ if (numberOfSets > 0) {
+ setCriteriaBatchSize *= Math.max(1, numberOfSets /dependentExpressions.size()); //scale down to be conservative
+ }
}
} else if (indSymbolNDV > processorBatchSize) {
//don't bother making a virtual join dependent if they are likely to be large
@@ -1259,27 +1227,112 @@
if (!usesKey && accessNode != null && target.getType() == NodeConstants.Types.SOURCE && target.getChildCount() == 0) {
usesIndex = usesKey(depElems, target.getGroups(), metadata, false);
}
- float dependentAccessCardinality = Math.min(depTargetCardinality, depTargetCardinality * indSymbolNDV / depSymbolNDV);
- float scaledCardinality = Math.min(dependentCardinality, dependentCardinality * indSymbolNDV / depSymbolNDV);
- float numberComparisons = (usesIndex?safeLog(depTargetCardinality):depTargetCardinality) * (usesIndex?indSymbolNDV:safeLog(indSymbolNDV));
- float newDependentQueries = accessNode == null?0:(float)Math.ceil(indSymbolNDV / setCriteriaBatchSize);
-
- float relativeCost = newDependentQueries*procNewRequestTime;
- float relativeComparisonCost = (numberComparisons - safeLog(scaledCardinality) /*no longer needed by the join*/
- /*sort cost reduction, however it's always true if its on the source and using an index
- TODO: there are other cost reductions, which we could get by checking the other parent nodes */
- + (scaledCardinality*safeLog(scaledCardinality) - dependentCardinality*safeLog(dependentCardinality)))
- * compareTime;
- float relativeReadCost = (dependentAccessCardinality - depTargetCardinality)*readTime; //cardinality reductions
-
- if (relativeCost + relativeComparisonCost + relativeReadCost < 0) {
- return scaledCardinality;
+ float[] estimates = estimateCost(accessNode, setCriteriaBatchSize, usesIndex, depTargetCardinality, indSymbolNDV, dependentCardinality, depSymbolNDV);
+ if (estimates[1] < 0) {
+ if (dca.expectedCardinality == null) {
+ dca.expectedCardinality = estimates[0];
+ } else {
+ dca.expectedCardinality = Math.min(dca.expectedCardinality, estimates[0]);
+ }
}
+ dca.expectedNdv[i] = indSymbolNDV;
+ //use a quick binary search to find the max ndv
+ float min = 0;
+ float max = Math.max(Integer.MAX_VALUE, indSymbolNDV);
+ for (int j = 0; j < 10; j++) {
+ if (estimates[1] > 1) {
+ max = indSymbolNDV;
+ indSymbolNDV = (indSymbolNDV + min)/2;
+ } else if (estimates[1] < 0) {
+ min = indSymbolNDV;
+ //we assume that values should be closer to the min side
+ indSymbolNDV = Math.min(indSymbolNDV * 8 + 1, (indSymbolNDV + max)/2);
+ } else {
+ break;
+ }
+ estimates = estimateCost(accessNode, setCriteriaBatchSize, usesIndex, depTargetCardinality, indSymbolNDV, dependentCardinality, depSymbolNDV);
+ }
+ dca.maxNdv[i] = indSymbolNDV;
}
}
+ return dca;
+ }
+
+ private static float[] estimateCost(PlanNode accessNode, float setCriteriaBatchSize, boolean usesIndex, float depTargetCardinality,
+ float indSymbolNDV, float dependentCardinality, float depSymbolNDV) {
+ float dependentAccessCardinality = Math.min(depTargetCardinality, depTargetCardinality * indSymbolNDV / depSymbolNDV);
+ float scaledCardinality = Math.min(dependentCardinality, dependentCardinality * indSymbolNDV / depSymbolNDV);
+ float numberComparisons = (usesIndex?safeLog(depTargetCardinality):depTargetCardinality) * (usesIndex?indSymbolNDV:safeLog(indSymbolNDV));
+ float newDependentQueries = accessNode == null?0:(float)Math.ceil(indSymbolNDV / setCriteriaBatchSize);
- return null;
+ float relativeCost = newDependentQueries*procNewRequestTime;
+ float relativeComparisonCost = (numberComparisons - safeLog(scaledCardinality) /*no longer needed by the join*/
+ /*sort cost reduction, however it's always true if its on the source and using an index
+ TODO: there are other cost reductions, which we could get by checking the other parent nodes */
+ + (scaledCardinality*safeLog(scaledCardinality) - dependentCardinality*safeLog(dependentCardinality)))
+ * compareTime;
+ float relativeReadCost = (dependentAccessCardinality - depTargetCardinality)*readTime; //cardinality reductions
+ return new float[] {scaledCardinality, relativeCost + relativeComparisonCost + relativeReadCost};
}
+
+ /**
+ * For now we only consider a single target. In the future we may consider multiple.
+ */
+ private static LinkedList<PlanNode> determineTargets(
+ PlanNode dependentNode, QueryMetadataInterface metadata,
+ CapabilitiesFinder capFinder, RulePushSelectCriteria rpsc,
+ Expression depExpr, LinkedList<Expression> depExpressions)
+ throws QueryPlannerException, TeiidComponentException {
+ LinkedList<PlanNode> targets = new LinkedList<PlanNode>();
+ LinkedList<PlanNode> critNodes = new LinkedList<PlanNode>();
+ critNodes.add(RelationalPlanner.createSelectNode(new DependentSetCriteria(depExpr, null), false));
+ LinkedList<PlanNode> initialTargets = new LinkedList<PlanNode>();
+ initialTargets.add(dependentNode);
+ while (!critNodes.isEmpty()) {
+ PlanNode critNode = critNodes.remove();
+ PlanNode initial = initialTargets.remove();
+ if (critNode.getGroups().isEmpty()) {
+ //TODO: we need to project constants up through a plan to avoid this case
+ continue;
+ }
+ PlanNode sourceNode = FrameUtil.findOriginatingNode(initial, critNode.getGroups());
+ PlanNode target = sourceNode;
+ if (initial != sourceNode) {
+ target = rpsc.examinePath(initial, sourceNode, metadata, capFinder);
+ }
+ if (target != sourceNode || (sourceNode.getType() == NodeConstants.Types.SOURCE && sourceNode.getChildCount() == 0)) {
+ targets.add(target);
+ DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
+ depExpressions.add(dsc.getExpression());
+ continue;
+ }
+ if (sourceNode.getType() == NodeConstants.Types.SOURCE) {
+ PlanNode child = sourceNode.getFirstChild();
+ child = FrameUtil.findOriginatingNode(child, child.getGroups());
+ if (child != null && child.getType() == NodeConstants.Types.SET_OP) {
+ targets.add(target);
+ DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
+ depExpressions.add(dsc.getExpression());
+ //TODO: we need better handling for set op situations
+ continue;
+ }
+ if (!rpsc.pushAcrossFrame(sourceNode, critNode, metadata)) {
+ targets.add(target);
+ DependentSetCriteria dsc = (DependentSetCriteria)critNode.getProperty(Info.SELECT_CRITERIA);
+ depExpressions.add(dsc.getExpression());
+ }
+ List<PlanNode> createdNodes = rpsc.getCreatedNodes();
+ for (PlanNode planNode : createdNodes) {
+ critNodes.add(planNode);
+ initialTargets.add(planNode.getFirstChild());
+ NodeEditor.removeChildNode(planNode.getParent(), planNode);
+ }
+ rpsc.getCreatedNodes().clear();
+ }
+ //the source must be a null or project node, which we don't care about
+ }
+ return targets;
+ }
static float getNDVEstimate(PlanNode indNode,
QueryMetadataInterface metadata, float cardinality,
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleChooseDependent.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -41,6 +41,7 @@
import org.teiid.query.optimizer.relational.plantree.NodeConstants;
import org.teiid.query.optimizer.relational.plantree.NodeEditor;
import org.teiid.query.optimizer.relational.plantree.PlanNode;
+import org.teiid.query.optimizer.relational.rules.NewCalculateCostUtil.DependentCostAnalysis;
import org.teiid.query.sql.lang.DependentSetCriteria;
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -85,31 +86,31 @@
PlanNode chosenNode = chooseDepWithoutCosting(sourceNode, bothCandidates?siblingNode:null, analysisRecord);
if(chosenNode != null) {
- pushCriteria |= markDependent(chosenNode, joinNode, metadata);
+ pushCriteria |= markDependent(chosenNode, joinNode, metadata, null);
continue;
}
- boolean useDepJoin = NewCalculateCostUtil.computeCostForDepJoin(joinNode, !entry.leftCandidate, metadata, capFinder, context) != null;
+ DependentCostAnalysis dca = NewCalculateCostUtil.computeCostForDepJoin(joinNode, !entry.leftCandidate, metadata, capFinder, context);
PlanNode dependentNode = sourceNode;
- if (bothCandidates && !useDepJoin) {
- useDepJoin = NewCalculateCostUtil.computeCostForDepJoin(joinNode, true, metadata, capFinder, context) != null;
- if (useDepJoin) {
+ if (bothCandidates && dca.expectedCardinality == null) {
+ dca = NewCalculateCostUtil.computeCostForDepJoin(joinNode, true, metadata, capFinder, context);
+ if (dca.expectedCardinality != null) {
dependentNode = siblingNode;
}
}
- if (useDepJoin) {
- pushCriteria |= markDependent(dependentNode, joinNode, metadata);
+ if (dca.expectedCardinality != null) {
+ pushCriteria |= markDependent(dependentNode, joinNode, metadata, dca);
} else {
float sourceCost = NewCalculateCostUtil.computeCostForTree(sourceNode, metadata);
float siblingCost = NewCalculateCostUtil.computeCostForTree(siblingNode, metadata);
if (bothCandidates && sourceCost != NewCalculateCostUtil.UNKNOWN_VALUE && sourceCost < RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY
&& (sourceCost < siblingCost || siblingCost == NewCalculateCostUtil.UNKNOWN_VALUE)) {
- pushCriteria |= markDependent(siblingNode, joinNode, metadata);
+ pushCriteria |= markDependent(siblingNode, joinNode, metadata, null);
} else if (siblingCost != NewCalculateCostUtil.UNKNOWN_VALUE && siblingCost < RuleChooseDependent.DEFAULT_INDEPENDENT_CARDINALITY) {
- pushCriteria |= markDependent(sourceNode, joinNode, metadata);
+ pushCriteria |= markDependent(sourceNode, joinNode, metadata, null);
}
}
}
@@ -260,10 +261,11 @@
/**
* Mark the specified access node to be made dependent
* @param sourceNode Node to make dependent
+ * @param dca
* @throws TeiidComponentException
* @throws QueryMetadataException
*/
- boolean markDependent(PlanNode sourceNode, PlanNode joinNode, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
+ boolean markDependent(PlanNode sourceNode, PlanNode joinNode, QueryMetadataInterface metadata, DependentCostAnalysis dca) throws QueryMetadataException, TeiidComponentException {
boolean isLeft = joinNode.getFirstChild() == sourceNode;
@@ -279,7 +281,7 @@
// Create DependentValueSource and set on the independent side as this will feed the values
joinNode.setProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE, id);
- List<PlanNode> crits = getDependentCriteriaNodes(id, independentExpressions, dependentExpressions, isLeft?joinNode.getLastChild():joinNode.getFirstChild(), metadata);
+ List<PlanNode> crits = getDependentCriteriaNodes(id, independentExpressions, dependentExpressions, isLeft?joinNode.getLastChild():joinNode.getFirstChild(), metadata, dca);
PlanNode newRoot = sourceNode;
@@ -303,21 +305,30 @@
* @since 4.3
*/
private List<PlanNode> getDependentCriteriaNodes(String id, List independentExpressions,
- List dependentExpressions, PlanNode indNode, QueryMetadataInterface metadata) throws QueryMetadataException, TeiidComponentException {
+ List dependentExpressions, PlanNode indNode, QueryMetadataInterface metadata, DependentCostAnalysis dca) throws QueryMetadataException, TeiidComponentException {
List<PlanNode> result = new LinkedList<PlanNode>();
- Iterator depIter = dependentExpressions.iterator();
- Iterator indepIter = independentExpressions.iterator();
+ Float cardinality = null;
- float cardinality = NewCalculateCostUtil.computeCostForTree(indNode, metadata);
-
- while(depIter.hasNext()) {
- Expression depExpr = (Expression) depIter.next();
- Expression indepExpr = (Expression) indepIter.next();
+ for (int i = 0; i < dependentExpressions.size(); i++) {
+ Expression depExpr = (Expression) dependentExpressions.get(i);
+ Expression indepExpr = (Expression) independentExpressions.get(i);
DependentSetCriteria crit = new DependentSetCriteria(SymbolMap.getExpression(depExpr), id);
- Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(indepExpr, true);
- float ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true);
+ float ndv = NewCalculateCostUtil.UNKNOWN_VALUE;
+ if (dca != null && dca.expectedNdv[i] != null) {
+ if (dca.expectedNdv[i] > 4*dca.maxNdv[i]) {
+ continue; //not necessary to use
+ }
+ ndv = dca.expectedNdv[i];
+ crit.setMaxNdv(dca.maxNdv[i]);
+ } else {
+ Collection<ElementSymbol> elems = ElementCollectorVisitor.getElements(indepExpr, true);
+ if (cardinality == null) {
+ cardinality = NewCalculateCostUtil.computeCostForTree(indNode, metadata);
+ }
+ ndv = NewCalculateCostUtil.getNDVEstimate(indNode, metadata, cardinality, elems, true);
+ }
crit.setNdv(ndv);
crit.setValueExpression(indepExpr);
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -31,13 +31,16 @@
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.client.plan.PlanNode;
import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleSource;
+import org.teiid.common.buffer.BufferManager.BufferReserveMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.QueryPlugin;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.util.CommandContext;
@@ -57,6 +60,8 @@
private boolean isUpdate = false;
private boolean returnedRows = false;
protected Command nextCommand;
+ private int reserved;
+ private int schemaSize;
protected AccessNode() {
super();
@@ -65,6 +70,13 @@
public AccessNode(int nodeID) {
super(nodeID);
}
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+ this.schemaSize = getBufferManager().getSchemaSize(getOutputElements());
+ }
public void reset() {
super.reset();
@@ -181,6 +193,10 @@
//end of source
tupleSource.closeSource();
tupleSources.remove(i--);
+ if (reserved > 0) {
+ reserved -= schemaSize;
+ getBufferManager().releaseBuffers(schemaSize);
+ }
if (!processCommandsIndividually()) {
registerNext();
}
@@ -238,6 +254,9 @@
}
}
tupleSources.add(getDataManager().registerRequest(getContext(), atomicCommand, modelName, connectorBindingId, getID(), limit));
+ if (tupleSources.size() > 1) {
+ reserved += getBufferManager().reserveBuffers(schemaSize, BufferReserveMode.FORCE);
+ }
}
protected boolean processCommandsIndividually() {
@@ -249,6 +268,8 @@
}
public void closeDirect() {
+ getBufferManager().releaseBuffers(reserved);
+ reserved = 0;
super.closeDirect();
closeSources();
}
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/DependentCriteriaProcessor.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -38,6 +38,7 @@
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.optimizer.relational.rules.NewCalculateCostUtil;
import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.AbstractSetCriteria;
@@ -66,6 +67,10 @@
Object nextValue;
boolean isNull;
+
+ float maxNdv = NewCalculateCostUtil.UNKNOWN_VALUE;
+
+ boolean overMax;
}
class TupleState {
@@ -96,6 +101,21 @@
dvs = new DependentValueSource(sortUtility.sort());
for (SetState setState : dependentSetStates) {
setState.valueIterator = dvs.getValueIterator(setState.valueExpression);
+ if (setState.maxNdv > 0 && setState.maxNdv < dvs.getTupleBuffer().getRowCount()) {
+ ValueIterator vi = dvs.getValueIterator(setState.valueExpression);
+ Comparable last = null;
+ int distinctCount = 0;
+ while (vi.hasNext()) {
+ Comparable next = (Comparable) vi.next();
+ if (last == null || next.compareTo(last) != 0) {
+ distinctCount++;
+ }
+ last = next;
+ }
+ if (distinctCount > setState.maxNdv) {
+ setState.overMax = true;
+ }
+ }
}
}
}
@@ -177,6 +197,7 @@
sources.add(ts.getDepedentSetStates());
}
ts.getDepedentSetStates().add(state);
+ state.maxNdv = dsc.getMaxNdv();
}
}
}
@@ -276,21 +297,25 @@
if (i == currentIndex++) {
- boolean done = false;
+ int doneCount = 0;
- while (!done) {
+ while (doneCount < source.size()) {
boolean isNull = false;
boolean lessThanMax = true;
for (SetState state : source) {
+ if (state.overMax) {
+ doneCount++;
+ continue;
+ }
if (state.nextValue == null && !state.isNull) {
if (state.valueIterator.hasNext()) {
state.nextValue = state.valueIterator.next();
state.isNull = state.nextValue == null;
} else {
state.valueIterator.reset();
- done = true; // should be true for each iterator from this source
+ doneCount++; // should be true for each iterator from this source
continue;
}
}
@@ -299,7 +324,7 @@
lessThanMax &= state.replacement.size() < maxSize * (run + 1);
}
- if (done) {
+ if (doneCount == source.size()) {
if (!restartIndexes.isEmpty() && restartIndexes.getLast().intValue() == i) {
restartIndexes.removeLast();
}
@@ -316,7 +341,7 @@
}
} else {
restartIndexes.add(i);
- done = true;
+ break;
}
}
}
@@ -339,6 +364,9 @@
}
public Criteria replaceDependentCriteria(AbstractSetCriteria crit, SetState state) {
+ if (state.overMax) {
+ return QueryRewriter.TRUE_CRITERIA;
+ }
if (state.replacement.isEmpty()) {
// No values - return criteria that is always false
return QueryRewriter.FALSE_CRITERIA;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/EnhancedSortMergeJoinStrategy.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -136,6 +136,7 @@
int rowId = 0;
List<?> lastTuple = null;
boolean sortedDistinct = sorted && !state.isDistinct();
+ int sizeHint = index.getExpectedHeight(state.getTupleBuffer().getRowCount());
outer: while (its.hasNext()) {
//detect if sorted and distinct
List<?> originalTuple = its.nextTuple();
@@ -153,7 +154,7 @@
if (!state.isDistinct()) {
tuple.add(keyLength - 1, rowId++);
}
- index.insert(tuple, sorted?InsertMode.ORDERED:InsertMode.NEW, state.getTupleBuffer().getRowCount());
+ index.insert(tuple, sorted?InsertMode.ORDERED:InsertMode.NEW, sizeHint);
}
if (!sorted) {
index.compact();
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/DependentSetCriteria.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -24,6 +24,7 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.optimizer.relational.rules.NewCalculateCostUtil;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.ContextReference;
import org.teiid.query.sql.symbol.Expression;
@@ -46,7 +47,8 @@
/**
* The estimated number of distinct values for the value Expression
*/
- private float ndv;
+ private float ndv = NewCalculateCostUtil.UNKNOWN_VALUE;
+ private float maxNdv = NewCalculateCostUtil.UNKNOWN_VALUE;
/**
* Construct with the left expression
@@ -61,6 +63,14 @@
return id;
}
+ public float getMaxNdv() {
+ return maxNdv;
+ }
+
+ public void setMaxNdv(float maxNdv) {
+ this.maxNdv = maxNdv;
+ }
+
public float getNdv() {
return ndv;
}
@@ -144,6 +154,7 @@
}
criteriaCopy.id = this.id;
criteriaCopy.ndv = this.ndv;
+ criteriaCopy.maxNdv = this.maxNdv;
return criteriaCopy;
}
Modified: trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/test/java/org/teiid/common/buffer/TestSTree.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -58,6 +58,25 @@
assertNull(map.insert(Arrays.asList(1, String.valueOf(1)), InsertMode.NEW, -1));
}
+ @Test public void testUnOrderedInsert() throws TeiidComponentException {
+ BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
+ bm.setProcessorBatchSize(16);
+
+ ElementSymbol e1 = new ElementSymbol("x");
+ e1.setType(Integer.class);
+ List elements = Arrays.asList(e1);
+ STree map = bm.createSTree(elements, "1", 1);
+
+ int size = (1<<16)+(1<<4)+1;
+ int logSize = map.getExpectedHeight(size);
+
+ for (int i = 0; i < size; i++) {
+ assertNull(map.insert(Arrays.asList(i), InsertMode.NEW, logSize));
+ assertEquals(i + 1, map.getRowCount());
+ }
+ assertTrue(5 >= map.getHeight());
+ }
+
@Test public void testOrderedInsert() throws TeiidComponentException {
BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
bm.setProcessorBatchSize(16);
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -25,12 +25,14 @@
import static org.junit.Assert.*;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
import org.junit.Test;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.optimizer.TestOptimizer;
+import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
@@ -810,4 +812,46 @@
TestProcessor.helpProcess(plan, dataManager, expected);
}
+ @Test public void testDependentJoinBackoff() throws Exception {
+ // Create query
+ String sql = "SELECT pm1.g1.e1 FROM pm1.g1, pm6.g1 WHERE pm1.g1.e1=pm6.g1.e1"; //$NON-NLS-1$
+
+ // Construct data manager with data
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData4(dataManager);
+
+ FakeMetadataFacade fakeMetadata = FakeMetadataFactory.example1();
+
+ FakeMetadataFactory.setCardinality("pm1.g1", 1, fakeMetadata);
+ FakeMetadataFactory.setCardinality("pm6.g1", 1000, fakeMetadata);
+ // Plan query
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
+ depcaps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+ depcaps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1));
+ depcaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+
+ BasicSourceCapabilities caps = new BasicSourceCapabilities();
+ caps.setCapabilitySupport(Capability.CRITERIA_IN, true);
+
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm6", depcaps); //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(new Object[] {
+ new String("b")})}; //$NON-NLS-1$
+
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, fakeMetadata, new String[] {
+ "SELECT pm6.g1.e1 FROM pm6.g1 WHERE pm6.g1.e1 IN (<dependent values>) ORDER BY pm6.g1.e1",
+ "SELECT pm1.g1.e1 FROM pm1.g1"
+ }, capFinder, ComparisonMode.EXACT_COMMAND_STRING);
+
+ // Run query
+ TestProcessor.helpProcess(plan, dataManager, expected);
+
+ //note that the dependent join was not actually performed
+ assertEquals(new HashSet<String>(Arrays.asList("SELECT pm1.g1.e1 FROM pm1.g1", "SELECT pm6.g1.e1 FROM pm6.g1 ORDER BY pm6.g1.e1")),
+ new HashSet<String>(dataManager.getQueries()));
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -7650,5 +7650,5 @@
helpProcess(plan, dataManager, expected);
}
- private static final boolean DEBUG = false;
+ private static final boolean DEBUG = true;
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java 2011-04-04 22:34:47 UTC (rev 3058)
+++ trunk/engine/src/test/java/org/teiid/query/processor/relational/TestAccessNode.java 2011-04-04 22:35:34 UTC (rev 3059)
@@ -61,7 +61,7 @@
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
FakeDataManager dataManager = new FakeDataManager();
TestProcessor.sampleData1(dataManager);
-
+ node.setElements(command.getProjectedSymbols());
node.initialize(context, bm, dataManager);
node.setShouldEvaluateExpressions(true);
// Call open()
@@ -99,6 +99,7 @@
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
FakeDataManager dataManager = new FakeDataManager();
TestProcessor.sampleData1(dataManager);
+ node.setElements(query.getProjectedSymbols());
node.initialize(context, bm, dataManager);
// Call open()
node.open();
13 years, 9 months
teiid SVN: r3058 - trunk/test-integration/common/src/test/resources/TestODBCSocketTransport.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2011-04-04 18:34:47 -0400 (Mon, 04 Apr 2011)
New Revision: 3058
Modified:
trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testSelect.expected
Log:
updating unit test with the increment in oids
Modified: trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testSelect.expected
===================================================================
--- trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testSelect.expected 2011-04-04 19:26:16 UTC (rev 3057)
+++ trunk/test-integration/common/src/test/resources/TestODBCSocketTransport/testSelect.expected 2011-04-04 22:34:47 UTC (rev 3058)
@@ -1,35 +1,35 @@
varchar varchar varchar varchar varchar bool bool varchar int4 varchar bool bool int4
vdbname schemaname name type nameinsource isphysical supportsupdates uid cardinality description issystem ismaterialized oid
-parts SYS Columns Table <null> true false mmuuid:1c9a5cb2-17b1-4e4a-8b0e-3a42bd052509 0 <null> true false 7
-parts SYS DataTypes Table <null> true false mmuuid:9a8794f9-66f8-49e8-8576-89d212d0f957 0 <null> true false 8
-parts SYS KeyColumns Table <null> true false mmuuid:14946083-3bd5-42d5-8283-1c0694347c29 0 <null> true false 9
-parts SYS Keys Table <null> true false mmuuid:1e5135dc-ce5d-4b25-a8ff-63f5440b3108 0 <null> true false 10
-parts SYSADMIN MatViews Table <null> true false mmuuid:520ba1e8-3553-460f-8d18-9b43f089e256 0 <null> true false 5
-parts PartsSupplier PARTSSUPPLIER.PARTS Table PARTS true true mmuuid:f6276601-73fe-1edc-a81c-ecf397b10590 16 <null> false false 0
-parts PartsSupplier PARTSSUPPLIER.SHIP_VIA Table SHIP_VIA true true mmuuid:0f4e9b80-73ff-1edc-a81c-ecf397b10590 4 <null> false false 1
-parts PartsSupplier PARTSSUPPLIER.STATUS Table STATUS true true mmuuid:1f297200-73ff-1edc-a81c-ecf397b10590 3 <null> false false 2
-parts PartsSupplier PARTSSUPPLIER.SUPPLIER Table SUPPLIER true true mmuuid:2c371ec0-73ff-1edc-a81c-ecf397b10590 16 <null> false false 4
-parts PartsSupplier PARTSSUPPLIER.SUPPLIER_PARTS Table SUPPLIER_PARTS true true mmuuid:3deafb00-73ff-1edc-a81c-ecf397b10590 227 <null> false false 3
-parts SYS ProcedureParams Table <null> true false mmuuid:a56bd7fe-c87a-411c-8f5d-661975a25626 0 <null> true false 11
-parts SYS Procedures Table <null> true false mmuuid:0bc132a5-9f8d-4a3c-9f5d-98156a98a962 0 <null> true false 12
-parts SYS Properties Table <null> true false mmuuid:7a45e50a-d03f-4548-ba35-761651bbca85 0 <null> true false 13
-parts SYS ReferenceKeyColumns Table <null> true false mmuuid:6a9653e8-a337-41b2-86fa-77b98f409a29 0 <null> true false 14
-parts SYS Schemas Table <null> true false mmuuid:8648a554-b2ad-4e8e-84ca-2ec618b311a9 0 <null> true false 15
-parts SYS Tables Table <null> true false mmuuid:8551b3bd-11cc-4049-9bcf-fe91a0eb7ba7 0 <null> true false 16
-parts SYSADMIN VDBResources Table <null> true false mmuuid:1785804d-beaf-4831-9531-e59164fedd49 0 <null> true false 6
-parts SYS VirtualDatabases Table <null> true false mmuuid:47297c72-d621-4f4e-af4e-74060ac5f489 0 <null> true false 17
-parts pg_catalog matpg_relatt Table <null> false false mmuid:9bfddc66-af75-4366-8eac-b9fef3421219 0 <null> true true 29
-parts pg_catalog pg_am Table <null> false false mmuid:1462b28e-0bab-436f-9654-013821506337 0 <null> true false 23
-parts pg_catalog pg_attrdef Table <null> false false mmuid:71091853-c65e-46a9-9947-aa024f806e2d 0 <null> true false 26
-parts pg_catalog pg_attribute Table <null> false false mmuid:fa463d98-365f-489a-a707-025193cb51eb 0 <null> true true 20
-parts pg_catalog pg_class Table <null> false false mmuid:7e21f2e6-06e3-4bca-9b01-72ea47821560 0 <null> true true 19
-parts pg_catalog pg_database Table <null> false false mmuid:492dd834-907f-429b-aa6e-958ad65204c6 0 <null> true false 27
-parts pg_catalog pg_index Table <null> false false mmuid:22ac431d-e6e6-4eef-9d74-b31795424e97 0 <null> true true 22
-parts pg_catalog pg_namespace Table <null> false false mmuid:6609866a-3d7b-4f4b-95fe-ebfac769d699 0 <null> true false 18
-parts pg_catalog pg_proc Table <null> false false mmuid:da4b747e-7d87-403a-8309-2cdf1399031b 0 <null> true true 24
-parts pg_catalog pg_trigger Table <null> false false mmuid:9569efdb-21b2-4b4f-a2db-e7406267b8ed 0 <null> true false 25
-parts pg_catalog pg_type Table <null> false false mmuid:9462e3f8-cd3c-414f-a570-f6f33c40e36a 0 <null> true false 21
-parts pg_catalog pg_user Table <null> false false mmuid:28d034eb-6f39-402f-b642-9c9560e57247 0 <null> true false 28
+parts SYS Columns Table <null> true false mmuuid:1c9a5cb2-17b1-4e4a-8b0e-3a42bd052509 0 <null> true false 8
+parts SYS DataTypes Table <null> true false mmuuid:9a8794f9-66f8-49e8-8576-89d212d0f957 0 <null> true false 9
+parts SYS KeyColumns Table <null> true false mmuuid:14946083-3bd5-42d5-8283-1c0694347c29 0 <null> true false 10
+parts SYS Keys Table <null> true false mmuuid:1e5135dc-ce5d-4b25-a8ff-63f5440b3108 0 <null> true false 11
+parts SYSADMIN MatViews Table <null> true false mmuuid:520ba1e8-3553-460f-8d18-9b43f089e256 0 <null> true false 6
+parts PartsSupplier PARTSSUPPLIER.PARTS Table PARTS true true mmuuid:f6276601-73fe-1edc-a81c-ecf397b10590 16 <null> false false 1
+parts PartsSupplier PARTSSUPPLIER.SHIP_VIA Table SHIP_VIA true true mmuuid:0f4e9b80-73ff-1edc-a81c-ecf397b10590 4 <null> false false 2
+parts PartsSupplier PARTSSUPPLIER.STATUS Table STATUS true true mmuuid:1f297200-73ff-1edc-a81c-ecf397b10590 3 <null> false false 3
+parts PartsSupplier PARTSSUPPLIER.SUPPLIER Table SUPPLIER true true mmuuid:2c371ec0-73ff-1edc-a81c-ecf397b10590 16 <null> false false 5
+parts PartsSupplier PARTSSUPPLIER.SUPPLIER_PARTS Table SUPPLIER_PARTS true true mmuuid:3deafb00-73ff-1edc-a81c-ecf397b10590 227 <null> false false 4
+parts SYS ProcedureParams Table <null> true false mmuuid:a56bd7fe-c87a-411c-8f5d-661975a25626 0 <null> true false 12
+parts SYS Procedures Table <null> true false mmuuid:0bc132a5-9f8d-4a3c-9f5d-98156a98a962 0 <null> true false 13
+parts SYS Properties Table <null> true false mmuuid:7a45e50a-d03f-4548-ba35-761651bbca85 0 <null> true false 14
+parts SYS ReferenceKeyColumns Table <null> true false mmuuid:6a9653e8-a337-41b2-86fa-77b98f409a29 0 <null> true false 15
+parts SYS Schemas Table <null> true false mmuuid:8648a554-b2ad-4e8e-84ca-2ec618b311a9 0 <null> true false 16
+parts SYS Tables Table <null> true false mmuuid:8551b3bd-11cc-4049-9bcf-fe91a0eb7ba7 0 <null> true false 17
+parts SYSADMIN VDBResources Table <null> true false mmuuid:1785804d-beaf-4831-9531-e59164fedd49 0 <null> true false 7
+parts SYS VirtualDatabases Table <null> true false mmuuid:47297c72-d621-4f4e-af4e-74060ac5f489 0 <null> true false 18
+parts pg_catalog matpg_relatt Table <null> false false mmuid:9bfddc66-af75-4366-8eac-b9fef3421219 0 <null> true true 30
+parts pg_catalog pg_am Table <null> false false mmuid:1462b28e-0bab-436f-9654-013821506337 0 <null> true false 24
+parts pg_catalog pg_attrdef Table <null> false false mmuid:71091853-c65e-46a9-9947-aa024f806e2d 0 <null> true false 27
+parts pg_catalog pg_attribute Table <null> false false mmuid:fa463d98-365f-489a-a707-025193cb51eb 0 <null> true true 21
+parts pg_catalog pg_class Table <null> false false mmuid:7e21f2e6-06e3-4bca-9b01-72ea47821560 0 <null> true true 20
+parts pg_catalog pg_database Table <null> false false mmuid:492dd834-907f-429b-aa6e-958ad65204c6 0 <null> true false 28
+parts pg_catalog pg_index Table <null> false false mmuid:22ac431d-e6e6-4eef-9d74-b31795424e97 0 <null> true true 23
+parts pg_catalog pg_namespace Table <null> false false mmuid:6609866a-3d7b-4f4b-95fe-ebfac769d699 0 <null> true false 19
+parts pg_catalog pg_proc Table <null> false false mmuid:da4b747e-7d87-403a-8309-2cdf1399031b 0 <null> true true 25
+parts pg_catalog pg_trigger Table <null> false false mmuid:9569efdb-21b2-4b4f-a2db-e7406267b8ed 0 <null> true false 26
+parts pg_catalog pg_type Table <null> false false mmuid:9462e3f8-cd3c-414f-a570-f6f33c40e36a 0 <null> true false 22
+parts pg_catalog pg_user Table <null> false false mmuid:28d034eb-6f39-402f-b642-9c9560e57247 0 <null> true false 29
Row Count : 30
getColumnName getColumnType getCatalogName getColumnClassName getColumnLabel getColumnTypeName getSchemaName getTableName getColumnDisplaySize getPrecision getScale isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isNullable isReadOnly isSearchable isSigned isWritable
vdbname 12 java.lang.String vdbname varchar 2147483647 0 0 false true false false 1 false true false true
13 years, 9 months