db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmars...@apache.org
Subject svn commit: r432165 - in /db/derby/code/branches/10.1/java: engine/org/apache/derby/impl/sql/execute/ testing/org/apache/derbyTesting/functionTests/master/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Thu, 17 Aug 2006 06:32:28 GMT
Author: kmarsden
Date: Wed Aug 16 23:32:27 2006
New Revision: 432165

URL: http://svn.apache.org/viewvc?rev=432165&view=rev
Log:
DERBY-1652 - Update trigger updating the same rows as the original update does not throw an
exception ERROR 54038: "Maximum depth of nested triggers was exceeded" as it should


Contributed by Yip Ng


The cause of the problem is that the trigger descriptor is created after the stored prepared
statement(SPS) has been compiled, so the compiled form of the SPS is not aware of that its
trigger action can fire on the trigger table itself. Hence, the constant action was not generated
correctly.

During upgrade, the SPSs are invalidated at database boot time. The SPS will be recompile
when it is being invoked and the recompilation at this point will of course detect the relevent
trigger and generate the correct constant action for the SPS and produce the expected behavior
when the SPS is executed - throwing an error when it exceeds the trigger's maximum depth in
the above case.

The simplest solution without introducing another revalidation of the SPS is to create the
trigger descriptor first before compiling the SPS. I ran derbyall and had to go over the testcases
which have the wrong master outputs and I have corrected them on this patch.



Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
    db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java?rev=432165&r1=432164&r2=432165&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
(original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
Wed Aug 16 23:32:27 2006
@@ -257,22 +257,16 @@
 		*/
 		UUID tmpTriggerId = dd.getUUIDFactory().createUUID();
 
-		/*	
-		** If we have a WHEN action we create it now.
-		*/ 
+		actionSPSId = (actionSPSId == null) ? 
+			dd.getUUIDFactory().createUUID() : actionSPSId;
+		 
 		DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
-		if (whenText != null)
-		{
-			whenspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
-						whenSPSId, spsCompSchemaId, whenText, true, triggerTable);
-		}
-
-		/*
-		** Create the trigger action
-		*/
-		actionspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
-						actionSPSId, spsCompSchemaId, actionText, false, triggerTable);
 		
