Commit 22c2d06d authored by Gleb Shchepa's avatar Gleb Shchepa

backport from mysql-trunk

BUG #11754979 - 46675: ON DUPLICATE KEY UPDATE AND UPDATECOUNT() POSSIBLY WRONG 

The mysql_affected_rows() client call returns 3 instead of 2 on
INSERT ... ON DUPLICATE KEY UPDATE query with a duplicated key value.

The fix for the old bug #29692 was incomplete: unnecessary double
increment of "touched" rows still happened.

This bugfix removes:
1) unneeded increment of "touched" rows and
2) useless double resetting of auto-increment value.


sql/sql_insert.cc:
  write_record() function:
  Unneeded increment of "touched" rows and useless double resetting
  of auto-increment value has been removed.
tests/mysql_client_test.c:
  New test case.
parent 53fb954d
......@@ -1610,9 +1610,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
goto before_trg_err;
table->file->restore_auto_increment(prev_insert_id);
if (table->next_number_field)
table->file->adjust_next_insert_id_after_explicit_value(
table->next_number_field->val_int());
info->touched++;
if (!records_are_comparable(table) || compare_records(table))
{
......@@ -1649,8 +1646,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
if (table->next_number_field)
table->file->adjust_next_insert_id_after_explicit_value(
table->next_number_field->val_int());
info->touched++;
goto ok_or_after_trg_err;
}
else /* DUP_REPLACE */
......
......@@ -19660,6 +19660,34 @@ static void test_bug12337762()
DBUG_VOID_RETURN;
}
/*
BUG 11754979 - 46675: ON DUPLICATE KEY UPDATE AND UPDATECOUNT() POSSIBLY WRONG
*/
static void test_bug11754979()
{
MYSQL* conn;
DBUG_ENTER("test_bug11754979");
myheader("test_bug11754979");
DIE_UNLESS((conn= mysql_client_init(NULL)));
DIE_UNLESS(mysql_real_connect(conn, opt_host, opt_user,
opt_password, opt_db ? opt_db:"test", opt_port,
opt_unix_socket, CLIENT_FOUND_ROWS));
myquery(mysql_query(conn, "DROP TABLE IF EXISTS t1"));
myquery(mysql_query(conn, "CREATE TABLE t1(id INT, label CHAR(1), PRIMARY KEY(id))"));
myquery(mysql_query(conn, "INSERT INTO t1(id, label) VALUES (1, 'a')"));
myquery(mysql_query(conn, "INSERT INTO t1(id, label) VALUES (1, 'a') "
"ON DUPLICATE KEY UPDATE id = 4"));
DIE_UNLESS(mysql_affected_rows(conn) == 2);
myquery(mysql_query(conn, "DROP TABLE t1"));
mysql_close(conn);
DBUG_VOID_RETURN;
}
/*
Read and parse arguments and MySQL options from my.cnf
*/
......@@ -20005,6 +20033,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug56976", test_bug56976 },
{ "test_bug11766854", test_bug11766854 },
{ "test_bug12337762", test_bug12337762 },
{ "test_bug11754979", test_bug11754979 },
{ 0, 0 }
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment