From: Date: September 3 2008 9:32am Subject: bzr commit into mysql-5.0 branch (gshchepa:2647) Bug#39002 List-Archive: http://lists.mysql.com/commits/53135 X-Bug: 39002 Message-Id: <20080903080655.4DFE640C029@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit #At file:///work/bzr/mysql-5.0-5.1.29-rc-gca/ 2647 Gleb Shchepa 2008-09-03 Bug #39002: The server crashes on the query: INSERT .. SELECT .. ON DUPLICATE KEY UPDATE col=DEFAULT In order to get correct values from update fields that belongs to the SELECT part in the INSERT .. SELECT .. ON DUPLICATE KEY UPDATE statement, the server adds referenced fields to the select list. Part of the code that does this transformation is shared between implementations of the DEFAULT(col) function and the DEFAULT keyword (in the col=DEFAULT expression), and an implementation of the DEFAULT keyword is incomplete. modified: mysql-test/r/default.result mysql-test/t/default.test sql/item.cc per-file messages: mysql-test/r/default.result Added test case for bug #39002. mysql-test/t/default.test Added test case for bug #39002. sql/item.cc The Item_default_value::transform() function has been modified to take into account the fact that the DEFAULT keyword has no arguments unlike the DEFAULT(col) function that always has an argument. === modified file 'mysql-test/r/default.result' --- a/mysql-test/r/default.result 2007-09-20 08:54:46 +0000 +++ b/mysql-test/r/default.result 2008-09-03 07:32:43 +0000 @@ -205,4 +205,19 @@ Warnings: Warning 1364 Field 'id' doesn't have a default value drop view v1; drop table t1; +create table t1 (a int unique); +create table t2 (b int default 10); +insert into t1 (a) values (1); +insert into t2 (b) values (1); +insert into t1 (a) select b from t2 on duplicate key update a=default; +select * from t1; +a +NULL +insert into t1 (a) values (1); +insert into t1 (a) select b from t2 on duplicate key update a=default(b); +select * from t1; +a +NULL +10 +drop table t1, t2; End of 5.0 tests. === modified file 'mysql-test/t/default.test' --- a/mysql-test/t/default.test 2007-02-12 11:41:36 +0000 +++ b/mysql-test/t/default.test 2008-09-03 07:32:43 +0000 @@ -145,5 +145,24 @@ insert into t1 values(default); drop view v1; drop table t1; +# +# Bug #39002: crash with +# INSERT ... SELECT ... ON DUPLICATE KEY UPDATE col=DEFAULT +# + +create table t1 (a int unique); +create table t2 (b int default 10); +insert into t1 (a) values (1); +insert into t2 (b) values (1); + +insert into t1 (a) select b from t2 on duplicate key update a=default; +select * from t1; + +insert into t1 (a) values (1); +insert into t1 (a) select b from t2 on duplicate key update a=default(b); +select * from t1; + +drop table t1, t2; + --echo End of 5.0 tests. === modified file 'sql/item.cc' --- a/sql/item.cc 2008-06-27 15:56:41 +0000 +++ b/sql/item.cc 2008-09-03 07:32:43 +0000 @@ -6039,6 +6039,13 @@ Item *Item_default_value::transform(Item { DBUG_ASSERT(!current_thd->is_stmt_prepare()); + /* + If the value of arg is NULL, then this object represents a constant, + so further transformation is unnecessary (and impossible). + */ + if (!arg) + return 0; + Item *new_item= arg->transform(transformer, args); if (!new_item) return 0;