Issue Details (XML | Word | Printable)

Key: DERBY-1652
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Yip Ng
Reporter: Kathey Marsden
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Derby

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

Created: 07/Aug/06 01:58 PM   Updated: 30/Jun/09 04:12 PM
Return to search
Component/s: SQL
Affects Version/s: 10.0.2.0, 10.1.3.1, 10.2.1.6
Fix Version/s: 10.1.3.2, 10.2.1.6

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works derby1652-10.1.3-diff.txt 2006-08-08 09:35 AM Yip Ng 7 kB
Text File Licensed for inclusion in ASF works derby1652-10.1.3-stat.txt 2006-08-08 09:35 AM Yip Ng 0.3 kB
Text File Licensed for inclusion in ASF works derby1652-trunk-diff01.txt 2006-08-08 10:05 PM Yip Ng 9 kB
Text File Licensed for inclusion in ASF works derby1652-trunk-stat01.txt 2006-08-08 10:05 PM Yip Ng 0.4 kB
Issue Links:
Reference

Issue & fix info: Release Note Needed
Resolution Date: 17/Aug/06 11:15 PM


 Description  « Hide
Execution of an update trigger that updates the same row as the original update will recurse forever and exceed the maximum nesting level of 16 so should throw the exception:
ERROR 54038: "Maximum depth of nested triggers was exceeded"

However, it does not always throw the exception. For example:


CREATE TABLE "TEST" (
      
 "TESTID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START
 WITH 1,
 INCREMENT BY 1),
      
 "INFO" INTEGER NOT NULL,
      
 "TIMESTAMP" 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 TIMESTAMP = CURRENT_TIMESTAMP WHERE
  TESTID = OLD.TESTID;
 INSERT INTO TEST (INFO) VALUES
 (1),
 (2),
 (3);

 UPDATE TEST SET INFO = 1 WHERE TESTID = 2;

Does not throw an exception:

However, If the derby jars are updated to a new version, the correct exception is thrown.

 Replace derby jars with new version
 Execute the following in ij:
 UPDATE TEST SET INFO = 1 WHERE TESTID = 2;
 ERROR 54038: Maximum depth of nested triggers was exceeded.


Note: This issue stemmed from the Invalid issue, DERBY-1603, because a user hit the exception after upgrade and thought the exception after upgrade, not the lack of exception before upgrade was the problem. This may be a common user error, so we need a release note to help mitigate the issue. I will add one shortly after confirming the correct trigger syntax.






 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Kathey Marsden made changes - 07/Aug/06 02:01 PM
Field Original Value New Value
Link This issue relates to DERBY-1603 [ DERBY-1603 ]
Daniel John Debrunner added a comment - 07/Aug/06 02:30 PM
Does the comment "However, If the derby jars are updated to a new version" mean that the bug is fixed in the new version and so thiis bug is already fixed.
Ie. it is just a problem with some older versions and upgrading to the latest 10.1 will mean the exception is always thrown, no matter how the trigger was created?

Kathey Marsden added a comment - 07/Aug/06 02:45 PM
Dan asked:
>Does the comment "However, If the derby jars are >updated to a new version" mean that the bug is fixed in >the new version and so thiis bug is already fixed.

No if you create this trigger in the latest 10.2 you will see that when it fires it does not give an exception.

It is changing versions that triggers the trigger to start giving the exception. So for instance if you create the trigger in 10.1.3.1, it would fire without error until you moved to 10.1.3.2. Then you would start seeing the exception when the trigger fires. This is why I am concerned about user impact with this issue. The incorrect trigger will operate as the user might think it would until they upgrade and then boom, their application works no more.





Yip Ng added a comment - 08/Aug/06 09:35 AM
Attaching patch for DERBY-1652. The patch is for the 10.1 codebase. A similar patch is needed for 10.2, which I'll post as soon as derbyall completes.

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. Appreciate if someone can review this.

