Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 24454 invoked from network); 16 Feb 2011 01:32:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Feb 2011 01:32:21 -0000 Received: (qmail 15664 invoked by uid 500); 16 Feb 2011 01:32:21 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 15468 invoked by uid 500); 16 Feb 2011 01:32:20 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 15456 invoked by uid 99); 16 Feb 2011 01:32:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Feb 2011 01:32:20 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 16 Feb 2011 01:32:18 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 980821A693B for ; Wed, 16 Feb 2011 01:31:57 +0000 (UTC) Date: Wed, 16 Feb 2011 01:31:57 +0000 (UTC) From: "Dag H. Wanvik (JIRA)" To: derby-dev@db.apache.org Message-ID: <684787913.19342.1297819917619.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <2349786.35221288975482368.JavaMail.jira@thor> Subject: [jira] Updated: (DERBY-4887) ALTER TABLE DROP COLUMN leaves the dependent trigger invalid rather than drop it MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/DERBY-4887?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Dag H. Wanvik updated DERBY-4887: --------------------------------- Urgency: Normal Bug behavior facts: [Deviation from standard] Labels: derby_triage10_8 (was: ) What ill effects (could) happen due to this? Marking with Normal urgency, but I did consider Urgent. Any thoughts? > ALTER TABLE DROP COLUMN leaves the dependent trigger invalid rather than drop it > -------------------------------------------------------------------------------- > > Key: DERBY-4887 > URL: https://issues.apache.org/jira/browse/DERBY-4887 > Project: Derby > Issue Type: Bug > Components: SQL > Reporter: Mamta A. Satoor > Assignee: Mamta A. Satoor > Labels: derby_triage10_8 > Attachments: repro.txt > > > If a trigger references a column, it seems like ALTER TABLE DROP COLUMN should either > (a) refuse to run, because the trigger is referencing that column, or > (b) drop the column, and also drop the trigger . > Leaving the trigger in the system, referencing a non-existent column, does not seem like desirable behavior. > It seems like the "CASCADE" and "RESTRICT" forms of DROP COLUMN should control whether case (a) or (b) is taken by the ALTER TABLE. > Currently, ALTER TABLE DROP COLUMN leaves the stored prepared statement for trigger action invalid. The trigger action relies on the column positions of the columns but those positoins are not valid anymore after ALTER TABLE DROP COLUMN. In worst case scenario, the trigger action ends up using data for invalid columns. eg of that is as follows > connect 'jdbc:derby:wombat;create=true'; > -- Create the table > CREATE TABLE tab ( > element_id INTEGER NOT NULL, > altered_id VARCHAR(30) NOT NULL, > counter SMALLINT NOT NULL DEFAULT 0, > timets TIMESTAMP NOT NULL > ); > -- Create a trigger against the table > CREATE TRIGGER mytrig > AFTER UPDATE ON tab > REFERENCING NEW AS newt OLD AS oldt > FOR EACH ROW MODE DB2SQL > UPDATE tab set tab.counter = CASE WHEN (oldt.counter < 32767) THEN (oldt.counter + 1) ELSE 1 END > WHERE ((newt.counter is null) or (oldt.counter = newt.counter)) > AND newt.element_id = tab.element_id > AND newt.altered_id = tab.altered_id; > -- Next, we dop and recreate the column (with a different length) and a row into the table > alter table tab drop column altered_id; > ALTER TABLE TAB ADD COLUMN altered_id VARCHAR(64); > insert into tab(element_id, altered_id, counter, timets) values (99, '1234567890',1,CURRENT_TIMESTAMP); > select * from tab; > ELEMENT_ID |COUNT&|TIMETS |ALTERED_ID > ---------------------------------------------------------------------------- > 99 |1 |2010-11-03 10:05:29.39 |1234567890 > -- the following update will cause the trigger to fire which should increment the counter column's value from 1 to 2 but it doesn't. The explanation is below > update tab set timets = CURRENT_TIMESTAMP where ELEMENT_ID = 99; > select * from tab; > ELEMENT_ID |COUNT&|TIMETS |ALTERED_ID > 99 |1 |2010-11-03 10:05:38.343 |1234567890 > The update should have incremented the counter column to 2 but it remains at 1 because of invalid column positions in stored prepared statement created for trigger action. > More background on general topic of trigger action plan can also be found at DERBY-4874 -- This message is automatically generated by JIRA. - For more information on JIRA, see: http://www.atlassian.com/software/jira