db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r909176 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java
Date Thu, 11 Feb 2010 23:34:39 GMT
Author: bpendleton
Date: Thu Feb 11 23:34:35 2010
New Revision: 909176

URL: http://svn.apache.org/viewvc?rev=909176&view=rev
Log:
DERBY-4479: RENAME TABLE needs to invalidate any cached CREATE TABLE statement

The problem involves a missing dependency between the CREATE TABLE statement
and the table that it is creating. For other types of statements, the
dependency of the statement on the table is generally registered during
compilation.

However, this isn't quite so easy with the CREATE TABLE statement, because
the table descriptor doesn't exist during compilation, since the table isn't
created until the statement is actually executed.

This change registers the dependency at execution time. At the very end of
CreateTableConstantAction.executeConstantAction, there is
some new code added to register a dependency from the CREATE TABLE
statement to the table we have just finished creating. 

A new test is also added.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java?rev=909176&r1=909175&r2=909176&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTableConstantAction.java
Thu Feb 11 23:34:35 2010
@@ -376,6 +376,16 @@
 		{
 			lcc.addDeclaredGlobalTempTable(td);
 		}
+
+		// Indicate that the CREATE TABLE statement itself depends on the
+		// table it is creating. Normally such statement dependencies are
+		// added during compilation, but here we have a bootstrapping issue
+		// because the table doesn't exist until the CREATE TABLE statement
+		// has been executed, so we had to defer the creation of this
+		// dependency until now. (DERBY-4479)
+		dd.getDependencyManager().addDependency(
+			activation.getPreparedStatement(), td, lcc.getContextManager());
+
 	}
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java?rev=909176&r1=909175&r2=909176&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/RenameTableTest.java
Thu Feb 11 23:34:35 2010
@@ -230,4 +230,26 @@
         // select * from tcheck1;
         s.executeUpdate("drop table tcheck1");
     }
+
+    /**
+     * Tests that rename table invalidates stored statement plans (DERBY-4479).
+     *
+     * By issuing the *identical* create table statement after the rename,
+     * we check to see whether the compiled statements from the first
+     * create table statement were properly invalidated by the rename.
+     * 
+     * @exception SQLException
+     */
+    public void testRenameInvalidation_derby_4479()
+        throws SQLException
+    {
+        getConnection().setAutoCommit(true);
+        Statement s = createStatement();
+        s.executeUpdate("create table a (x int not null primary key)");
+        s.executeUpdate("rename table a to b");
+        s.executeUpdate("create table a (x int not null primary key)");
+        s.executeUpdate("drop table a");
+        s.executeUpdate("drop table b");
+    }
+
 }



Mime
View raw message