db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1512294 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ResultSetNode.java engine/org/apache/derby/impl/sql/compile/SelectNode.java testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
Date Fri, 09 Aug 2013 13:22:40 GMT
Author: rhillegas
Date: Fri Aug  9 13:22:40 2013
New Revision: 1512294

URL: http://svn.apache.org/r1512294
Log:
DERBY-6211: Mark the end of join optimization with a call to traceEndQueryBlock(); commit
derby-6211-13-aa-SelectNode_optimizer.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java?rev=1512294&r1=1512293&r2=1512294&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/ResultSetNode.java Fri
Aug  9 13:22:40 2013
@@ -1475,39 +1475,6 @@ public abstract class ResultSetNode exte
 	}
 
 	/**
-	 * Get an optimizer to use for this ResultSetNode.  Only get it once -
-	 * subsequent calls return the same optimizer.
-	 *
-	 * @exception StandardException		Thrown on error
-	 */
-	protected Optimizer getOptimizer(
-							OptimizableList optList,
-							OptimizablePredicateList predList,
-							DataDictionary dataDictionary,
-							RequiredRowOrdering requiredRowOrdering,
-							OptimizerPlan overridingPlan)
-			throws StandardException
-	{
-		if (optimizer == null)
-		{
-			/* Get an optimizer. */
-			OptimizerFactory optimizerFactory = getLanguageConnectionContext().getOptimizerFactory();
-
-			optimizer = optimizerFactory.getOptimizer(
-											optList,
-											predList,
-											dataDictionary,
-											requiredRowOrdering,
-											getCompilerContext().getNumTables(),
-											overridingPlan,
-								getLanguageConnectionContext());
-		}
-
-		optimizer.prepForNextRound();
-		return optimizer;
-	}
-
-	/**
 	 * Get the optimizer for this result set.
 	 * 
 	 * @return If this.optimizer has has already been created by the

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java?rev=1512294&r1=1512293&r2=1512294&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/SelectNode.java Fri
Aug  9 13:22:40 2013
@@ -32,8 +32,12 @@ import org.apache.derby.iapi.services.co
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.sql.compile.CompilerContext;
 import org.apache.derby.iapi.sql.compile.CostEstimate;
+import org.apache.derby.iapi.sql.compile.OptimizableList;
+import org.apache.derby.iapi.sql.compile.OptimizablePredicateList;
 import org.apache.derby.iapi.sql.compile.Optimizer;
+import org.apache.derby.iapi.sql.compile.OptimizerFactory;
 import org.apache.derby.iapi.sql.compile.OptimizerPlan;
+import org.apache.derby.iapi.sql.compile.RequiredRowOrdering;
 import org.apache.derby.iapi.sql.compile.Visitor;
 import org.apache.derby.iapi.sql.conn.Authorizer;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
@@ -2041,7 +2045,43 @@ class SelectNode extends ResultSetNode
 			havingSubquerys.optimize(dataDictionary, costEstimate.rowCount());
 		}
 
-		return this;
+        // dispose of the optimizer we created above
+        if ( optimizerTracingIsOn() ) { getOptimizerTracer().traceEndQueryBlock(); }
+
+        return this;
+	}
+
+	/**
+	 * Get an optimizer to use for this SelectNode.  Only get it once -
+	 * subsequent calls return the same optimizer.
+	 *
+	 * @exception StandardException		Thrown on error
+	 */
+	private Optimizer getOptimizer(
+							OptimizableList optList,
+							OptimizablePredicateList predList,
+							DataDictionary dataDictionary,
+							RequiredRowOrdering requiredRowOrdering,
+							OptimizerPlan overridingPlan)
+			throws StandardException
+	{
+		if (optimizer == null)
+		{
+			/* Get an optimizer. */
+			OptimizerFactory optimizerFactory = getLanguageConnectionContext().getOptimizerFactory();
+
+			optimizer = optimizerFactory.getOptimizer(
+											optList,
+											predList,
+											dataDictionary,
+											requiredRowOrdering,
+											getCompilerContext().getNumTables(),
+											overridingPlan,
+								getLanguageConnectionContext());
+		}
+
+		optimizer.prepForNextRound();
+		return optimizer;
 	}
 
 	/**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java?rev=1512294&r1=1512293&r2=1512294&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/XMLOptimizerTraceTest.java
Fri Aug  9 13:22:40 2013
@@ -188,6 +188,33 @@ public class XMLOptimizerTraceTest  exte
                  "create index r_a on r( a )"
                  );
         }
+        
+        if ( !tableExists( conn, "T1" ) )
+        {
+            goodStatement
+                (
+                 conn,
+                 "create table t1( c1 int, c2 int, c3 int )"
+                 );
+        }
+        
+        if ( !tableExists( conn, "T2" ) )
+        {
+            goodStatement
+                (
+                 conn,
+                 "create table t2( c1 int, c2 int, c3 int )"
+                 );
+        }
+        
+        if ( !tableExists( conn, "T3" ) )
+        {
+            goodStatement
+                (
+                 conn,
+                 "create table t3( c1 int, c2 int, c3 int )"
+                 );
+        }
     }
     
     ///////////////////////////////////////////////////////////////////////////////////
@@ -293,6 +320,9 @@ public class XMLOptimizerTraceTest  exte
              conn,
              "call syscs_util.syscs_register_tool( 'optimizerTracingViews', false )"
              );
+
+        // use planCost to examine an outer join
+        vetOuterJoin( conn );
     }
 
     /**
@@ -542,6 +572,72 @@ public class XMLOptimizerTraceTest  exte
         goodStatement( conn, "drop type ArrayList restrict" );
     }
 
+
+    /**
+     * <p>
+     * Test xml optimizer tracing of outer joins.
+     * </p>
+     */
+    private void vetOuterJoin( Connection conn ) throws Exception
+    {
+        File    traceFile = SupportFilesSetup.getReadWrite( TRACE_FILE_NAME );
+
+        // turn on xml-based optimizer tracing
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracing', true, 'xml' )"
+             );
+
+        // run an outer join
+        goodStatement
+            (
+             conn,
+             "select * from t3, (t1 left outer join t2 on t1.c1 = t2.c1) where t3.c1 = t1.c1"
+             );
+
+        // turn off optimizer tracing
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracing', false, '" + traceFile.getPath()
+ "' )"
+             );
+
+        // load the trace viewer
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracingViews', true, '" + traceFile.getPath()
+ "' )"
+             );
+
+        // verify the plan shapes which were considered
+        PreparedStatement   ps = chattyPrepare
+            (
+             conn,
+             "select distinct summary from planCost\n" +
+             "where complete and qbID = 1\n" +
+             "order by summary\n"
+             );
+        ResultSet   rs = ps.executeQuery();
+        rs.next();
+        String  summary1 = rs.getString( 1 ).trim();
+        rs.next();
+        String  summary2 = rs.getString( 1 ).trim();
+        assertTrue( summary1.startsWith( "( \"APP\"." ) );
+        assertTrue( summary1.endsWith( " * ProjectRestrictNode )" ) );
+        assertTrue( summary2.startsWith( "( ProjectRestrictNode # \"APP\"." ) );
+        rs.close();
+        ps.close();
+
+        // unload the trace viewer
+        goodStatement
+            (
+             conn,
+             "call syscs_util.syscs_register_tool( 'optimizerTracingViews', false )"
+             );
+
+    }
+    
    ///////////////////////////////////////////////////////////////////////////////////
     //
     // MINIONS



Mime
View raw message