Loading mysql-test/r/innodb.result +19 −0 Original line number Diff line number Diff line Loading @@ -3245,3 +3245,22 @@ where table_schema='test' and table_name = 't1'; table_comment data_free_is_set this is a comment 1 drop table t1; CREATE TABLE t1 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 VARCHAR(128) NOT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100; CREATE TABLE t2 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; AUTO_INCREMENT 200 ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; AUTO_INCREMENT 200 DROP TABLE t2; DROP TABLE t1; mysql-test/t/innodb.test +23 −0 Original line number Diff line number Diff line Loading @@ -2436,6 +2436,29 @@ select table_comment, data_free > 0 as data_free_is_set where table_schema='test' and table_name = 't1'; drop table t1; # # Bug 34920 test # CONNECTION default; CREATE TABLE t1 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 VARCHAR(128) NOT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100; CREATE TABLE t2 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; DROP TABLE t2; DROP TABLE t1; # End 34920 test ####################################################################### # # # Please, DO NOT TOUCH this file as well as the innodb.result file. # Loading storage/innobase/dict/dict0dict.c +3 −3 Original line number Diff line number Diff line Loading @@ -429,7 +429,7 @@ void dict_table_autoinc_initialize( /*==========================*/ dict_table_t* table, /* in: table */ ib_longlong value) /* in: next value to assign to a row */ ib_ulonglong value) /* in: next value to assign to a row */ { ut_ad(mutex_own(&table->autoinc_mutex)); Loading @@ -441,7 +441,7 @@ dict_table_autoinc_initialize( Reads the next autoinc value (== autoinc counter value), 0 if not yet initialized. */ ib_longlong ib_ulonglong dict_table_autoinc_read( /*====================*/ /* out: value for a new row, or 0 */ Loading Loading @@ -470,7 +470,7 @@ dict_table_autoinc_update( /*======================*/ dict_table_t* table, /* in: table */ ib_longlong value) /* in: value which was assigned to a row */ ib_ulonglong value) /* in: value which was assigned to a row */ { if (table->autoinc_inited && value > table->autoinc) { Loading storage/innobase/handler/ha_innodb.cc +43 −16 Original line number Diff line number Diff line Loading @@ -3545,7 +3545,19 @@ ha_innobase::write_row( if (auto_inc > prebuilt->last_value) { set_max_autoinc: ut_a(prebuilt->table->autoinc_increment > 0); auto_inc += prebuilt->table->autoinc_increment; ulonglong have; ulonglong need; /* Check for overflow conditions. */ need = prebuilt->table->autoinc_increment; have = ~0x0ULL - auto_inc; if (have < need) { need = have; } auto_inc += need; err = innobase_set_max_autoinc(auto_inc); Loading Loading @@ -5105,8 +5117,15 @@ ha_innobase::create( DBUG_ASSERT(innobase_table != 0); if ((create_info->used_fields & HA_CREATE_USED_AUTO) && (create_info->auto_increment_value != 0)) { /* Note: We can't call update_thd() as prebuilt will not be setup at this stage and so we use thd. */ /* We need to copy the AUTOINC value from the old table if this is an ALTER TABLE. */ if (((create_info->used_fields & HA_CREATE_USED_AUTO) || thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && create_info->auto_increment_value != 0) { /* Query was ALTER TABLE...AUTO_INCREMENT = x; or CREATE TABLE ...AUTO_INCREMENT = x; Find out a table Loading Loading @@ -5856,7 +5875,7 @@ ha_innobase::info( } if (flag & HA_STATUS_AUTO && table->found_next_number_field) { longlong auto_inc; ulonglong auto_inc; int ret; /* The following function call can the first time fail in Loading Loading @@ -7207,9 +7226,9 @@ ha_innobase::innobase_read_and_init_auto_inc( /*=========================================*/ /* out: 0 or generic MySQL error code */ longlong* value) /* out: the autoinc value */ ulonglong* value) /* out: the autoinc value */ { longlong auto_inc; ulonglong auto_inc; ibool stmt_start; int mysql_error = 0; dict_table_t* innodb_table = prebuilt->table; Loading Loading @@ -7260,7 +7279,9 @@ ha_innobase::innobase_read_and_init_auto_inc( index, autoinc_col_name, &auto_inc); if (error == DB_SUCCESS) { if (auto_inc < ~0x0ULL) { ++auto_inc; } dict_table_autoinc_initialize(innodb_table, auto_inc); } else { ut_print_timestamp(stderr); Loading Loading @@ -7313,14 +7334,14 @@ ha_innobase::innobase_get_auto_increment( error = innobase_autoinc_lock(); if (error == DB_SUCCESS) { ib_longlong autoinc; ulonglong autoinc; /* Determine the first value of the interval */ autoinc = dict_table_autoinc_read(prebuilt->table); /* We need to initialize the AUTO-INC value, for that we release all locks.*/ if (autoinc <= 0) { if (autoinc == 0) { trx_t* trx; trx = prebuilt->trx; Loading @@ -7339,14 +7360,11 @@ ha_innobase::innobase_get_auto_increment( mysql_error = innobase_read_and_init_auto_inc( &autoinc); if (!mysql_error) { /* Should have read the proper value */ ut_a(autoinc > 0); } else { if (mysql_error) { error = DB_ERROR; } } else { *value = (ulonglong) autoinc; *value = autoinc; } /* A deadlock error during normal processing is OK and can be ignored. */ Loading Loading @@ -7431,10 +7449,19 @@ ha_innobase::get_auto_increment( /* With old style AUTOINC locking we only update the table's AUTOINC counter after attempting to insert the row. */ if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) { ulonglong have; ulonglong need; /* Check for overflow conditions. */ need = *nb_reserved_values * increment; have = ~0x0ULL - *first_value; if (have < need) { need = have; } /* Compute the last value in the interval */ prebuilt->last_value = *first_value + (*nb_reserved_values * increment); prebuilt->last_value = *first_value + need; ut_a(prebuilt->last_value >= *first_value); Loading storage/innobase/handler/ha_innodb.h +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ class ha_innobase: public handler int update_thd(THD* thd); int change_active_index(uint keynr); int general_fetch(uchar* buf, uint direction, uint match_mode); int innobase_read_and_init_auto_inc(longlong* ret); int innobase_read_and_init_auto_inc(ulonglong* ret); ulong innobase_autoinc_lock(); ulong innobase_set_max_autoinc(ulonglong auto_inc); ulong innobase_reset_autoinc(ulonglong auto_inc); Loading Loading
mysql-test/r/innodb.result +19 −0 Original line number Diff line number Diff line Loading @@ -3245,3 +3245,22 @@ where table_schema='test' and table_name = 't1'; table_comment data_free_is_set this is a comment 1 drop table t1; CREATE TABLE t1 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 VARCHAR(128) NOT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100; CREATE TABLE t2 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; AUTO_INCREMENT 200 ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; AUTO_INCREMENT 200 DROP TABLE t2; DROP TABLE t1;
mysql-test/t/innodb.test +23 −0 Original line number Diff line number Diff line Loading @@ -2436,6 +2436,29 @@ select table_comment, data_free > 0 as data_free_is_set where table_schema='test' and table_name = 't1'; drop table t1; # # Bug 34920 test # CONNECTION default; CREATE TABLE t1 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 VARCHAR(128) NOT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=100; CREATE TABLE t2 ( c1 INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, c2 INT(10) UNSIGNED DEFAULT NULL, PRIMARY KEY(c1) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=200; SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; ALTER TABLE t2 ADD CONSTRAINT t1_t2_1 FOREIGN KEY(c1) REFERENCES t1(c1); SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't2'; DROP TABLE t2; DROP TABLE t1; # End 34920 test ####################################################################### # # # Please, DO NOT TOUCH this file as well as the innodb.result file. # Loading
storage/innobase/dict/dict0dict.c +3 −3 Original line number Diff line number Diff line Loading @@ -429,7 +429,7 @@ void dict_table_autoinc_initialize( /*==========================*/ dict_table_t* table, /* in: table */ ib_longlong value) /* in: next value to assign to a row */ ib_ulonglong value) /* in: next value to assign to a row */ { ut_ad(mutex_own(&table->autoinc_mutex)); Loading @@ -441,7 +441,7 @@ dict_table_autoinc_initialize( Reads the next autoinc value (== autoinc counter value), 0 if not yet initialized. */ ib_longlong ib_ulonglong dict_table_autoinc_read( /*====================*/ /* out: value for a new row, or 0 */ Loading Loading @@ -470,7 +470,7 @@ dict_table_autoinc_update( /*======================*/ dict_table_t* table, /* in: table */ ib_longlong value) /* in: value which was assigned to a row */ ib_ulonglong value) /* in: value which was assigned to a row */ { if (table->autoinc_inited && value > table->autoinc) { Loading
storage/innobase/handler/ha_innodb.cc +43 −16 Original line number Diff line number Diff line Loading @@ -3545,7 +3545,19 @@ ha_innobase::write_row( if (auto_inc > prebuilt->last_value) { set_max_autoinc: ut_a(prebuilt->table->autoinc_increment > 0); auto_inc += prebuilt->table->autoinc_increment; ulonglong have; ulonglong need; /* Check for overflow conditions. */ need = prebuilt->table->autoinc_increment; have = ~0x0ULL - auto_inc; if (have < need) { need = have; } auto_inc += need; err = innobase_set_max_autoinc(auto_inc); Loading Loading @@ -5105,8 +5117,15 @@ ha_innobase::create( DBUG_ASSERT(innobase_table != 0); if ((create_info->used_fields & HA_CREATE_USED_AUTO) && (create_info->auto_increment_value != 0)) { /* Note: We can't call update_thd() as prebuilt will not be setup at this stage and so we use thd. */ /* We need to copy the AUTOINC value from the old table if this is an ALTER TABLE. */ if (((create_info->used_fields & HA_CREATE_USED_AUTO) || thd_sql_command(thd) == SQLCOM_ALTER_TABLE) && create_info->auto_increment_value != 0) { /* Query was ALTER TABLE...AUTO_INCREMENT = x; or CREATE TABLE ...AUTO_INCREMENT = x; Find out a table Loading Loading @@ -5856,7 +5875,7 @@ ha_innobase::info( } if (flag & HA_STATUS_AUTO && table->found_next_number_field) { longlong auto_inc; ulonglong auto_inc; int ret; /* The following function call can the first time fail in Loading Loading @@ -7207,9 +7226,9 @@ ha_innobase::innobase_read_and_init_auto_inc( /*=========================================*/ /* out: 0 or generic MySQL error code */ longlong* value) /* out: the autoinc value */ ulonglong* value) /* out: the autoinc value */ { longlong auto_inc; ulonglong auto_inc; ibool stmt_start; int mysql_error = 0; dict_table_t* innodb_table = prebuilt->table; Loading Loading @@ -7260,7 +7279,9 @@ ha_innobase::innobase_read_and_init_auto_inc( index, autoinc_col_name, &auto_inc); if (error == DB_SUCCESS) { if (auto_inc < ~0x0ULL) { ++auto_inc; } dict_table_autoinc_initialize(innodb_table, auto_inc); } else { ut_print_timestamp(stderr); Loading Loading @@ -7313,14 +7334,14 @@ ha_innobase::innobase_get_auto_increment( error = innobase_autoinc_lock(); if (error == DB_SUCCESS) { ib_longlong autoinc; ulonglong autoinc; /* Determine the first value of the interval */ autoinc = dict_table_autoinc_read(prebuilt->table); /* We need to initialize the AUTO-INC value, for that we release all locks.*/ if (autoinc <= 0) { if (autoinc == 0) { trx_t* trx; trx = prebuilt->trx; Loading @@ -7339,14 +7360,11 @@ ha_innobase::innobase_get_auto_increment( mysql_error = innobase_read_and_init_auto_inc( &autoinc); if (!mysql_error) { /* Should have read the proper value */ ut_a(autoinc > 0); } else { if (mysql_error) { error = DB_ERROR; } } else { *value = (ulonglong) autoinc; *value = autoinc; } /* A deadlock error during normal processing is OK and can be ignored. */ Loading Loading @@ -7431,10 +7449,19 @@ ha_innobase::get_auto_increment( /* With old style AUTOINC locking we only update the table's AUTOINC counter after attempting to insert the row. */ if (innobase_autoinc_lock_mode != AUTOINC_OLD_STYLE_LOCKING) { ulonglong have; ulonglong need; /* Check for overflow conditions. */ need = *nb_reserved_values * increment; have = ~0x0ULL - *first_value; if (have < need) { need = have; } /* Compute the last value in the interval */ prebuilt->last_value = *first_value + (*nb_reserved_values * increment); prebuilt->last_value = *first_value + need; ut_a(prebuilt->last_value >= *first_value); Loading
storage/innobase/handler/ha_innodb.h +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ class ha_innobase: public handler int update_thd(THD* thd); int change_active_index(uint keynr); int general_fetch(uchar* buf, uint direction, uint match_mode); int innobase_read_and_init_auto_inc(longlong* ret); int innobase_read_and_init_auto_inc(ulonglong* ret); ulong innobase_autoinc_lock(); ulong innobase_set_max_autoinc(ulonglong auto_inc); ulong innobase_reset_autoinc(ulonglong auto_inc); Loading