Author: shawkins
Date: 2011-10-25 10:03:30 -0400 (Tue, 25 Oct 2011)
New Revision: 3580
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
Log:
TEIID-1792 making join planning more avoident of cross joins of unknown size
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java 2011-10-25
03:01:49 UTC (rev 3579)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/JoinRegion.java 2011-10-25
14:03:30 UTC (rev 3580)
@@ -250,7 +250,7 @@
HashSet<PlanNode> criteria = new
HashSet<PlanNode>(this.criteriaNodes);
HashSet<GroupSymbol> groups = new
HashSet<GroupSymbol>(this.joinSourceNodes.size());
-
+ boolean hasUnknown = false;
for (int i = 0; i < joinOrder.length; i++) {
Integer source = (Integer)joinOrder[i];
@@ -286,6 +286,7 @@
if (sourceCost == NewCalculateCostUtil.UNKNOWN_VALUE) {
sourceCost = UNKNOWN_TUPLE_EST;
+ hasUnknown = true;
if (applicableCriteria != null && !applicableCriteria.isEmpty())
{
CompoundCriteria cc = new CompoundCriteria();
for (PlanNode planNode : applicableCriteria) {
@@ -322,6 +323,10 @@
sourceCost = depJoinCost;
}
}
+
+ if (i > 0 && (applicableCriteria == null ||
applicableCriteria.isEmpty()) && hasUnknown) {
+ sourceCost *= 10; //cross join penalty
+ }
cost *= sourceCost;
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java 2011-10-25
03:01:49 UTC (rev 3579)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/optimizer/TestJoinOptimization.java 2011-10-25
14:03:30 UTC (rev 3580)
@@ -39,6 +39,7 @@
import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
import org.teiid.query.optimizer.relational.rules.JoinUtil;
@@ -1026,5 +1027,25 @@
0 // UnionAll
});
}
+
+ @Test public void testCrossJoinAvoidance() throws Exception {
+
+ CapabilitiesFinder capFinder = TestOptimizer.getGenericFinder();
+
+ QueryMetadataInterface metadata = RealMetadataFactory.exampleBQT();
+ RealMetadataFactory.setCardinality("bqt1.smallb", 1800, metadata);
//$NON-NLS-1$
+ RealMetadataFactory.setCardinality("bqt1.smalla", 0, metadata);
//$NON-NLS-1$
+ RealMetadataFactory.setCardinality("bqt2.smallb", 15662, metadata);
//$NON-NLS-1$
+
+ TestOptimizer.helpPlan(
+ "SELECT BQT1.SmallA.IntKey FROM BQT1.SmallB, BQT1.Smalla, bqt2.smallb
where bqt2.smallb.intkey = bqt1.smallb.intkey and bqt2.smallb.intkey =
bqt1.smalla.intkey", //$NON-NLS-1$
+ metadata,
+ null, capFinder,
+ new String[] {"SELECT g_0.intkey AS c_0 FROM BQT1.Smalla AS g_0 ORDER BY
c_0",
+ "SELECT g_0.intkey AS c_0 FROM BQT1.SmallB AS g_0 ORDER BY c_0",
+ "SELECT g_0.intkey AS c_0 FROM bqt2.smallb AS g_0 ORDER BY c_0"},
//$NON-NLS-1$ //$NON-NLS-2$
+ ComparisonMode.EXACT_COMMAND_STRING );
+
+ }
}
Show replies by date