On a side note, I ran derbyall on a *clean* 10.1 codeline and I see the following
failures:

derbyall/derbyall.fail:unit/T_Diagnosticable.unit
derbyall/derbyall.fail:i18n/urlLocale.sql
derbyall/derbyall.fail:i18n/messageLocale.sql
derbyall/derbyall.fail:i18n/iepnegativetests_ES.sql
derbyall/derbynetclientmats/derbynetmats.fail:derbynet/sysinfo.java
derbyall/derbynetmats/derbynetmats.fail:derbynet/sysinfo.java

Is this a known problem?

Yip Ng made changes - 08/Aug/06 09:35 AM
Attachment derby1652-10.1.3-diff.txt [ 12338363 ]
Attachment derby1652-10.1.3-stat.txt [ 12338362 ]
Yip Ng made changes - 08/Aug/06 09:35 AM
Derby Info [Release Note Needed, Existing Application Impact] [Patch Available, Existing Application Impact, Release Note Needed]
Yip Ng added a comment - 08/Aug/06 10:05 PM
Attaching patch for DERBY-1652. This patch applies to the trunk codeline. Derbyall still running, will confirm if it passes successfully in subsequent comment. Nevertheless, the patch is ready for review.

Yip Ng made changes - 08/Aug/06 10:05 PM
Attachment derby1652-trunk-diff01.txt [ 12338422 ]
Attachment derby1652-trunk-stat01.txt [ 12338421 ]
Yip Ng added a comment - 09/Aug/06 07:15 AM
derbyall passes with derby1652-trunk-diff01.txt.

Yip Ng added a comment - 10/Aug/06 03:47 AM
This patch appears to add a duplicate entry to the dependency table. Need to investigate...

Yip Ng made changes - 10/Aug/06 03:47 AM
Derby Info [Patch Available, Existing Application Impact, Release Note Needed] [Existing Application Impact, Release Note Needed]
Yip Ng made changes - 10/Aug/06 06:06 PM
Derby Info [Release Note Needed, Existing Application Impact] [Patch Available, Existing Application Impact, Release Note Needed]
Yip Ng added a comment - 10/Aug/06 06:07 PM
False alarm. Renabling patch available.

Yip Ng made changes - 11/Aug/06 12:53 AM
Derby Info [Release Note Needed, Existing Application Impact, Patch Available] [Patch Available, Existing Application Impact, Release Note Needed]
Fix Version/s 10.2.0.0 [ 11187 ]
Yip Ng made changes - 11/Aug/06 08:22 AM
Affects Version/s 10.1.3.1 [ 12311953 ]
Derby Info [Existing Application Impact, Patch Available, Release Note Needed] [Patch Available, Existing Application Impact, Release Note Needed]
Affects Version/s 10.2.0.0 [ 11187 ]
Dag H. Wanvik added a comment - 11/Aug/06 03:20 PM
The patch look good.

When the trunk patch is applied I get the desired error on the repro,
without it, I do not. I also checked with soft and hard upgrade (from
10.1 trunk) and its still works in those cases. I did not try out the
10.1 version of the patch.

The diagnosis seems correct from looking locally at the code, although
I have not traced the logic fully to where the dependency actually
gets picked up.

Minor nit on the code: The variable tmpTriggerId may be done away
with, or at least its comment text updated; it is no longer so
meaningful now that the sps creation is moved out, but if you prefer,
I am ok with leaving that to the committer's discretion.

+1

Yip Ng added a comment - 11/Aug/06 06:04 PM
Thanks for the taking the time to review this patch, Dag. The local variable tmpTriggerId is kept because it is still needed later by the createSPS method. As for when the dependency will get picked up, it is at the trigger action's bind phase.

Dag H. Wanvik added a comment - 14/Aug/06 02:33 PM
Yes, I know it's used by the createSPS methods; my point was that you
could do away with it by using TriggerDecriptor#getUUID instead once
triggerd is created. In the old code, a variable was necessary, since
the trigger was referenced before creation. Just a detail, I agree.

