db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r1534465 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java
Date Tue, 22 Oct 2013 02:37:12 GMT
Author: kmarsden
Date: Tue Oct 22 02:37:12 2013
New Revision: 1534465

URL: http://svn.apache.org/r1534465
Log:
DERBY-2130 - Optimizer performance slowdown from 10.1 to 10.2

Patch contributed by Army Brown


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/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/OptimizerImpl.java?rev=1534465&r1=1534464&r2=1534465&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 Tue
Oct 22 02:37:12 2013
@@ -223,13 +223,8 @@ class OptimizerImpl implements Optimizer
 		this.numTablesInQuery = numTablesInQuery;
 		numOptimizables = optimizableList.size();
 		proposedJoinOrder = new int[numOptimizables];
-		if (numTablesInQuery > 6)
-		{
-			permuteState = READY_TO_JUMP;
-			firstLookOrder = new int[numOptimizables];
-		}
-		else
-			permuteState = NO_JUMP;
+        if (initJumpState() == READY_TO_JUMP)
+            firstLookOrder = new int[numOptimizables];
 
 		/* Mark all join positions as unused */
 		for (int i = 0; i < numOptimizables; i++)
@@ -385,7 +380,27 @@ class OptimizerImpl implements Optimizer
 		 * phase in certain situations.  DERBY-1866.
 		 */
 		desiredJoinOrderFound = false;
-	}
+        
+        /*
+         * If we JUMPed permutations last round, it's possible that we timed out
+         * before finishing all of the jump processing (most likely we ended in
+         * the middle of a WALK_LOW). So reset the jump state here to make sure
+         * we get a clean start. Failure to do so can lead to execution of
+         * code-paths that are not expected and thus incorrect cost estimates
+         * (most notably, an uninitialized bestCost, which we should never see).
+         * DERBY-1905.
+         */
+        initJumpState();
+    }
+    
+    /**
+     * Determine if we want to try "jumping" permutations with this
+     * OptimizerImpl, and (re-)initialize the permuteState field accordingly.
+     */
+    private int initJumpState() {
+        permuteState = (numTablesInQuery >= 6 ? READY_TO_JUMP : NO_JUMP);
+        return permuteState;
+    }
 
     private  boolean tracingIsOn() { return lcc.optimizerTracingIsOn(); }
 



Mime
View raw message