[teiid-commits] teiid SVN: r2822 - in branches/7.1.x: engine/src/main/java/org/teiid/query/optimizer/relational/rules and 1 other directories.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Jan 10 14:51:55 EST 2011


Author: shawkins
Date: 2011-01-10 14:51:55 -0500 (Mon, 10 Jan 2011)
New Revision: 2822

Modified:
   branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
   branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
   branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
   branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
Log:
TEIID-1422 fix for pushing limits too far

Modified: branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
===================================================================
--- branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml	2011-01-10 17:20:37 UTC (rev 2821)
+++ branches/7.1.x/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml	2011-01-10 19:51:55 UTC (rev 2822)
@@ -785,12 +785,12 @@
           be true regardless of which version of Teiid is used.</para>
         </listitem>
         <listitem>
-        <para>RulePushNonJoinCriteria – this rule will push criteria out of
+        <para>RulePushNonJoinCriteria - this rule will push criteria out of
           an on clause if it is not necessary for the correctness of the join.
         </para>
         </listitem>
         <listitem>
-        <para>RuleRaiseNull – this rule will raise null nodes to their
+        <para>RuleRaiseNull - this rule will raise null nodes to their
           highest possible point.  Raising a null node removes the need to
           consider any part of the old plan that was below the null node.
         </para>
@@ -806,12 +806,12 @@
           together.</para>
         </listitem>
         <listitem>
-        <para>RuleRemoveOptionalJoins – removes optional join nodes form
+        <para>RuleRemoveOptionalJoins - removes optional join nodes form
           the plan tree as soon as possible so that planning will be more
           optimal.</para>
         </listitem>
         <listitem>
-        <para>RulePlanJoins – this rule attempts to find an optimal
+        <para>RulePlanJoins - this rule attempts to find an optimal
           ordering of the joins performed in the plan, while ensuring that
           &access_patterns; dependencies are met.  This rule has three main
           steps.  First it must determine an ordering of joins that satisfy
@@ -908,7 +908,7 @@
           retrieved from B, thus greatly speeding the overall query.</para>
         </listitem>
             <listitem>
-        <para>RuleChooseJoinStrategy – Determines the base join strategy.
+        <para>RuleChooseJoinStrategy - Determines the base join strategy.
            Currently this is a decision as to whether to use a merge join rather
           than the default strategy, which is a nested loop join.  Ideally the
           choice of a hash join would also be evaluated here.  Also costing
@@ -932,9 +932,12 @@
           model option.</para>
         </listitem>
             <listitem>
-        <para>RuleAccessPatternValidation – validates that all access
+        <para>RuleAccessPatternValidation - validates that all access
           patterns have been satisfied.</para>
         </listitem>
+        <listitem>
+        <para>RulePushLimit - pushes limit and offset information as far as possible in the plan.</para>
+        </listitem>
         </itemizedlist>
        </section>
        <section>

Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java	2011-01-10 17:20:37 UTC (rev 2821)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java	2011-01-10 19:51:55 UTC (rev 2822)
@@ -142,7 +142,8 @@
             }
             case NodeConstants.Types.SET_OP:
             {
-                if (!SetQuery.Operation.UNION.equals(child.getProperty(NodeConstants.Info.SET_OPERATION))) {
+                if (!SetQuery.Operation.UNION.equals(child.getProperty(NodeConstants.Info.SET_OPERATION)) 
+                		|| !child.hasBooleanProperty(NodeConstants.Info.USE_ALL)) {
                     return false;
                 }                                
                 //distribute the limit
@@ -166,8 +167,6 @@
                 return child.getProperty(NodeConstants.Info.INTO_GROUP) == null;
             }
             case NodeConstants.Types.SOURCE:
-            case NodeConstants.Types.SELECT:
-            case NodeConstants.Types.DUP_REMOVE:
             {
                 return true;
             }
@@ -211,12 +210,6 @@
             return null;
         }
         
-        List<PlanNode> setops = NodeEditor.findAllNodes(accessNode, NodeConstants.Types.SET_OP, NodeConstants.Types.SOURCE);
-        
-        if (!setops.isEmpty()) {
-            return null;
-        }
-        
         Expression limit = (Expression)parentNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
         
         if (limit != null && !CapabilitiesUtil.supportsRowLimit(modelID, metadata, capFinder)) {

Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java	2011-01-10 17:20:37 UTC (rev 2821)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java	2011-01-10 19:51:55 UTC (rev 2822)
@@ -263,9 +263,7 @@
 					return areAggregatesCardinalityDependent(aggs);
 				}
 				case NodeConstants.Types.TUPLE_LIMIT: {
-					if (FrameUtil.isOrderedLimit(parent)) {
-						return true;
-					}
+					return true;
 				}
 				//we assmue that projects of non-deterministic expressions do not matter
 			}

Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java	2011-01-10 17:20:37 UTC (rev 2821)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java	2011-01-10 19:51:55 UTC (rev 2822)
@@ -56,11 +56,7 @@
 
 import junit.framework.TestCase;
 
