List:Commits« Previous MessageNext Message »
From:igor Date:January 12 2007 6:12am
Subject:bk commit into 5.0 tree (igor:1.2378) BUG#25398
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-01-11 21:12:50-08:00, igor@stripped +3 -0
  Fixed bug #25398: crash in a trigger when using trigger fields 
  in a select list.
  The objects of the Item_trigger_field class inherited the methods
  copy_or_same and get_tmp_table_item from the class Item_field while
  they rather should have used the default implementations defined 
  for the base class Item.
  It could cause catastrophic problems for triggers that used SELECTs
  with select list containing trigger fields such as NEW.<table column>
  under DISTINCT.

  mysql-test/r/trigger.result@stripped, 2007-01-11 21:12:46-08:00, igor@stripped +32 -0
    Added a test case for bug #25398.

  mysql-test/t/trigger.test@stripped, 2007-01-11 21:12:46-08:00, igor@stripped +46 -0
    Added a test case for bug #25398.

  sql/item.h@stripped, 2007-01-11 21:12:46-08:00, igor@stripped +2 -0
    Fixed bug #25398: crash in a trigger when using trigger fields 
    in a select list.
    The objects of the Item_trigger_field class inherited the implementations
    of the methods copy_or_same and get_tmp_table_item from the class Item_field
    while they rather should have used the default implementations defined 
    for the base class Item.
    It could cause catastrophic problems for triggers that used SELECTs
    with select list containing trigger fields such as NEW.<table column>
    under DISTINCT.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	igor
# Host:	olga.mysql.com
# Root:	/home/igor/dev-opt/mysql-5.0-opt-bug25398

--- 1.216/sql/item.h	2007-01-11 21:12:55 -08:00
+++ 1.217/sql/item.h	2007-01-11 21:12:55 -08:00
@@ -2269,6 +2269,8 @@
   bool fix_fields(THD *, Item **);
   void print(String *str);
   table_map used_tables() const { return (table_map)0L; }
+  Item *copy_or_same(THD *thd) { return this; }
+  Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
   void cleanup();
 
 private:

--- 1.50/mysql-test/r/trigger.result	2007-01-11 21:12:55 -08:00
+++ 1.51/mysql-test/r/trigger.result	2007-01-11 21:12:55 -08:00
@@ -1278,4 +1278,36 @@
 2	b
 3	c
 drop table t1;
+CREATE TABLE t1 (
+id int NOT NULL DEFAULT '0',
+a  varchar(10) NOT NULL,
+b  varchar(10),
+c  varchar(10),
+d  timestamp NOT NULL,
+PRIMARY KEY (id, a)
+);
+CREATE TABLE t2 (
+fubar_id         int unsigned NOT NULL DEFAULT '0',
+last_change_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+PRIMARY KEY  (fubar_id)
+);
+CREATE TRIGGER fubar_change
+AFTER UPDATE ON t1
+FOR EACH ROW
+BEGIN
+INSERT INTO t2 (fubar_id, last_change_time)
+SELECT DISTINCT NEW.id AS fubar_id, NOW() AS last_change_time
+FROM t1 WHERE (id = NEW.id) AND (OLD.c != NEW.c)
+ON DUPLICATE KEY UPDATE
+last_change_time =
+IF((fubar_id = NEW.id)AND(OLD.c != NEW.c),NOW(),last_change_time);
+END
+|
+INSERT INTO t1 (id,a, b,c,d) VALUES
+(1,'a','b','c',now()),(2,'a','b','c',now());
+UPDATE t1 SET c='Bang!' WHERE id=1;
+SELECT fubar_id FROM t2;
+fubar_id
+1
+DROP TABLE t1,t2;
 End of 5.0 tests

--- 1.57/mysql-test/t/trigger.test	2007-01-11 21:12:55 -08:00
+++ 1.58/mysql-test/t/trigger.test	2007-01-11 21:12:55 -08:00
@@ -1548,4 +1548,50 @@
 
 drop table t1;
 
+#
+# Bug#25398: crash when a trigger contains a SELECT with 
+#            trigger fields in the select list under DISTINCT
+#
+
+CREATE TABLE t1 (
+  id int NOT NULL DEFAULT '0',
+  a  varchar(10) NOT NULL,
+  b  varchar(10),
+  c  varchar(10),
+  d  timestamp NOT NULL,
+  PRIMARY KEY (id, a)
+);
+
+CREATE TABLE t2 (
+  fubar_id         int unsigned NOT NULL DEFAULT '0',
+  last_change_time datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+  PRIMARY KEY  (fubar_id)
+);
+
+DELIMITER |;
+
+CREATE TRIGGER fubar_change
+  AFTER UPDATE ON t1
+    FOR EACH ROW
+      BEGIN
+        INSERT INTO t2 (fubar_id, last_change_time)
+          SELECT DISTINCT NEW.id AS fubar_id, NOW() AS last_change_time
+            FROM t1 WHERE (id = NEW.id) AND (OLD.c != NEW.c)
+        ON DUPLICATE KEY UPDATE
+          last_change_time =
+            IF((fubar_id = NEW.id)AND(OLD.c != NEW.c),NOW(),last_change_time);
+      END
+|
+
+DELIMITER ;|
+
+INSERT INTO t1 (id,a, b,c,d) VALUES
+ (1,'a','b','c',now()),(2,'a','b','c',now());
+
+UPDATE t1 SET c='Bang!' WHERE id=1;
+
+SELECT fubar_id FROM t2;
+
+DROP TABLE t1,t2;
+
 --echo End of 5.0 tests
Thread
bk commit into 5.0 tree (igor:1.2378) BUG#25398igor12 Jan