#At file:///data0/martin/bzr/5.1bt-bug44306/ based on revid:satya.bn@stripped
2861 Martin Hansson 2009-04-21
Bug#44306: Assertion fail on duplicate key error in
'INSERT ... SELECT' statements
The code that produces result rows expected that a duplicate row
error could not occur in INSERT ... SELECT statements with
unfulfilled WHERE conditions. This may happen, however, if the
SELECT list contains only aggregate functions.
Fixed by checking if there is an error before trying to set
status to 'ok'.
@ mysql-test/r/insert_select.result
Bug#44306: Test result
@ mysql-test/t/insert_select.test
Bug#44306: Test case
@ sql/sql_insert.cc
Bug#44306: Fix
modified:
mysql-test/r/insert_select.result
mysql-test/t/insert_select.test
sql/sql_insert.cc
=== modified file 'mysql-test/r/insert_select.result'
--- a/mysql-test/r/insert_select.result 2007-09-24 13:23:40 +0000
+++ b/mysql-test/r/insert_select.result 2009-04-21 12:45:10 +0000
@@ -765,6 +765,11 @@ f1 f2
2 2
10 10
DROP TABLE t1, t2;
+CREATE TABLE t1 ( a INT KEY, b INT );
+INSERT INTO t1 VALUES ( 0, 1 );
+INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
+ERROR 23000: Duplicate entry '0' for key 'PRIMARY'
+DROP TABLE t1;
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
CREATE TABLE t1 (c VARCHAR(30), INDEX ix_c (c(10)));
CREATE TABLE t2 (d VARCHAR(10));
=== modified file 'mysql-test/t/insert_select.test'
--- a/mysql-test/t/insert_select.test 2007-09-24 13:23:40 +0000
+++ b/mysql-test/t/insert_select.test 2009-04-21 12:45:10 +0000
@@ -324,6 +324,16 @@ SELECT * FROM t2;
DROP TABLE t1, t2;
#
+# Bug#44306: Assertion fail on duplicate key error in 'INSERT ... SELECT'
+# statements
+#
+CREATE TABLE t1 ( a INT KEY, b INT );
+INSERT INTO t1 VALUES ( 0, 1 );
+--error ER_DUP_ENTRY
+INSERT INTO t1 ( b ) SELECT MAX( b ) FROM t1 WHERE b = 2;
+DROP TABLE t1;
+
+#
# Bug #26207: inserts don't work with shortened index
#
SET SQL_MODE='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc 2009-04-08 23:58:57 +0000
+++ b/sql/sql_insert.cc 2009-04-21 12:45:10 +0000
@@ -3223,7 +3223,9 @@ bool select_insert::send_eof()
(thd->arg_of_last_insert_id_function ?
thd->first_successful_insert_id_in_prev_stmt :
(info.copied ? autoinc_value_of_last_inserted_row : 0));
- ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
+ /* An error may have been set during execution of aggregate functions. */
+ if (!thd->main_da.is_error())
+ ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
DBUG_RETURN(0);
}
Attachment: [text/bzr-bundle] bzr/mhansson@mysql.com-20090421124510-xrl2hfqutyymlgcg.bundle