-
-
-/** 
- * @since 4.3
- */
+ at SuppressWarnings("nls")
 public class TestLimit extends TestCase {
 
     private static final int[] FULL_PUSHDOWN = new int[] {
@@ -460,24 +456,56 @@
     public void testLimitNotPushedWithUnion() {
         FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
         BasicSourceCapabilities caps = new BasicSourceCapabilities();
-        caps.setCapabilitySupport(Capability.QUERY_UNION, true);
         caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
         // pm1 model supports order by
         capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
 
         String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 100";//$NON-NLS-1$
         String[] expectedSql = new String[] {
-            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 UNION SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2" //$NON-NLS-1$
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1", "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2" //$NON-NLS-1$
             };
         ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
                                                     null, capFinder, expectedSql, true);  
 
         TestOptimizer.checkNodeTypes(plan, new int[] {
+            2,      // Access
+            0,      // DependentAccess
+            0,      // DependentSelect
+            0,      // DependentProject
+            1,      // DupRemove
+            0,      // Grouping
+            1,      // Limit
+            0,      // NestedLoopJoinStrategy
+            0,      // MergeJoinStrategy
+            0,      // Null
+            0,      // PlanExecution
+            0,      // Project
+            0,      // Select
+            0,      // Sort
+            1       // UnionAll
+        }, NODE_TYPES);
+    }
+    
+    public void testLimitNotPushedWithDupRemove() {
+        FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+        BasicSourceCapabilities caps = new BasicSourceCapabilities();
+        caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+        // pm1 model supports order by
+        capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+
+        String sql = "SELECT distinct * FROM pm1.g1 LIMIT 100";//$NON-NLS-1$
+        String[] expectedSql = new String[] {
+            "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1" //$NON-NLS-1$
+            };
+        ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), 
+                                                    null, capFinder, expectedSql, true);  
+
+        TestOptimizer.checkNodeTypes(plan, new int[] {
             1,      // Access
             0,      // DependentAccess
             0,      // DependentSelect
             0,      // DependentProject
-            0,      // DupRemove
+            1,      // DupRemove
             0,      // Grouping
             1,      // Limit
             0,      // NestedLoopJoinStrategy
@@ -491,14 +519,14 @@
         }, NODE_TYPES);
     }
     
-    public void testLimitPushedWithUnion() {
+    public void testLimitPushedWithUnionAll() {
         FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
         BasicSourceCapabilities caps = new BasicSourceCapabilities();
         caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
         // pm1 model supports order by
         capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
 
-        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 100";//$NON-NLS-1$
+        String sql = "SELECT * FROM pm1.g1 UNION ALL SELECT * FROM PM1.g2 LIMIT 100";//$NON-NLS-1$
         String[] expectedSql = new String[] {
             "SELECT pm1.g2.e1, pm1.g2.e2, pm1.g2.e3, pm1.g2.e4 FROM PM1.g2 LIMIT 100", "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 100" //$NON-NLS-1$ //$NON-NLS-2$
             };
@@ -510,7 +538,7 @@
             0,      // DependentAccess
             0,      // DependentSelect
             0,      // DependentProject
-            1,      // DupRemove
+            0,      // DupRemove
             0,      // Grouping
             1,      // Limit
             0,      // NestedLoopJoinStrategy
@@ -533,7 +561,7 @@
         // pm1 model supports order by
         capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
 
-        String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 50, 100";//$NON-NLS-1$
+        String sql = "SELECT * FROM pm1.g1 UNION ALL SELECT * FROM PM1.g2 LIMIT 50, 100";//$NON-NLS-1$
         String[] expectedSql = new String[] {
             "SELECT PM1.g2.e1 AS c_0, PM1.g2.e2 AS c_1, PM1.g2.e3 AS c_2, PM1.g2.e4 AS c_3 FROM PM1.g2 LIMIT 150", "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT 150" //$NON-NLS-1$ //$NON-NLS-2$
             };
@@ -545,7 +573,7 @@
             0,      // DependentAccess
             0,      // DependentSelect
             0,      // DependentProject
-            1,      // DupRemove
+            0,      // DupRemove
             0,      // Grouping
             1,      // Limit
             0,      // NestedLoopJoinStrategy



More information about the teiid-commits mailing list