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/03/04 11:00:42 UTC
svn commit: r1573989 - in /db/derby/code/branches/10.10: ./
java/engine/org/apache/derby/iapi/sql/
java/engine/org/apache/derby/impl/jdbc/
java/engine/org/apache/derby/impl/sql/
java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/
Author: kahatlen
Date: Tue Mar 4 10:00:41 2014
New Revision: 1573989
URL: http://svn.apache.org/r1573989
Log:
DERBY-4753: "ERROR 42X01: Syntax error: FALSE." during call to java.sql.DatabaseMetaData.getIndexInfo
Merged revision 1570490 from trunk.
Modified:
db/derby/code/branches/10.10/ (props changed)
db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
Propchange: db/derby/code/branches/10.10/
------------------------------------------------------------------------------
Merged /db/derby/code/trunk:r1570490
Modified: db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java?rev=1573989&r1=1573988&r2=1573989&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/iapi/sql/PreparedStatement.java Tue Mar 4 10:00:41 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/branches/10.10/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=1573989&r1=1573988&r2=1573989&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Tue Mar 4 10:00:41 2014
@@ -1341,7 +1341,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/branches/10.10/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java?rev=1573989&r1=1573988&r2=1573989&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java (original)
+++ db/derby/code/branches/10.10/java/engine/org/apache/derby/impl/sql/GenericPreparedStatement.java Tue Mar 4 10:00:41 2014
@@ -241,8 +241,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");
@@ -305,7 +310,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);
}
/**
@@ -319,7 +324,8 @@ public class GenericPreparedStatement
{
parent.getLanguageConnectionContext().
setupSubStatementSessionContext(parent);
- return executeStmt(activation, rollbackParentContext, timeoutMillis);
+ return executeStmt(activation, rollbackParentContext,
+ false, timeoutMillis);
}
@@ -327,10 +333,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);
}
@@ -341,6 +348,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
*
@@ -348,6 +356,7 @@ public class GenericPreparedStatement
*/
private ResultSet executeStmt(Activation activation,
boolean rollbackParentContext,
+ boolean forMetaData,
long timeoutMillis)
throws
StandardException
@@ -422,7 +431,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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java?rev=1573989&r1=1573988&r2=1573989&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/BasicSetup.java Tue Mar 4 10:00:41 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;
@@ -1958,4 +1961,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/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java?rev=1573989&r1=1573988&r2=1573989&view=diff
==============================================================================
--- db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java (original)
+++ db/derby/code/branches/10.10/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/UpgradeRun.java Tue Mar 4 10:00:41 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) {