You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by ba...@apache.org on 2006/03/03 23:52:50 UTC

svn commit: r382953 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java

Author: bandaram
Date: Fri Mar  3 14:52:48 2006
New Revision: 382953

URL: http://svn.apache.org/viewcvs?rev=382953&view=rev
Log:
DERBY-1073: Reset optimizer timeout for subqueries after new scoped predicates
are pushed into it for next round of evaluation.

If we have predicates that were pushed down to this OptimizerImpl from an
outer query, then we reset the timeout state to prepare for the next round
of optimization.  Otherwise if we timed out during a previous round and then
we get here for another round, we'll immediately "timeout" again before
optimizing any of the Optimizables in our list.  This is okay if we don't
have any predicates from outer queries because in that case the plan we find
this round will be the same one we found in the previous round, in which
case there's no point in resetting the timeout state and doing the work a
second time.  But if we have predicates from an outer query, those predicates
could help us find a much better plan this round than we did in previous
rounds--so we reset the timeout state to ensure that we have a chance to
consider plans that can take advantage of the pushed predicates.

Submitted by Army Brown (qozinx@sbcglobal.net)

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java?rev=382953&r1=382952&r2=382953&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java Fri Mar  3 14:52:48 2006
@@ -284,6 +284,43 @@
 		 */
 		bestCost = getNewCostEstimate(
 			Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
+
+		/* If we have predicates that were pushed down to this OptimizerImpl
+		 * from an outer query, then we reset the timeout state to prepare for
+		 * the next round of optimization.  Otherwise if we timed out during
+		 * a previous round and then we get here for another round, we'll
+		 * immediately "timeout" again before optimizing any of the Optimizables
+		 * in our list.  This is okay if we don't have any predicates from
+		 * outer queries because in that case the plan we find this round
+		 * will be the same one we found in the previous round, in which
+		 * case there's no point in resetting the timeout state and doing
+		 * the work a second time.  But if we have predicates from an outer
+		 * query, those predicates could help us find a much better plan
+		 * this round than we did in previous rounds--so we reset the timeout
+		 * state to ensure that we have a chance to consider plans that
+		 * can take advantage of the pushed predicates.
+		 */
+		boolean resetTimer = false;
+		if ((predicateList != null) && (predicateList.size() > 0))
+		{
+			for (int i = predicateList.size() - 1; i >= 0; i--)
+			{
+				// If the predicate is "scoped", then we know it was pushed
+				// here from an outer query.
+				if (((Predicate)predicateList.
+					getOptPredicate(i)).isScopedForPush())
+				{
+					resetTimer = true;
+					break;
+				}
+			}
+		}
+
+		if (resetTimer)
+		{
+			timeOptimizationStarted = System.currentTimeMillis();
+			timeExceeded = false;
+		}
 	}
 
     public int getMaxMemoryPerTable()