Author: shawkins
Date: 2012-01-06 15:53:01 -0500 (Fri, 06 Jan 2012)
New Revision: 3780
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
Log:
TEIID-1868 TEIID-1533 refining the backoff logic to not be used unless the ndv is known.
Modified:
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
---
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2012-01-06
20:06:41 UTC (rev 3779)
+++
branches/7.6.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2012-01-06
20:53:01 UTC (rev 3780)
@@ -1161,7 +1161,12 @@
for (int i = 0; i < independentExpressions.size(); i++) {
Expression indExpr = (Expression)independentExpressions.get(i);
Collection<ElementSymbol> indElements =
ElementCollectorVisitor.getElements(indExpr, true);
- float indSymbolNDV = getNDVEstimate(independentNode, metadata, independentCardinality,
indElements, true);
+ float indSymbolNDV = getNDVEstimate(independentNode, metadata, independentCardinality,
indElements, false);
+ boolean unknownNDV = false;
+ if (indSymbolNDV == UNKNOWN_VALUE) {
+ unknownNDV = true;
+ indSymbolNDV = independentCardinality/2;
+ }
Expression depExpr = (Expression)dependentExpressions.get(i);
LinkedList<Expression> depExpressions = new LinkedList<Expression>();
@@ -1220,6 +1225,7 @@
}
}
depSymbolNDV = Math.max((float)Math.pow(depTargetCardinality, .75),
Math.min(indSymbolOrigNDV, depTargetCardinality));
+ unknownNDV = true;
} else {
depSymbolNDV = depTargetCardinality;
}
@@ -1236,6 +1242,10 @@
dca.expectedCardinality = Math.min(dca.expectedCardinality, estimates[0]);
}
}
+ //don't use the ndv if it is unknown
+ if (unknownNDV) {
+ continue;
+ }
dca.expectedNdv[i] = indSymbolNDV;
//use a quick binary search to find the max ndv
float min = 0;
Modified:
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java
===================================================================
---
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-01-06
20:06:41 UTC (rev 3779)
+++
branches/7.6.x/engine/src/test/java/org/teiid/query/processor/TestDependentJoins.java 2012-01-06
20:53:01 UTC (rev 3780)
@@ -29,9 +29,11 @@
import java.util.List;
import org.junit.Test;
+import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TransformationMetadata;
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
@@ -832,17 +834,40 @@
}
@Test public void testDependentJoinBackoff() throws Exception {
- // Create query
+ FakeDataManager dataManager = helpTestBackoff(true);
+
+ //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()));
+ }
+
+ @Test public void testDependentJoinBackoff1() throws Exception {
+ FakeDataManager dataManager = helpTestBackoff(false);
+
+ //note that the dependent join was performed
+ assertEquals(4, new HashSet<String>(dataManager.getQueries()).size());
+ }
+
+ private FakeDataManager helpTestBackoff(boolean setNdv) throws Exception,
+ QueryMetadataException, TeiidComponentException,
+ TeiidProcessingException {
+ // 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);
- QueryMetadataInterface fakeMetadata = RealMetadataFactory.example1();
+ TransformationMetadata fakeMetadata = RealMetadataFactory.example1();
RealMetadataFactory.setCardinality("pm1.g1", 1, fakeMetadata);
+ if (setNdv) {
+ fakeMetadata.getElementID("pm1.g1.e1").setDistinctValues(1);
+ }
RealMetadataFactory.setCardinality("pm6.g1", 1000, fakeMetadata);
+ if (setNdv) {
+ fakeMetadata.getElementID("pm6.g1.e1").setDistinctValues(1000);
+ }
// Plan query
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities depcaps = new BasicSourceCapabilities();
@@ -867,11 +892,8 @@
// 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()));
- }
+ return dataManager;
+ }
@Test public void testDjHint() {
// Create query
Show replies by date