Kathey Marsden added a comment - 15/Aug/06 03:16 AM
I don't know much about this code area but I looked at this patch as I am very keen to see this in to 10.2 and would also like to get it into 10.1 as soon as possible. The approach looks reasonable to me but I have to admit I don't understand the full impact of moving the trigger descriptor creation before compiling the SPS, so I don't have too much to offer in terms of code review.

On the tests, I have some questions about the the test updates
In updateableResultSet.java we have this diff.

                        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();

By changing a different value are we still performing the action described?

Similarly in triggerGeneral master update we had previously positive test cases that now throw an error. Might we be able to use the workaround you gave me, to specify on which columns the trigger will fire to retain the original semantics of these tests?


Yip Ng added a comment - 15/Aug/06 08:00 AM
For the updatableResultSet.java, yes, it will still perform the action described because the triggers are also modified to preserve the original intention of the test.

The master output for triggerGeneral.sql were incorrect for those testcases, so I just replaced them with the expected results (I thought they were "negative" tests with wrong results). I tried to preserve the original testcase intent whenever I can but the column list specification won't work on those testcases since they are using an "after insert" trigger. And that test file already have tests to insert to another table from the trigger action, so now those tests really become "negative"...

Mike Matrigali added a comment - 15/Aug/06 04:21 PM
I am looking at committing the trunk submitted diff, assuming there is no objection. It seems like Dag's comment can be handled as a separate item. To this end I ran all the tests on XP, sun jdk1.4.2 and got
3 diffs:
derbyall/derbynetmats/DerbyNet/jdbcapi/blobclob4BLOB.diff (known issue showing up in the tinderbox tests)
derbyall/upgrade/Upgrade_10_1_10_2.diff (known issue showing up in the tinderbox tests)
and the following I need to investigate:
*** Start: _Suite jdk1.4.2_07 DerbyNetClient derbynetmats:jdbcapi 2006-08-14 19:
57:40 ***
0 add
> ..................................E...E.
> There were 2 errors:
> 1) testUpdateUpdatedTupleScrollUpdateRow(org.apache.derbyTesting.functionTests
.tests.jdbcapi.URCoveringIndexTest)java.lang.OutOfMemoryError
> 2) testNextOnLastRowForwardOnly(org.apache.derbyTesting.functionTests.tests.jd
bcapi.ScrollResultSetTest)java.lang.OutOfMemoryError
> FAILURES!!!
> Tests run: 817, Failures: 0, Errors: 2
Test Failed.
*** End: _Suite jdk1.4.2_07 DerbyNetClient derbynetmats:jdbcapi 2006-08-14 20:
01:56 ***

Mike Matrigali made changes - 15/Aug/06 04:21 PM
Derby Info [Release Note Needed, Patch Available, Existing Application Impact] [Patch Available, Existing Application Impact, Release Note Needed]
Kathey Marsden added a comment - 15/Aug/06 07:33 PM
Yip said
>I thought they were "negative" tests with wrong results
Thanks Yip, I think I got confused because of the comments: "--after" and the trigger name: "tgood" don't lend themselves to a negative test. If more work is done on the patch it might be good to change them for clarity moving forward.

ij> -- after
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;
ERROR 54038: Maximum depth of nested triggers was exceeded.

Repository Revision Date User Message
ASF #431698 Tue Aug 15 20:55:21 UTC 2006 mikem DERBY-1652, submitted 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.
Files Changed
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
MODIFY /db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
MODIFY /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out

Mike Matrigali added a comment - 15/Aug/06 08:57 PM
I reproduced the out of memory on my machine in a clean codeline so do not believe it is caused by this
patch. I also have reported DERBY-1701 for those out of memory errors which have been showing up in the public regression test runs on a number of platforms.

I committed this patch as is, feeling the comments above were not worth holding up the patch. They seem like good things to do, but not necessary to hold up the fix.

