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 ka...@apache.org on 2014/02/21 09:39:25 UTC

svn commit: r1570490 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/sql/ engine/org/apache/derby/impl/jdbc/ engine/org/apache/derby/impl/sql/ testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/

Author: kahatlen
Date: Fri Feb 21 08:39:24 2014
New Revision: 1570490

URL: http://svn.apache.org/r1570490
Log:
DERBY-4753: "ERROR 42X01: Syntax error: FALSE." during call to java.sql.DatabaseMetaData.getIndexInfo

When recompiling a meta-data query after detecting that its plan is
stale, pass down a flag to the compiler to say that it's a meta-data
query and that use of internal syntax is allowed.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java?rev=1570490&r1=1570489&r2=1570490&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java Fri Feb 21 08:39:24 2014
@@ -102,6 +102,7 @@ public interface PreparedStatement
 	 *
 	 * @param activation The activation containing all the local state
 	 *		to execute the plan.
+     * @param forMetaData true if this is a meta-data query
      * @param timeoutMillis timeout value in milliseconds.
 	 *
 	 * @return	A ResultSet for a statement. A ResultSet represents
@@ -112,6 +113,7 @@ public interface PreparedStatement
 	 * @exception StandardException		Thrown on failure
 	 */
     ResultSet execute(Activation activation,
+                      boolean forMetaData,
                       long timeoutMillis)
         throws StandardException;
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=1570490&r1=1570489&r2=1570490&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Fri Feb 21 08:39:24 2014
@@ -1334,7 +1334,8 @@ public class EmbedStatement extends Conn
 				//and clear existing result sets in case this has been cached
 				a.reset();
 				a.setMaxRows(maxRows);
-                ResultSet resultsToWrap = ps.execute(a, timeoutMillis);
+                ResultSet resultsToWrap =
+                        ps.execute(a, forMetaData, timeoutMillis);
                 addWarning(ps.getCompileTimeWarnings());
 				addWarning(a.getWarnings());
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1570490&r1=1570489&r2=1570490&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java Fri Feb 21 08:39:24 2014
@@ -47,7 +47,6 @@ import org.apache.derby.iapi.sql.ResultD
 import org.apache.derby.iapi.sql.ResultSet;
 import org.apache.derby.iapi.sql.Statement;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
-import org.apache.derby.iapi.sql.conn.SQLSessionContext;
 import org.apache.derby.iapi.sql.conn.StatementContext;
 import org.apache.derby.iapi.sql.depend.DependencyManager;
 import org.apache.derby.iapi.sql.depend.Provider;
@@ -251,8 +250,13 @@ public class GenericPreparedStatement
 
 	public void rePrepare(LanguageConnectionContext lcc) 
 		throws StandardException {
+        rePrepare(lcc, false);
+    }
+
+    public void rePrepare(LanguageConnectionContext lcc, boolean forMetaData)
+        throws StandardException {
 		if (!upToDate()) {
-			PreparedStatement ps = statement.prepare(lcc);
+            PreparedStatement ps = statement.prepare(lcc, forMetaData);
 
 			if (SanityManager.DEBUG)
 				SanityManager.ASSERT(ps == this, "ps != this");
@@ -315,7 +319,7 @@ public class GenericPreparedStatement
 		Activation a = getActivation(lcc, false);
 		a.setSingleExecution();
 		lcc.setupSubStatementSessionContext(parent);
-		return executeStmt(a, rollbackParentContext, timeoutMillis);
+        return executeStmt(a, rollbackParentContext, false, timeoutMillis);
 	}
 
 	/**
@@ -329,7 +333,8 @@ public class GenericPreparedStatement
 	{
 		parent.getLanguageConnectionContext().
 			setupSubStatementSessionContext(parent);
-		return executeStmt(activation, rollbackParentContext, timeoutMillis);
+        return executeStmt(activation, rollbackParentContext,
+                           false, timeoutMillis);
 	}
 
 
@@ -337,10 +342,11 @@ public class GenericPreparedStatement
 	 * @see PreparedStatement#execute
 	 */
 	public ResultSet execute(Activation activation,
+                             boolean forMetaData,
 							 long timeoutMillis)
 			throws StandardException
 	{
-		return executeStmt(activation, false, timeoutMillis);
+        return executeStmt(activation, false, forMetaData, timeoutMillis);
 	}
 
 
@@ -351,6 +357,7 @@ public class GenericPreparedStatement
 	  * @param rollbackParentContext True if 1) the statement context is
 	  *  NOT a top-level context, AND 2) in the event of a statement-level
 	  *	 exception, the parent context needs to be rolled back, too.
