Loading mysql-test/r/ndb_alter_table.result +22 −1 Original line number Diff line number Diff line DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; CREATE TABLE t1 ( a INT NOT NULL, Loading Loading @@ -328,3 +328,24 @@ select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; no_copy no_copy DROP TABLE t1, ndb_show_tables; create table t1 (a int primary key auto_increment, b int) engine=ndb; insert into t1 (b) values (101),(102),(103); select * from t1 where a = 3; a b 3 103 alter table t1 rename t2; insert into t2 (b) values (201),(202),(203); select * from t2 where a = 6; a b 6 203 alter table t2 add c int; insert into t2 (b) values (301),(302),(303); select * from t2 where a = 9; a b c 9 303 NULL alter table t2 rename t1; insert into t1 (b) values (401),(402),(403); select * from t1 where a = 12; a b c 12 403 NULL drop table t1; mysql-test/r/ndb_basic.result +24 −24 Original line number Diff line number Diff line Loading @@ -642,30 +642,30 @@ counter datavalue 6 newval 7 newval 8 newval 35 newval 36 newval 37 newval 38 newval 39 newval 40 newval 41 newval 42 newval 43 newval 44 newval 45 newval 46 newval 47 newval 48 newval 49 newval 50 newval 51 newval 52 newval 53 newval 54 newval 55 newval 56 newval 57 newval 58 newval 9 newval 10 newval 11 newval 12 newval 13 newval 14 newval 15 newval 16 newval 17 newval 18 newval 19 newval 20 newval 21 newval 22 newval 23 newval 24 newval 25 newval 26 newval 27 newval 28 newval 29 newval 30 newval 31 newval 32 newval drop table t1; CREATE TABLE t1 ( b INT ) PACK_KEYS = 0 ENGINE = ndb; select * from t1; Loading mysql-test/t/ndb_alter_table.test +16 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ -- source include/not_embedded.inc --disable_warnings DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; --enable_warnings Loading Loading @@ -383,3 +383,18 @@ LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; DROP TABLE t1, ndb_show_tables; # simple test that auto incr is not lost at rename or alter create table t1 (a int primary key auto_increment, b int) engine=ndb; insert into t1 (b) values (101),(102),(103); select * from t1 where a = 3; alter table t1 rename t2; insert into t2 (b) values (201),(202),(203); select * from t2 where a = 6; alter table t2 add c int; insert into t2 (b) values (301),(302),(303); select * from t2 where a = 9; alter table t2 rename t1; insert into t1 (b) values (401),(402),(403); select * from t1 where a = 12; drop table t1; sql/ha_ndbcluster.cc +29 −19 Original line number Diff line number Diff line Loading @@ -106,7 +106,6 @@ static uint ndbcluster_alter_table_flags(uint flags) } #define NDB_FAILED_AUTO_INCREMENT ~(Uint64)0 #define NDB_AUTO_INCREMENT_RETRIES 10 #define ERR_PRINT(err) \ Loading Loading @@ -2465,14 +2464,16 @@ int ha_ndbcluster::write_row(byte *record) { // Table has hidden primary key Ndb *ndb= get_ndb(); Uint64 auto_value= NDB_FAILED_AUTO_INCREMENT; int ret; Uint64 auto_value; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { auto_value= ndb->getAutoIncrementValue(m_table); } while (auto_value == NDB_FAILED_AUTO_INCREMENT && Ndb_tuple_id_range_guard g(m_share); ret= ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1); } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1) ERR_RETURN(ndb->getNdbError()); if (set_hidden_key(op, table_share->fields, (const byte*)&auto_value)) ERR_RETURN(op->getNdbError()); Loading Loading @@ -2567,11 +2568,12 @@ int ha_ndbcluster::write_row(byte *record) Ndb *ndb= get_ndb(); Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1; DBUG_PRINT("info", ("Trying to set next auto increment value to %lu", (ulong) next_val)); if (ndb->setAutoIncrementValue(m_table, next_val, TRUE)) DBUG_PRINT("info", ("Setting next auto increment value to %u", next_val)); ("Trying to set next auto increment value to %llu", (ulonglong) next_val)); Ndb_tuple_id_range_guard g(m_share); if (ndb->setAutoIncrementValue(m_table, g.range, next_val, TRUE) == -1) ERR_RETURN(ndb->getNdbError()); } m_skip_auto_increment= TRUE; Loading Loading @@ -3542,9 +3544,16 @@ void ha_ndbcluster::info(uint flag) if (m_table) { Ndb *ndb= get_ndb(); Ndb_tuple_id_range_guard g(m_share); auto_increment_value= ndb->readAutoIncrementValue(m_table); if (ndb->readAutoIncrementValue(m_table, g.range, auto_increment_value) == -1) { const NdbError err= ndb->getNdbError(); sql_print_error("Error %lu in readAutoIncrementValue(): %s", (ulong) err.code, err.message); auto_increment_value= ~(Uint64)0; } } } DBUG_VOID_RETURN; Loading Loading @@ -5236,17 +5245,18 @@ ulonglong ha_ndbcluster::get_auto_increment() m_rows_to_insert - m_rows_inserted : ((m_rows_to_insert > m_autoincrement_prefetch) ? m_rows_to_insert : m_autoincrement_prefetch)); auto_value= NDB_FAILED_AUTO_INCREMENT; int ret; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { auto_value= (m_skip_auto_increment) ? ndb->readAutoIncrementValue(m_table) : ndb->getAutoIncrementValue(m_table, cache_size); } while (auto_value == NDB_FAILED_AUTO_INCREMENT && Ndb_tuple_id_range_guard g(m_share); ret= m_skip_auto_increment ? ndb->readAutoIncrementValue(m_table, g.range, auto_value) : ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size); } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1) { const NdbError err= ndb->getNdbError(); sql_print_error("Error %lu in ::get_auto_increment(): %s", Loading sql/ha_ndbcluster.h +14 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ typedef struct st_ndbcluster_share { ulonglong commit_count; char *db; char *table_name; Ndb::TupleIdRange tuple_id_range; #ifdef HAVE_NDB_BINLOG uint32 flags; NdbEventOperation *op; Loading Loading @@ -139,6 +140,19 @@ set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state) pthread_mutex_unlock(&share->mutex); } struct Ndb_tuple_id_range_guard { Ndb_tuple_id_range_guard(NDB_SHARE* _share) : share(_share), range(share->tuple_id_range) { pthread_mutex_lock(&share->mutex); } ~Ndb_tuple_id_range_guard() { pthread_mutex_unlock(&share->mutex); } NDB_SHARE* share; Ndb::TupleIdRange& range; }; #ifdef HAVE_NDB_BINLOG /* NDB_SHARE.flags */ #define NSF_HIDDEN_PK 1 /* table has hidden primary key */ Loading Loading @@ -726,7 +740,6 @@ static void set_tabname(const char *pathname, char *tabname); int drop_indexes(Ndb *ndb, TABLE *tab); int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict, KEY *key_info, const char *index_name, uint index_no); int initialize_autoincrement(const void *table); int get_metadata(const char* path); void release_metadata(THD *thd, Ndb *ndb); NDB_INDEX_TYPE get_index_type(uint idx_no) const; Loading Loading
mysql-test/r/ndb_alter_table.result +22 −1 Original line number Diff line number Diff line DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; CREATE TABLE t1 ( a INT NOT NULL, Loading Loading @@ -328,3 +328,24 @@ select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; no_copy no_copy DROP TABLE t1, ndb_show_tables; create table t1 (a int primary key auto_increment, b int) engine=ndb; insert into t1 (b) values (101),(102),(103); select * from t1 where a = 3; a b 3 103 alter table t1 rename t2; insert into t2 (b) values (201),(202),(203); select * from t2 where a = 6; a b 6 203 alter table t2 add c int; insert into t2 (b) values (301),(302),(303); select * from t2 where a = 9; a b c 9 303 NULL alter table t2 rename t1; insert into t1 (b) values (401),(402),(403); select * from t1 where a = 12; a b c 12 403 NULL drop table t1;
mysql-test/r/ndb_basic.result +24 −24 Original line number Diff line number Diff line Loading @@ -642,30 +642,30 @@ counter datavalue 6 newval 7 newval 8 newval 35 newval 36 newval 37 newval 38 newval 39 newval 40 newval 41 newval 42 newval 43 newval 44 newval 45 newval 46 newval 47 newval 48 newval 49 newval 50 newval 51 newval 52 newval 53 newval 54 newval 55 newval 56 newval 57 newval 58 newval 9 newval 10 newval 11 newval 12 newval 13 newval 14 newval 15 newval 16 newval 17 newval 18 newval 19 newval 20 newval 21 newval 22 newval 23 newval 24 newval 25 newval 26 newval 27 newval 28 newval 29 newval 30 newval 31 newval 32 newval drop table t1; CREATE TABLE t1 ( b INT ) PACK_KEYS = 0 ENGINE = ndb; select * from t1; Loading
mysql-test/t/ndb_alter_table.test +16 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ -- source include/not_embedded.inc --disable_warnings DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2; drop database if exists mysqltest; --enable_warnings Loading Loading @@ -383,3 +383,18 @@ LOAD DATA INFILE 'tmp.dat' INTO TABLE ndb_show_tables; select 'no_copy' from ndb_show_tables where id = @t1_id and name like '%t1%'; DROP TABLE t1, ndb_show_tables; # simple test that auto incr is not lost at rename or alter create table t1 (a int primary key auto_increment, b int) engine=ndb; insert into t1 (b) values (101),(102),(103); select * from t1 where a = 3; alter table t1 rename t2; insert into t2 (b) values (201),(202),(203); select * from t2 where a = 6; alter table t2 add c int; insert into t2 (b) values (301),(302),(303); select * from t2 where a = 9; alter table t2 rename t1; insert into t1 (b) values (401),(402),(403); select * from t1 where a = 12; drop table t1;
sql/ha_ndbcluster.cc +29 −19 Original line number Diff line number Diff line Loading @@ -106,7 +106,6 @@ static uint ndbcluster_alter_table_flags(uint flags) } #define NDB_FAILED_AUTO_INCREMENT ~(Uint64)0 #define NDB_AUTO_INCREMENT_RETRIES 10 #define ERR_PRINT(err) \ Loading Loading @@ -2465,14 +2464,16 @@ int ha_ndbcluster::write_row(byte *record) { // Table has hidden primary key Ndb *ndb= get_ndb(); Uint64 auto_value= NDB_FAILED_AUTO_INCREMENT; int ret; Uint64 auto_value; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { auto_value= ndb->getAutoIncrementValue(m_table); } while (auto_value == NDB_FAILED_AUTO_INCREMENT && Ndb_tuple_id_range_guard g(m_share); ret= ndb->getAutoIncrementValue(m_table, g.range, auto_value, 1); } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1) ERR_RETURN(ndb->getNdbError()); if (set_hidden_key(op, table_share->fields, (const byte*)&auto_value)) ERR_RETURN(op->getNdbError()); Loading Loading @@ -2567,11 +2568,12 @@ int ha_ndbcluster::write_row(byte *record) Ndb *ndb= get_ndb(); Uint64 next_val= (Uint64) table->next_number_field->val_int() + 1; DBUG_PRINT("info", ("Trying to set next auto increment value to %lu", (ulong) next_val)); if (ndb->setAutoIncrementValue(m_table, next_val, TRUE)) DBUG_PRINT("info", ("Setting next auto increment value to %u", next_val)); ("Trying to set next auto increment value to %llu", (ulonglong) next_val)); Ndb_tuple_id_range_guard g(m_share); if (ndb->setAutoIncrementValue(m_table, g.range, next_val, TRUE) == -1) ERR_RETURN(ndb->getNdbError()); } m_skip_auto_increment= TRUE; Loading Loading @@ -3542,9 +3544,16 @@ void ha_ndbcluster::info(uint flag) if (m_table) { Ndb *ndb= get_ndb(); Ndb_tuple_id_range_guard g(m_share); auto_increment_value= ndb->readAutoIncrementValue(m_table); if (ndb->readAutoIncrementValue(m_table, g.range, auto_increment_value) == -1) { const NdbError err= ndb->getNdbError(); sql_print_error("Error %lu in readAutoIncrementValue(): %s", (ulong) err.code, err.message); auto_increment_value= ~(Uint64)0; } } } DBUG_VOID_RETURN; Loading Loading @@ -5236,17 +5245,18 @@ ulonglong ha_ndbcluster::get_auto_increment() m_rows_to_insert - m_rows_inserted : ((m_rows_to_insert > m_autoincrement_prefetch) ? m_rows_to_insert : m_autoincrement_prefetch)); auto_value= NDB_FAILED_AUTO_INCREMENT; int ret; uint retries= NDB_AUTO_INCREMENT_RETRIES; do { auto_value= (m_skip_auto_increment) ? ndb->readAutoIncrementValue(m_table) : ndb->getAutoIncrementValue(m_table, cache_size); } while (auto_value == NDB_FAILED_AUTO_INCREMENT && Ndb_tuple_id_range_guard g(m_share); ret= m_skip_auto_increment ? ndb->readAutoIncrementValue(m_table, g.range, auto_value) : ndb->getAutoIncrementValue(m_table, g.range, auto_value, cache_size); } while (ret == -1 && --retries && ndb->getNdbError().status == NdbError::TemporaryError); if (auto_value == NDB_FAILED_AUTO_INCREMENT) if (ret == -1) { const NdbError err= ndb->getNdbError(); sql_print_error("Error %lu in ::get_auto_increment(): %s", Loading
sql/ha_ndbcluster.h +14 −1 Original line number Diff line number Diff line Loading @@ -106,6 +106,7 @@ typedef struct st_ndbcluster_share { ulonglong commit_count; char *db; char *table_name; Ndb::TupleIdRange tuple_id_range; #ifdef HAVE_NDB_BINLOG uint32 flags; NdbEventOperation *op; Loading Loading @@ -139,6 +140,19 @@ set_ndb_share_state(NDB_SHARE *share, NDB_SHARE_STATE state) pthread_mutex_unlock(&share->mutex); } struct Ndb_tuple_id_range_guard { Ndb_tuple_id_range_guard(NDB_SHARE* _share) : share(_share), range(share->tuple_id_range) { pthread_mutex_lock(&share->mutex); } ~Ndb_tuple_id_range_guard() { pthread_mutex_unlock(&share->mutex); } NDB_SHARE* share; Ndb::TupleIdRange& range; }; #ifdef HAVE_NDB_BINLOG /* NDB_SHARE.flags */ #define NSF_HIDDEN_PK 1 /* table has hidden primary key */ Loading Loading @@ -726,7 +740,6 @@ static void set_tabname(const char *pathname, char *tabname); int drop_indexes(Ndb *ndb, TABLE *tab); int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict, KEY *key_info, const char *index_name, uint index_no); int initialize_autoincrement(const void *table); int get_metadata(const char* path); void release_metadata(THD *thd, Ndb *ndb); NDB_INDEX_TYPE get_index_type(uint idx_no) const; Loading