+		/*
+		** Create the trigger descriptor first so the trigger action
+		** compilation can pick up the relevant trigger especially in 
+		** the case of self triggering.
+		*/ 
 		TriggerDescriptor triggerd = 
 				ddg.newTriggerDescriptor(
 									triggerSd,
@@ -284,7 +278,7 @@
 									isEnabled,
 									triggerTable,
 									whenspsd == null ? null : whenspsd.getUUID(),
-									actionspsd.getUUID(),
+									actionSPSId,
 									creationTimestamp == null ? new Timestamp(System.currentTimeMillis()) : creationTimestamp,
 									referencedCols,
 									originalActionText,
@@ -297,6 +291,21 @@
 		dd.addDescriptor(triggerd, triggerSd,
 								DataDictionary.SYSTRIGGERS_CATALOG_NUM, false,
 								tc);
+		/*	
+		** If we have a WHEN action we create it now.
+		*/
+		if (whenText != null)
+		{
+			whenspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
+				whenSPSId, spsCompSchemaId, whenText, true, triggerTable);
+		}
+
+		/*
+		** Create the trigger action
+		*/
+		actionspsd = createSPS(lcc, ddg, dd, tc, tmpTriggerId, triggerSd,
+			actionSPSId, spsCompSchemaId, actionText, false, triggerTable);
+	
 
 		/*
 		** Make underlying spses dependent on the trigger.

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out?rev=432165&r1=432164&r2=432165&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
Wed Aug 16 23:32:27 2006
@@ -1196,12 +1196,10 @@
 create trigger tgood after insert on x for each statement mode db2sql insert into x values
666;
 0 rows inserted/updated/deleted
 ij> insert into x values 1;
-1 row inserted/updated/deleted
+ERROR 54038: Maximum depth of nested triggers was exceeded.
 ij> select * from x;
 X          
 -----------
-1          
-666        
 ij> drop trigger tgood;
 0 rows inserted/updated/deleted
 ij> create trigger tgood after insert on x for each statement mode db2sql delete from
x;
@@ -1251,4 +1249,18 @@
 ij(CONNECTION1)> create trigger mytrigger after update on myschema.mytable for each row
mode db2sql select * from sys.systables;
 0 rows inserted/updated/deleted
 ij(CONNECTION1)> rollback;
+ij(CONNECTION1)> create table test (testid integer not null 
+    generated always as identity (start with 1, increment by 1), 
+    info integer not null, ts timestamp not null default '1980-01-01-00.00.00.000000');
+0 rows inserted/updated/deleted
+ij(CONNECTION1)> create trigger update_test 
+    after update on test 
+    referencing old as old 
+    for each row mode db2sql 
+    update test set ts=current_timestamp where testid=old.testid;
+0 rows inserted/updated/deleted
+ij(CONNECTION1)> insert into test(info) values (1),(2),(3);
+3 rows inserted/updated/deleted
+ij(CONNECTION1)> UPDATE TEST SET INFO = 1 WHERE TESTID = 2;
+ERROR 54038: Maximum depth of nested triggers was exceeded.
 ij(CONNECTION1)> 

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql?rev=432165&r1=432164&r2=432165&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
Wed Aug 16 23:32:27 2006
@@ -602,3 +602,13 @@
 create trigger mytrigger after update on myschema.mytable for each row mode db2sql select
* from sys.systables;
 rollback;
 
+create table test (testid integer not null 
+    generated always as identity (start with 1, increment by 1), 
+    info integer not null, ts timestamp not null default '1980-01-01-00.00.00.000000');
+create trigger update_test 
+    after update on test 
+    referencing old as old 
+    for each row mode db2sql 
+    update test set ts=current_timestamp where testid=old.testid;
+insert into test(info) values (1),(2),(3);
+UPDATE TEST SET INFO = 1 WHERE TESTID = 2;

Modified: db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java?rev=432165&r1=432164&r2=432165&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
(original)
+++ db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
Wed Aug 16 23:32:27 2006
@@ -1210,7 +1210,7 @@
 			rs.next();
 			System.out.println("column 1 on this row is " + rs.getInt(1));
 			System.out.println("this update row will fire the update trigger which will update all
the rows in the table to have c1=1 and hence no more rows will qualify for the resultset");
-			rs.updateLong(1,123);
+			rs.updateLong(2,2);
 			rs.updateRow();
 			rs.next();
 			try {
@@ -2456,9 +2456,9 @@
 		stmt.executeUpdate("create trigger tr1 after delete on table0WithTriggers for each statement
mode db2sql insert into deleteTriggerInsertIntoThisTable values (1)");
 		stmt.executeUpdate("create trigger tr2 after update on table0WithTriggers for each statement
mode db2sql insert into updateTriggerInsertIntoThisTable values (1)");
 		stmt.executeUpdate("create table table1WithTriggers (c1 int, c2 bigint)");
-		stmt.executeUpdate("create trigger tr3 after delete on table1WithTriggers for each statement
mode db2sql delete from table1WithTriggers");
+		stmt.executeUpdate("create trigger tr3 after delete on table1WithTriggers referencing old
as old for each row mode db2sql delete from table1WithTriggers where c1=old.c1+1 or c1=old.c1-1");
 		stmt.executeUpdate("create table table2WithTriggers (c1 int, c2 bigint)");
-		stmt.executeUpdate("create trigger tr4 after update on table2WithTriggers for each statement
mode db2sql update table2WithTriggers set c1=1");
+		stmt.executeUpdate("create trigger tr4 after update of c2 on table2WithTriggers for each
statement mode db2sql update table2WithTriggers set c1=1");
 		stmt.executeUpdate("create table selfReferencingT1 (c1 char(2) not null, c2 char(2), constraint
selfReferencingT1 primary key(c1), constraint manages1 foreign key(c2) references selfReferencingT1(c1)
on delete cascade)");
 		stmt.executeUpdate("create table selfReferencingT2 (c1 char(2) not null, c2 char(2), constraint
selfReferencingT2 primary key(c1), constraint manages2 foreign key(c2) references selfReferencingT2(c1)
on update restrict)");
 



Mime
View raw message