diff options
author | unknown <heikki@hundin.mysql.fi> | 2002-11-15 18:46:23 +0200 |
---|---|---|
committer | unknown <heikki@hundin.mysql.fi> | 2002-11-15 18:46:23 +0200 |
commit | 6e289b7d06721e84665491e55b5287a8a2fa11ec (patch) | |
tree | fb977c32e5d532ca8f99b762d278b7e22e331c50 /sql/ha_innodb.cc | |
parent | c717613b8dc6abca6cbeedfa7a359b2af8f1390d (diff) | |
download | mariadb-git-6e289b7d06721e84665491e55b5287a8a2fa11ec.tar.gz |
ha_innodb.cc:
Fix bug intoduced in 4.0.4 in REPLACE and AUTO_INCREMENT: if replace did an update, then auto-inc counter was left 1 too low
sql/ha_innodb.cc:
Fix bug intoduced in 4.0.4 in REPLACE and AUTO_INCREMENT: if replace did an update, then auto-inc counter was left 1 too low
Diffstat (limited to 'sql/ha_innodb.cc')
-rw-r--r-- | sql/ha_innodb.cc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index d4e5d0e43cf..d473d27e1fc 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -1697,6 +1697,7 @@ ha_innobase::write_row( longlong dummy; ibool incremented_auto_inc_for_stat = FALSE; ibool incremented_auto_inc_counter = FALSE; + ibool skip_auto_inc_decr; DBUG_ENTER("ha_innobase::write_row"); @@ -1861,13 +1862,25 @@ ha_innobase::write_row( if (error != DB_SUCCESS) { /* If the insert did not succeed we restore the value of the auto-inc counter we used; note that this behavior was - introduced only in version 4.0.4 */ + introduced only in version 4.0.4. + NOTE that a REPLACE command handles a duplicate key error + itself, and we must not decrement the autoinc counter + if we are performing a REPLACE statement. This was fixed + in 4.0.6. */ + + skip_auto_inc_decr = FALSE; + + if (error == DB_DUPLICATE_KEY) { + ut_a(user_thd->query); + dict_accept(user_thd->query, "REPLACE", + &skip_auto_inc_decr); + } - if (incremented_auto_inc_counter) { + if (!skip_auto_inc_decr && incremented_auto_inc_counter) { dict_table_autoinc_decrement(prebuilt->table); } - if (incremented_auto_inc_for_stat) { + if (!skip_auto_inc_decr && incremented_auto_inc_for_stat) { auto_inc_counter_for_this_stat--; } } |