db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpendle...@apache.org
Subject svn commit: r447644 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/sql/compile/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 18 Sep 2006 23:53:11 GMT
Author: bpendleton
Date: Mon Sep 18 16:53:11 2006
New Revision: 447644

URL: http://svn.apache.org/viewvc?view=rev&rev=447644
Log:
DERBY-1589: CREATE TABLE throws NPE after DROPs and REVOKEs

FKConstraintDefinitionNode, which is the compiler implementation code
for the "foreign key ... references ... " constraint in the compiler,
is not properly registering that the statement containing the
foreign key constraint has a dependency on the table being referenced. Due
to the lack of the dependency, when the referenced table (t11ConstraintTest)
is dropped, the statement is not invalidated. 

This patch changes the compiler so that it creates a dependency from
a statement with a FOREIGN KEY clause in it to the table which is
referenced by that clause. The patch also contains a simple regression
test, based on the original bug.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FKConstraintDefinitionNode.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FKConstraintDefinitionNode.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FKConstraintDefinitionNode.java?view=diff&rev=447644&r1=447643&r2=447644
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FKConstraintDefinitionNode.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FKConstraintDefinitionNode.java
Mon Sep 18 16:53:11 2006
@@ -107,6 +107,10 @@
 		// Verify if REFERENCES_PRIV is granted to columns referenced
 		getCompilerContext().pushCurrentPrivType(getPrivType());
 
+		// Indicate that this statement has a dependency on the
+		// table which is referenced by this foreign key:
+		getCompilerContext().createDependency(td);
+
 		// If references clause doesn't have columnlist, get primary key info
 		if (refRcl.size()==0 && (td.getPrimaryKey() != null))
 		{

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out?view=diff&rev=447644&r1=447643&r2=447644
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/grantRevokeDDL.out
Mon Sep 18 16:53:11 2006
@@ -3045,4 +3045,36 @@
 2 rows inserted/updated/deleted
 ij(MAMTA1)> commit;
 ij(MAMTA1)> autocommit on;
-ij(MAMTA1)> 
+ij(MAMTA1)> -- Simple test case for DERBY-1589. The problem here involves dependency
+-- management between the FOREIGN KEY clause in the CREATE TABLE statement
+-- and the underlying table that the FK refers to. The statement must
+-- declare a dependency on the referenced table so that changes to the table
+-- cause invalidation of the statement's compiled plan. The test case below
+-- sets up such a situation by dropping the referenced table and recreating
+-- it and then re-issuing a statement with identical text to one which
+-- was issued earlier.
+set connection mamta1;
+ij(MAMTA1)> create table d1589t11ConstraintTest (c111 int not null, c112 int not null,
primary key (c111, c112));
+0 rows inserted/updated/deleted
+ij(MAMTA1)> grant references on d1589t11ConstraintTest to mamta3;
+0 rows inserted/updated/deleted
+ij(MAMTA1)> set connection mamta3;
+ij(MAMTA3)> drop table d1589t31ConstraintTest;
+ERROR: Failed with SQLSTATE 42Y55
+ij(MAMTA3)> create table d1589t31ConstraintTest (c311 int, c312 int, foreign key(c311,
c312) references mamta1.d1589t11ConstraintTest);
+0 rows inserted/updated/deleted
+ij(MAMTA3)> drop table d1589t31ConstraintTest;
+0 rows inserted/updated/deleted
+ij(MAMTA3)> set connection mamta1;
+ij(MAMTA1)> drop table d1589t11ConstraintTest;
+0 rows inserted/updated/deleted
+ij(MAMTA1)> create table d1589t11ConstraintTest (c111 int not null, c112 int not null,
primary key (c111, c112));
+0 rows inserted/updated/deleted
+ij(MAMTA1)> grant references(c111) on d1589t11ConstraintTest to mamta3;
+0 rows inserted/updated/deleted
+ij(MAMTA1)> grant references(c112) on d1589t11ConstraintTest to PUBLIC;
+0 rows inserted/updated/deleted
+ij(MAMTA1)> set connection mamta3;
+ij(MAMTA3)> create table d1589t31ConstraintTest (c311 int, c312 int, foreign key(c311,
c312) references mamta1.d1589t11ConstraintTest);
+0 rows inserted/updated/deleted
+ij(MAMTA3)> 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql?view=diff&rev=447644&r1=447643&r2=447644
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/grantRevokeDDL.sql
Mon Sep 18 16:53:11 2006
@@ -1924,3 +1924,27 @@
 update mamta2.ttt1 set i = 888;
 commit;
 autocommit on;
+
+-- Simple test case for DERBY-1589. The problem here involves dependency
+-- management between the FOREIGN KEY clause in the CREATE TABLE statement
+-- and the underlying table that the FK refers to. The statement must
+-- declare a dependency on the referenced table so that changes to the table
+-- cause invalidation of the statement's compiled plan. The test case below
+-- sets up such a situation by dropping the referenced table and recreating
+-- it and then re-issuing a statement with identical text to one which
+-- was issued earlier.
+
+set connection mamta1;
+create table d1589t11ConstraintTest (c111 int not null, c112 int not null, primary key (c111,
c112));
+grant references on d1589t11ConstraintTest to mamta3;
+set connection mamta3;
+drop table d1589t31ConstraintTest;
+create table d1589t31ConstraintTest (c311 int, c312 int, foreign key(c311, c312) references
mamta1.d1589t11ConstraintTest);
+drop table d1589t31ConstraintTest;
+set connection mamta1;
+drop table d1589t11ConstraintTest;
+create table d1589t11ConstraintTest (c111 int not null, c112 int not null, primary key (c111,
c112));
+grant references(c111) on d1589t11ConstraintTest to mamta3;
+grant references(c112) on d1589t11ConstraintTest to PUBLIC;
+set connection mamta3;
+create table d1589t31ConstraintTest (c311 int, c312 int, foreign key(c311, c312) references
mamta1.d1589t11ConstraintTest); 



Mime
View raw message