[teiid-commits] teiid SVN: r3093 - in trunk/engine/src: test/java/org/teiid/query/optimizer and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Fri Apr 15 09:59:42 EDT 2011


Author: shawkins
Date: 2011-04-15 09:59:42 -0400 (Fri, 15 Apr 2011)
New Revision: 3093

Modified:
   trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java
   trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java
Log:
TEIID-1554 fix for npe with order by project optimization

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-15 01:56:17 UTC (rev 3092)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePlanSorts.java	2011-04-15 13:59:42 UTC (rev 3093)
@@ -272,9 +272,17 @@
 		}
 		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());
+			//instead of just calling ruleraiseaccess, we're more selective
+			//we do not want to raise the access node over a project that is handling an unrelated sort
+			PlanNode newRoot = RuleRaiseAccess.raiseAccessNode(root, accessNode, metadata, capFinder, true, record);
+			if (newRoot != null) {
+				root = newRoot;
+				if (accessNode.getParent().getType() == NodeConstants.Types.TUPLE_LIMIT) {
+					newRoot = RulePushLimit.raiseAccessOverLimit(root, accessNode, metadata, capFinder, accessNode.getParent());
+				}
+				if (newRoot != null) {
+					root = newRoot;
+				}
 			}
 		}
 		return root;

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-15 01:56:17 UTC (rev 3092)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestSortOptimization.java	2011-04-15 13:59:42 UTC (rev 3093)
@@ -204,6 +204,14 @@
                                       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 testProjectionRaisingWithAccessAndLimit() 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 limit 1"; //$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();



More information about the teiid-commits mailing list