diff options
author | unknown <heikki@donna.mysql.fi> | 2001-07-16 21:10:29 +0300 |
---|---|---|
committer | unknown <heikki@donna.mysql.fi> | 2001-07-16 21:10:29 +0300 |
commit | 6be4a56aad66f5101ca0cc094ae3a7c312456058 (patch) | |
tree | cb67587ae0313272710122ef1de5d31c2ca2d274 /sql | |
parent | 2e96c05506ee6cf74f4d027816c8b4c81caff05b (diff) | |
download | mariadb-git-6be4a56aad66f5101ca0cc094ae3a7c312456058.tar.gz |
ha_innobase.cc Fix a bug in showing of Auto_increment in SHOW TABLE STATUS
ha_innobase.h Fix a bug in showing of Auto_increment in SHOW TABLE STATUS
sql/ha_innobase.h:
Fix a bug in showing of Auto_increment in SHOW TABLE STATUS
sql/ha_innobase.cc:
Fix a bug in showing of Auto_increment in SHOW TABLE STATUS
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_innobase.cc | 45 | ||||
-rw-r--r-- | sql/ha_innobase.h | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/sql/ha_innobase.cc b/sql/ha_innobase.cc index 184c97837db..bab5dc582e7 100644 --- a/sql/ha_innobase.cc +++ b/sql/ha_innobase.cc @@ -2885,4 +2885,49 @@ ha_innobase::store_lock( return(to); } +/*********************************************************************** +Returns the next auto-increment column value for the table. write_row +normally fetches the value from the cache in the data dictionary. This +function in used by SHOW TABLE STATUS and when the first insert to the table +is done after database startup. */ + +longlong +ha_innobase::get_auto_increment() +/*=============================*/ + /* out: the next auto-increment column value */ +{ + row_prebuilt_t* prebuilt = (row_prebuilt_t*) innobase_prebuilt; + longlong nr; + int error; + + (void) extra(HA_EXTRA_KEYREAD); + index_init(table->next_number_index); + + /* We use an exclusive lock when we read the max key value from the + auto-increment column index. This is because then build_template will + advise InnoDB to fetch all columns. In SHOW TABLE STATUS the query + id of the auto-increment column is not changed, and previously InnoDB + did not fetch it, causing SHOW TABLE STATUS to show wrong values + for the autoinc column. */ + + prebuilt->select_lock_type = LOCK_X; + prebuilt->trx->mysql_n_tables_locked += 1; + + error=index_last(table->record[1]); + + if (error) { + nr = 1; + } else { + nr = (longlong) table->next_number_field-> + val_int_offset(table->rec_buff_length) + 1; + } + + (void) extra(HA_EXTRA_NO_KEYREAD); + + index_end(); + + return(nr); +} + + #endif /* HAVE_INNOBASE_DB */ diff --git a/sql/ha_innobase.h b/sql/ha_innobase.h index d832ac93d0f..4dbff654337 100644 --- a/sql/ha_innobase.h +++ b/sql/ha_innobase.h @@ -147,6 +147,7 @@ class ha_innobase: public handler THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); + longlong get_auto_increment(); }; extern bool innodb_skip; |