m1_142:97>svn commit

Sending java\engine\org\apache\derby\impl\sql\execute\CreateTriggerConstantAction.java
Sending java\engine\org\apache\derby\impl\store\raw\data\OverflowInputStream.java
Sending java\testing\org\apache\derbyTesting\functionTests\master\triggerGeneral.out
Sending java\testing\org\apache\derbyTesting\functionTests\tests\lang\triggerGeneral.sql
Sending java\testing\org\apache\derbyTesting\functionTests\tests\lang\updatableResultSet.java
Transmitting file data .....
Committed revision 431698.

Yip Ng added a comment - 17/Aug/06 06:03 AM
I think this issue should be considered as resolved once the changes have also been updated to 10.1 codeline.

Yip Ng made changes - 17/Aug/06 06:25 AM
Link This issue is related to DERBY-1261 [ DERBY-1261 ]
Repository Revision Date User Message
ASF #432165 Thu Aug 17 06:32:27 UTC 2006 kmarsden 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.
Files Changed
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
MODIFY /db/derby/code/branches/10.1/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
MODIFY /db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java

Kathey Marsden added a comment - 17/Aug/06 06:45 AM
Thanks Yip. Committed to 10.1

Date: Wed Aug 16 23:32:27 2006
New Revision: 432165

URL: http://svn.apache.org/viewvc?rev=432165&view=rev
We still need the release note as users may hit the error unexpectedly on upgrade and may need to change their triggers to specify which column in the trigger that will invoke the trigger action per Yip's suggestion at:
http://www.nabble.com/Re%3A--jira--Commented%3A-%28DERBY-1603%29-ERROR-54038%3A-%22Maximum-depth-of-nested-triggers-was-exceeded%22-occurs-when-trigger-fires-after-upating-10.1.2.5-jars-to-10.1.3.1-p5689247.html

I'm afraid I can't get to that right away after all. It will have to wait a while if I do it.

Thanks

Kathey


Mike Matrigali made changes - 17/Aug/06 11:15 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Repository Revision Date User Message
ASF #432658 Fri Aug 18 17:37:49 UTC 2006 rhillegas DERBY-1725: Merge trunk into 10.2 branch from 430947 through 431743. Merges in patches to the following JIRAs: DERBY-415 DERBY-1652 DERBY-1694 DERBY-1691 DERBY-1688 DERBY-1574 DERBY-766 DERBY-1664 DERBY-634.
Files Changed
MODIFY /db/derby/code/branches/10.2/java/tools/org/apache/derby/impl/tools/sysinfo/Main.java
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupNewDBTest.java (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupNewDBTest.java)
DEL /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest_app.properties
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/updatableResultSet.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/services/bytecode/BCMethod.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/DerbyNet/blobclob4BLOB.out
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/DataType.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/services/bytecode/CodeChunk.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery2.sql
ADD /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf)
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/suites/DerbyNet.exclude
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/subquery.out
DEL /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest_app.properties
MODIFY /db/derby/code/branches/10.2/java/drda/org/apache/derby/impl/drda/ConsistencyToken.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/derbyrunjartest.out
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/subquery2.out
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testProperties.java
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/build.xml (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/build.xml)
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/subquery.sql
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/copyfiles.ant (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/copyfiles.ant)
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/store/raw/data/OverflowInputStream.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/master/triggerGeneral.out
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupExistingDBTest_app.properties (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupExistingDBTest_app.properties)
ADD /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/util/JarUtil.java (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/JarUtil.java)
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/lang/triggerGeneral.sql
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/UpdateXXXTest.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/execute/CreateTriggerConstantAction.java
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/existingDb.jar (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/existingDb.jar)
MODIFY /db/derby/code/branches/10.2/java/testing/build.xml
REPLACE /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupExistingDBTest.java (from /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/perf/StartupExistingDBTest.java)
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/derbynet/testSecMec.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/types/XML.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/execute/BaseActivation.java
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/impl/sql/compile/CoalesceFunctionNode.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/_Suite.java
MODIFY /db/derby/code/branches/10.2/java/testing/org/apache/derbyTesting/functionTests/suites/jdbcapi.runall
MODIFY /db/derby/code/branches/10.2/java/engine/org/apache/derby/iapi/sql/compile/Optimizer.java

