From: Date: September 8 2005 1:29pm Subject: bk commit into 4.1 tree (evgen:1.2394) BUG#12695 List-Archive: http://lists.mysql.com/internals/29497 X-Bug: 12695 Message-Id: <20050908112909.BB86013E8D1@localhost.moonbone.local> Below is the list of changes that have just been committed into a local 4.1 repository of evgen. When evgen 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 1.2394 05/09/08 15:29:06 evgen@stripped +3 -0 Fix bug #12695 Duplicate entry 'xxxxx for key 1 INSERT ... SELECT ... statement was wrongly optimized for this case. Here SELECT by itself doesn't require tmp table, and optimized accordingly. But because data is selected from and inserted to same table, tmp table is added into process of execution. All rows selected from source table is inserted into tmp table, and after tmp table filling sum func is fully calculated. When insert starts to inserting data it produces several same rows, which is lead to data being inserted and error reported. This patch forces grouping on tmp table if sum func is present and only reason for tmp table is buffering for INSERT ... SELECT. mysql-test/r/insert_select.result 1.28 05/09/08 15:28:17 evgen@stripped +10 -0 Test case for bug#12695 Duplicate entry 'xxxxx for key 1 mysql-test/t/insert_select.test 1.22 05/09/08 15:27:53 evgen@stripped +10 -0 Test case for bug#12695 Duplicate entry 'xxxxx for key 1 sql/sql_select.cc 1.433 05/09/08 15:26:53 evgen@stripped +4 -0 Fix bug #12695 Duplicate entry 'xxxxx for key 1 # 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: evgen # Host: moonbone.local # Root: /work/12695-bug-4.1-mysql --- 1.432/sql/sql_select.cc 2005-08-22 15:46:12 +04:00 +++ 1.433/sql/sql_select.cc 2005-09-08 15:26:53 +04:00 @@ -1157,6 +1157,10 @@ if (tmp_join) curr_join= tmp_join; curr_tmp_table= exec_tmp_table1; + if (curr_join->tmp_table_param.sum_func_count && + test(curr_join->select_options & OPTION_BUFFER_RESULT) && + make_group_fields(this, curr_join)) + DBUG_VOID_RETURN; /* Copy data to the temporary table */ thd->proc_info= "Copying to tmp table"; --- 1.27/mysql-test/r/insert_select.result 2005-06-27 17:46:33 +04:00 +++ 1.28/mysql-test/r/insert_select.result 2005-09-08 15:28:17 +04:00 @@ -668,3 +668,13 @@ insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b; ERROR 42S02: Unknown table 't2' in field list drop table t1,t2,t3; +create table t1(f1 varchar(5) key); +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +select * from t1; +f1 +2000 +2001 +2002 +drop table t1; --- 1.21/mysql-test/t/insert_select.test 2005-07-28 04:21:43 +04:00 +++ 1.22/mysql-test/t/insert_select.test 2005-09-08 15:27:53 +04:00 @@ -204,4 +204,14 @@ insert into t1 select t2.a from t2 group by t2.a on duplicate key update a= t1.a + t2.b; drop table t1,t2,t3; +# +# Bug #12695 Duplicate entry 'xxxxx for key 1 +# +create table t1(f1 varchar(5) key); +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +insert into t1(f1) select if(max(f1) is null, '2000',max(f1)+1) from t1; +select * from t1; +drop table t1; + # End of 4.1 tests