summaryrefslogtreecommitdiff
path: root/storage/innobase
diff options
context:
space:
mode:
authorThirunarayanan Balathandayuthapani <thirunarayanan.balathandayuth@oracle.com>2016-08-26 11:00:44 +0530
committerMarko Mäkelä <marko.makela@mariadb.com>2019-07-23 10:58:56 +0300
commit07ba5560da805c766da68811692272dd9eebdaf7 (patch)
treeac13ffa21690820e69617afedef896756582df2f /storage/innobase
parent82563c5fc0a40d64d8e8e9de2bf6f904fa6c0dc6 (diff)
downloadmariadb-git-07ba5560da805c766da68811692272dd9eebdaf7.tar.gz
Bug #20989615 INNODB AUTO_INCREMENT PRODUCES SAME VALUE TWICE
Problem: ======= Autoincrement value gives duplicate values because of the following reasons. (1) In InnoDB handler function, current autoincrement value is not changed based on newly set auto_increment_increment or auto_increment_offset variable. (2) Handler function does the rounding logic and changes the current autoincrement value and InnoDB doesn't aware of the change in current autoincrement value. Solution: ======== Fix the problem(1), InnoDB always respect the auto_increment_increment and auto_increment_offset value in case of current autoincrement value. By fixing the problem (2), handler layer won't change any current autoincrement value. Reviewed-by: Jimmy Yang <jimmy.yang@oracle.com> RB: 13748
Diffstat (limited to 'storage/innobase')
-rw-r--r--storage/innobase/handler/ha_innodb.cc32
-rw-r--r--storage/innobase/row/row0mysql.c2
2 files changed, 34 insertions, 0 deletions
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 287eae5681c..8b48552eed4 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -5350,6 +5350,7 @@ no_commit:
innodb_srv_conc_enter_innodb(prebuilt->trx);
error = row_insert_for_mysql((byte*) record, prebuilt);
+ DEBUG_SYNC(user_thd, "ib_after_row_insert");
/* Handle duplicate key errors */
if (auto_inc_used) {
@@ -10461,6 +10462,37 @@ ha_innobase::get_auto_increment(
ulonglong col_max_value = innobase_get_int_col_max_value(
table->next_number_field);
+ /** The following logic is needed to avoid duplicate key error
+ for autoincrement column.
+
+ (1) InnoDB gives the current autoincrement value with respect
+ to increment and offset value.
+
+ (2) Basically it does compute_next_insert_id() logic inside InnoDB
+ to avoid the current auto increment value changed by handler layer.
+
+ (3) It is restricted only for insert operations. */
+
+ if (increment > 1 && thd_sql_command(user_thd) != SQLCOM_ALTER_TABLE
+ && autoinc < col_max_value) {
+
+ ulint prev_auto_inc = autoinc;
+
+ autoinc = ((autoinc - 1) + increment - offset)/ increment;
+
+ autoinc = autoinc * increment + offset;
+
+ /* If autoinc exceeds the col_max_value then reset
+ to old autoinc value. Because in case of non-strict
+ sql mode, boundary value is not considered as error. */
+
+ if (autoinc >= col_max_value) {
+ autoinc = prev_auto_inc;
+ }
+
+ ut_ad(autoinc > 0);
+ }
+
/* Called for the first time ? */
if (trx->n_autoinc_rows == 0) {
diff --git a/storage/innobase/row/row0mysql.c b/storage/innobase/row/row0mysql.c
index 2c39ec4587f..ad07ff7709d 100644
--- a/storage/innobase/row/row0mysql.c
+++ b/storage/innobase/row/row0mysql.c
@@ -1241,6 +1241,8 @@ run_again:
row_ins_step(thr);
+ DEBUG_SYNC_C("ib_after_row_insert_step");
+
err = trx->error_state;
if (err != DB_SUCCESS) {