Repository Revision Date User Message
ASF #432715 Fri Aug 18 20:24:00 UTC 2006 rhillegas DERBY-1725: Dummy commit to record the following linkages just in case I failed to correctly update the commit comments for the previous commits on this issue. The preceding commits merged the following patches from the trunk to the 10.2 branch: Merge 1 (432641): DERBY-1556. Merge 2 (432651): DERBY-1130 DERBY-1556 DERBY-1593. Merge 3 (432658): DERBY-415 DERBY-1652 DERBY-1694 DERBY-1691 DERBY-1688 DERBY-1574 DERBY-766 DERBY-1664 DERBY-634. Merge 4 (432679): DERBY-244 DERBY-1710 DERBY-1712 DERBY-1555 DERBY-1701 DERBY-1691 DERBY-1681 DERBY-1032 DERBY-1692.
Files Changed
MODIFY /db/derby/code/branches/10.2/BUILDING.txt

Yip Ng added a comment - 28/Aug/06 12:29 AM
Here is the release note for this jira:


Release Note for DERBY-1652
-------------------------------------------

PROBLEM

   In some cases, an after update trigger does not get fired upon itself when its trigger action contains
an update statement on the trigger's subject table.


SYMPTOMS

   (1) When defining a trigger for the first time for a table, e.g.:

  
        CREATE TABLE "TEST" ("TESTID" INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
                             "INFO" INTEGER NOT NULL,
                             "TIMESTAMP" 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 TIMESTAMP = CURRENT_TIMESTAMP WHERE TESTID = OLD.TESTID;
  
        INSERT INTO TEST (INFO) VALUES (1), (2), (3);

        UPDATE TEST SET INFO = 1 WHERE TESTID = 2;


        The above update statement executes successfully which it is incorrect. The system should have issued
        SQLSTATE 54038 since it self-triggers to its maximum depth of 16.

   
   (2) With the above example, when an user upgrades to a higher version and issues the same update statement:

        UPDATE TEST SET INFO = 1 WHERE TESTID = 2;
        ERROR 54038: Maximum depth of nested triggers was exceeded.

The SQLSTATE 54038 is issued in this case because after database upgrade, the trigger action will be
        invalidated by the system and will force a recompilation of the trigger when it is fired. The system
        generates the correct execution plan this time and since the trigger behavior have changed, this might
        cause applications to break unexpectedly.


CAUSE

   Derby's did not generate the correct execution plan for self-trigger invocation when such a trigger is declared
   for the first time on the subject table; hence, resulting in the stated problem above. The affected version is
   Derby 10.0 and 10.1.


SOLUTION

   A fix to resolve the above Derby symptom is available in 10.1 and 10.2.


WORKAROUND

   If self-trigger invocation was not intended by the application, the application can select which column(s) on the
   update statement can cause the trigger to fire in the cREATE TRIGGER statement. i.e.:

   CREATE TRIGGER update_test
   AFTER UPDATE OF INFO ON test
   REFERENCING OLD AS old
   FOR EACH ROW MODE DB2SQL
       UPDATE test SET timestamp=current_timestamp WHERE testid=old.testid;
 
   In the above statement, the trigger will only fire when an update is made to the "info" column instead of any column(s).

   

Kathey Marsden made changes - 21/Feb/07 06:26 PM
Status Resolved [ 5 ] Closed [ 6 ]
Dag H. Wanvik made changes - 30/Jun/09 04:12 PM
Issue & fix info [Release Note Needed, Existing Application Impact, Patch Available] [Release Note Needed]