Author: jolee
Date: 2014-01-16 11:40:23 -0500 (Thu, 16 Jan 2014)
New Revision: 4622
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
Log:
TEIID-2482: (reprise) Allow the use of the enhanced join for left outer joins
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2014-01-16
02:40:52 UTC (rev 4621)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleImplementJoinStrategy.java 2014-01-16
16:40:23 UTC (rev 4622)
@@ -34,11 +34,9 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.language.SortSpecification.NullOrdering;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
-import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.optimizer.relational.OptimizerRule;
import org.teiid.query.optimizer.relational.RuleStack;
import org.teiid.query.optimizer.relational.plantree.NodeConstants;
@@ -50,12 +48,9 @@
import org.teiid.query.processor.relational.MergeJoinStrategy.SortOption;
import org.teiid.query.processor.relational.RelationalNode;
import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.IsNullCriteria;
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -63,7 +58,6 @@
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
import org.teiid.query.util.CommandContext;
-import org.teiid.translator.ExecutionFactory.NullOrder;
/**
@@ -107,22 +101,13 @@
if (!JoinStrategyType.MERGE.equals(stype)) {
continue;
}
-
+ JoinType joinType = (JoinType)
joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
+
/**
* Don't push sorts for unbalanced inner joins, we prefer to use a
processing time cost based decision
*/
boolean pushLeft = true;
boolean pushRight = true;
- if (joinNode.getProperty(NodeConstants.Info.JOIN_TYPE) == JoinType.JOIN_INNER
&& context != null) {
- float leftCost =
NewCalculateCostUtil.computeCostForTree(joinNode.getFirstChild(), metadata);
- float rightCost =
NewCalculateCostUtil.computeCostForTree(joinNode.getLastChild(), metadata);
- if (leftCost != NewCalculateCostUtil.UNKNOWN_VALUE && rightCost !=
NewCalculateCostUtil.UNKNOWN_VALUE
- && (leftCost > context.getProcessorBatchSize() || rightCost
> context.getProcessorBatchSize())) {
- //we use a larger constant here to ensure that we don't unwisely
prevent pushdown
- pushLeft = leftCost < context.getProcessorBatchSize() || leftCost /
rightCost < 8;
- pushRight = rightCost < context.getProcessorBatchSize() || rightCost /
leftCost < 8 || joinNode.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE) !=
null;
- }
- }
List<SingleElementSymbol> leftExpressions =
(List<SingleElementSymbol>)
joinNode.getProperty(NodeConstants.Info.LEFT_EXPRESSIONS);
List<SingleElementSymbol> rightExpressions =
(List<SingleElementSymbol>)
joinNode.getProperty(NodeConstants.Info.RIGHT_EXPRESSIONS);
@@ -140,6 +125,18 @@
key = NewCalculateCostUtil.getKeyUsed(leftExpressions, null, metadata,
null);
right = false;
}
+
+ if ((joinType == JoinType.JOIN_INNER || joinType == JoinType.JOIN_LEFT_OUTER)
&& context != null) {
+ float leftCost =
NewCalculateCostUtil.computeCostForTree(joinNode.getFirstChild(), metadata);
+ float rightCost =
NewCalculateCostUtil.computeCostForTree(joinNode.getLastChild(), metadata);
+ if (leftCost != NewCalculateCostUtil.UNKNOWN_VALUE && rightCost !=
NewCalculateCostUtil.UNKNOWN_VALUE
+ && (leftCost > context.getProcessorBatchSize() || rightCost
> context.getProcessorBatchSize())) {
+ //we use a larger constant here to ensure that we don't unwisely
prevent pushdown
+ pushLeft = leftCost < context.getProcessorBatchSize() || leftCost /
rightCost < 8 || (key != null && !right);
+ pushRight = rightCost < context.getProcessorBatchSize() || rightCost /
leftCost < 8 || joinType == JoinType.JOIN_LEFT_OUTER || (key != null &&
right);
+ }
+ }
+
if (key != null &&
joinNode.getProperty(NodeConstants.Info.DEPENDENT_VALUE_SOURCE) == null) {
//redo the join predicates based upon the key alone
List<Object> keyCols = metadata.getElementIDsInKey(key);
@@ -202,7 +199,6 @@
}
boolean pushedRight = insertSort(joinNode.getLastChild(), rightExpressions, joinNode,
metadata, capabilitiesFinder, pushRight);
- JoinType joinType = (JoinType) joinNode.getProperty(NodeConstants.Info.JOIN_TYPE);
if ((!pushedRight || !pushedLeft) && (joinType == JoinType.JOIN_INNER ||
(joinType == JoinType.JOIN_LEFT_OUTER && !pushedLeft))) {
joinNode.setProperty(NodeConstants.Info.JOIN_STRATEGY,
JoinStrategyType.ENHANCED_SORT);
}
Show replies by date