Commit 47db86be authored by sunny's avatar sunny

branches/zip: Simplify the autoinc initialization code. This removes the

non-determinism related to reading the table's autoinc value for the first
time. This change has also reduced the sizeof dict_table_t by sizeof(ibool)
bytes because we don't need the dict_table_t::autoinc_inited field anymore.

This also fixes Bug#39830 Table autoinc value not updated on first insert.
rb://16
parent 2abb3f19
...@@ -287,8 +287,7 @@ dict_table_autoinc_lock( ...@@ -287,8 +287,7 @@ dict_table_autoinc_lock(
} }
/************************************************************************ /************************************************************************
Initializes the autoinc counter. It is not an error to initialize an already Unconditionally set the autoinc counter. */
initialized counter. */
UNIV_INTERN UNIV_INTERN
void void
dict_table_autoinc_initialize( dict_table_autoinc_initialize(
...@@ -298,7 +297,6 @@ dict_table_autoinc_initialize( ...@@ -298,7 +297,6 @@ dict_table_autoinc_initialize(
{ {
ut_ad(mutex_own(&table->autoinc_mutex)); ut_ad(mutex_own(&table->autoinc_mutex));
table->autoinc_inited = TRUE;
table->autoinc = value; table->autoinc = value;
} }
...@@ -312,18 +310,9 @@ dict_table_autoinc_read( ...@@ -312,18 +310,9 @@ dict_table_autoinc_read(
/* out: value for a new row, or 0 */ /* out: value for a new row, or 0 */
const dict_table_t* table) /* in: table */ const dict_table_t* table) /* in: table */
{ {
ib_int64_t value;
ut_ad(mutex_own(&table->autoinc_mutex)); ut_ad(mutex_own(&table->autoinc_mutex));
if (!table->autoinc_inited) { return(table->autoinc);
value = 0;
} else {
value = table->autoinc;
}
return(value);
} }
/************************************************************************ /************************************************************************
...@@ -331,14 +320,15 @@ Updates the autoinc counter if the value supplied is greater than the ...@@ -331,14 +320,15 @@ Updates the autoinc counter if the value supplied is greater than the
current value. If not inited, does nothing. */ current value. If not inited, does nothing. */
UNIV_INTERN UNIV_INTERN
void void
dict_table_autoinc_update( dict_table_autoinc_update_if_greater(
/*======================*/ /*=================================*/
dict_table_t* table, /* in/out: table */ dict_table_t* table, /* in/out: table */
ib_uint64_t value) /* in: value which was assigned to a row */ ib_uint64_t value) /* in: value which was assigned to a row */
{ {
if (table->autoinc_inited && value > table->autoinc) { ut_ad(mutex_own(&table->autoinc_mutex));
if (value > table->autoinc) {
table->autoinc = value; table->autoinc = value;
} }
} }
......
This diff is collapsed.
...@@ -73,11 +73,13 @@ class ha_innobase: public handler ...@@ -73,11 +73,13 @@ class ha_innobase: public handler
void update_thd(); void update_thd();
int change_active_index(uint keynr); int change_active_index(uint keynr);
int general_fetch(uchar* buf, uint direction, uint match_mode); int general_fetch(uchar* buf, uint direction, uint match_mode);
int innobase_read_and_init_auto_inc(ulonglong* ret); ulong innobase_lock_autoinc();
ulong innobase_autoinc_lock(); ulonglong innobase_peek_autoinc();
ulong innobase_set_max_autoinc(ulonglong auto_inc); ulong innobase_set_max_autoinc(ulonglong auto_inc);
ulong innobase_reset_autoinc(ulonglong auto_inc); ulong innobase_reset_autoinc(ulonglong auto_inc);
ulong innobase_get_auto_increment(ulonglong* value); ulong innobase_get_autoinc(ulonglong* value);
ulong innobase_update_autoinc(ulonglong auto_inc);
ulong innobase_initialize_autoinc();
dict_index_t* innobase_get_index(uint keynr); dict_index_t* innobase_get_index(uint keynr);
ulonglong innobase_get_int_col_max_value(const Field* field); ulonglong innobase_get_int_col_max_value(const Field* field);
......
...@@ -172,8 +172,7 @@ dict_table_autoinc_lock( ...@@ -172,8 +172,7 @@ dict_table_autoinc_lock(
/*====================*/ /*====================*/
dict_table_t* table); /* in/out: table */ dict_table_t* table); /* in/out: table */
/************************************************************************ /************************************************************************
Initializes the autoinc counter. It is not an error to initialize an already Unconditionally set the autoinc counter. */
initialized counter. */
UNIV_INTERN UNIV_INTERN
void void
dict_table_autoinc_initialize( dict_table_autoinc_initialize(
...@@ -194,8 +193,8 @@ Updates the autoinc counter if the value supplied is equal or bigger than the ...@@ -194,8 +193,8 @@ Updates the autoinc counter if the value supplied is equal or bigger than the
current value. If not inited, does nothing. */ current value. If not inited, does nothing. */
UNIV_INTERN UNIV_INTERN
void void
dict_table_autoinc_update( dict_table_autoinc_update_if_greater(
/*======================*/ /*=================================*/
dict_table_t* table, /* in/out: table */ dict_table_t* table, /* in/out: table */
ib_uint64_t value); /* in: value which was assigned to a row */ ib_uint64_t value); /* in: value which was assigned to a row */
......
...@@ -441,10 +441,6 @@ struct dict_table_struct{ ...@@ -441,10 +441,6 @@ struct dict_table_struct{
mutex_t autoinc_mutex; mutex_t autoinc_mutex;
/* mutex protecting the autoincrement /* mutex protecting the autoincrement
counter */ counter */
ibool autoinc_inited;
/* TRUE if the autoinc counter has been
inited; MySQL gets the init value by executing
SELECT MAX(auto inc column) */
ib_uint64_t autoinc;/* autoinc counter value to give to the ib_uint64_t autoinc;/* autoinc counter value to give to the
next inserted row */ next inserted row */
/*----------------------*/ /*----------------------*/
......
...@@ -2915,7 +2915,7 @@ next_rec: ...@@ -2915,7 +2915,7 @@ next_rec:
/* MySQL calls ha_innobase::reset_auto_increment() which does /* MySQL calls ha_innobase::reset_auto_increment() which does
the same thing. */ the same thing. */
dict_table_autoinc_lock(table); dict_table_autoinc_lock(table);
dict_table_autoinc_initialize(table, 0); dict_table_autoinc_initialize(table, 1);
dict_table_autoinc_unlock(table); dict_table_autoinc_unlock(table);
dict_update_statistics(table); dict_update_statistics(table);
......
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