+      * @param forMetaData true if this is a meta-data query
       * @param timeoutMillis timeout value in milliseconds.
 	  *	@return	the result set to be pawed through
 	  *
@@ -358,6 +365,7 @@ public class GenericPreparedStatement
 	  */
     private ResultSet executeStmt(Activation activation,
 								  boolean rollbackParentContext,
+                                  boolean forMetaData,
 								  long timeoutMillis)
         throws
             StandardException 
@@ -432,7 +440,7 @@ recompileOutOfDatePlan:
 			// to execute.  That exception will be caught by the executeSPS()
 			// method of the GenericTriggerExecutor class, and at that time
 			// the SPS action will be recompiled correctly.
-                rePrepare(lccToUse);
+                rePrepare(lccToUse, forMetaData);
 			}
 
 			StatementContext statementContext = lccToUse.pushStatementContext(

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java?rev=1570490&r1=1570489&r2=1570490&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java Fri Feb 21 08:39:24 2014
@@ -20,16 +20,19 @@ limitations under the License.
 */
 package org.apache.derbyTesting.functionTests.tests.upgradeTests;
 
+import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.util.ArrayList;
+import javax.sql.DataSource;
 
 import org.apache.derby.catalog.SystemProcedures;
 import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetStream;
 import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.JDBCDataSource;
 import org.apache.derbyTesting.junit.TestConfiguration;
 import org.apache.derbyTesting.junit.XML;
 
@@ -1959,4 +1962,62 @@ public class BasicSetup extends UpgradeC
         // PH_SOFT_UPGRADE phase or the PH_HARD_UPGRADE phase.
         JDBC.assertDrainResults(getConnection().getMetaData().getSchemas());
     }
+
+    /**
+     * Verify that recompilation of a stale meta-data query works in soft
+     * upgrade. Before DERBY-4753, it used to fail with a syntax error
+     * because the recompilation didn't accept internal syntax.
+     */
+    public void testDERBY4753() throws SQLException {
+        // Use a separate database for this test case because
+        // 1) we set a database property that we don't want the other test
+        //    cases to see
+        // 2) we want to start with an empty database so that the schema
+        //    changes we make are considered significant enough to make the
+        //    plans stale (in an already populated database, larger changes
+        //    are needed to make the plans stale)
+        final DataSource ds = JDBCDataSource.getDataSourceLogical("DERBY-4753");
+
+        if (getPhase() == PH_CREATE) {
+            // Create the database with the old version and set the stale
+            // plan check interval as low as possible to make the test reach
+            // the stale plan check earlier.
+            JDBCDataSource.setBeanProperty(ds, "createDatabase", "create");
+            Connection c = ds.getConnection();
+            Statement s = c.createStatement();
+            s.execute("call syscs_util.syscs_set_database_property("
+                    + "'derby.language.stalePlanCheckInterval', '5')");
+            s.close();
+            c.close();
+        } else if (getPhase() == PH_SOFT_UPGRADE) {
+            Connection c = ds.getConnection();
+            DatabaseMetaData dmd = c.getMetaData();
+
+            // First make sure the getIndexInfo query is compiled.
+            JDBC.assertEmpty(dmd.getIndexInfo(null, null, "", true, true));
+
+            // Then make some schema changes so that the tables used by the
+            // getIndexInfo query grows so much that they will be recompiled
+            // on the next stale plan check.
+            Statement s = c.createStatement();
+            for (int i = 0; i < 10; i++) {
+                String sql = "create table s" + i + ".t(col0 int";
+                for (int j = 1; j < 1000; j++) {
+                    sql += ", col" + j + " int";
+                }
+                sql += ')';
+                s.execute(sql);
+            }
+            s.close();
+
+            // Finally execute getIndexInfo() as many times as needed to
+            // reach the stale plan check interval so that it is recompiled.
+            // The fifth call used to fail with a syntax error.
+            for (int i = 0; i < 5; i++) {
+                JDBC.assertEmpty(dmd.getIndexInfo(null, null, "", true, true));
+            }
+
+            c.close();
+        }
+    }
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=1570490&r1=1570489&r2=1570490&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Fri Feb 21 08:39:24 2014
@@ -68,6 +68,7 @@ class UpgradeRun extends UpgradeClassLoa
         new AdditionalDb("ENCRYPT_10_2",  true),
         new AdditionalDb("ROLES_10_5", false),
         new AdditionalDb("BUILTIN_10_9", false),
+        new AdditionalDb("DERBY-4753", true),
     };
     
     public static Test suite(final int[] version, boolean useCreateOnUpgrade) {