#At file:///home/marty/MySQL/mysql-5.1-telco-6.2/
3016 Martin Skold 2009-10-07
Bug#47865 SHOW CREATE TABLE does not show the current auto_increment number for ndb tables: reading auto_increment value in ha_ndbcluster::update_create_info
modified:
sql/ha_ndbcluster.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2009-10-07 15:53:06 +0000
+++ b/sql/ha_ndbcluster.cc 2009-10-07 21:28:08 +0000
@@ -5412,7 +5412,48 @@ static int create_ndb_column(THD *thd,
void ha_ndbcluster::update_create_info(HA_CREATE_INFO *create_info)
{
DBUG_ENTER("update_create_info");
+ THD *thd= current_thd;
TABLE_SHARE *share= table->s;
+ const NDBTAB *ndbtab= m_table;
+ Ndb *ndb= check_ndb_in_thd(thd);
+
+ /*
+ Find any initial auto_increment value
+ */
+ for (uint i= 0; i < table->s->fields; i++)
+ {
+ Field *field= table->field[i];
+ if (field->flags & AUTO_INCREMENT_FLAG)
+ {
+ ulonglong auto_value;
+ uint retries= NDB_AUTO_INCREMENT_RETRIES;
+ int retry_sleep= 30; /* 30 milliseconds, transaction */
+ for (;;)
+ {
+ Ndb_tuple_id_range_guard g(m_share);
+ if (ndb->readAutoIncrementValue(m_table, g.range, auto_value))
+ {
+ if (--retries && !thd->killed &&
+ ndb->getNdbError().status == NdbError::TemporaryError)
+ {
+ do_retry_sleep(retry_sleep);
+ continue;
+ }
+ const NdbError err= ndb->getNdbError();
+ sql_print_error("Error %lu in ::update_create_info(): %s",
+ (ulong) err.code, err.message);
+ DBUG_VOID_RETURN;
+ }
+ break;
+ }
+ if (auto_value > 1)
+ {
+ create_info->auto_increment_value= auto_value;
+ break;
+ }
+ }
+ }
+
if (share->mysql_version < MYSQL_VERSION_TABLESPACE_IN_FRM)
{
DBUG_PRINT("info", ("Restored an old table %s, pre-frm_version 7",
@@ -5420,13 +5461,10 @@ void ha_ndbcluster::update_create_info(H
if (!create_info->tablespace && !share->tablespace)
{
DBUG_PRINT("info", ("Checking for tablespace in ndb"));
- THD *thd= current_thd;
- Ndb *ndb= check_ndb_in_thd(thd);
NDBDICT *ndbdict= ndb->getDictionary();
NdbError ndberr;
Uint32 id;
ndb->setDatabaseName(m_dbname);
- const NDBTAB *ndbtab= m_table;
DBUG_ASSERT(ndbtab != NULL);
if (!ndbtab->getTablespace(&id))
{