From 65d4dc98665202b64e805f6b15d68ac697e65813 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 28 Sep 2004 09:53:14 +0200 Subject: [PATCH] Adjusted so auto_increment value after bulk insert will be exactly +1 after last (if no parallel inserts) --- mysql-test/r/ndb_alter_table.result | 52 ++++++++++++++++++++++++++--- mysql-test/t/ndb_alter_table.test | 32 ++++++++++++++++-- sql/ha_ndbcluster.cc | 4 ++- 3 files changed, 80 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/ndb_alter_table.result b/mysql-test/r/ndb_alter_table.result index 897fa77185d..2ee1bf4497b 100644 --- a/mysql-test/r/ndb_alter_table.result +++ b/mysql-test/r/ndb_alter_table.result @@ -94,16 +94,60 @@ b INT NOT NULL ) ENGINE=ndbcluster; INSERT INTO t1 VALUES (9410,9412); ALTER TABLE t1 ADD COLUMN c int not null; -select * from t1; +select * from t1 order by a; a b c 9410 9412 0 -select * from t1; +select * from t1 order by a; a b c 9410 9412 0 alter table t1 drop c; -select * from t1; +select * from t1 order by a; a b 9410 9412 drop table t1; -select * from t1; +select * from t1 order by a; ERROR 42S02: Table 'test.t1' doesn't exist +CREATE TABLE t1 ( +a INT NOT NULL PRIMARY KEY, +b INT NOT NULL +) ENGINE=ndbcluster; +INSERT INTO t1 VALUES (0,1),(17,18); +select * from t1 order by a; +a b +0 1 +17 18 +alter table t1 modify column a int not null auto_increment; +select * from t1 order by a; +a b +0 1 +17 18 +INSERT INTO t1 VALUES (0,19),(20,21); +select * from t1 order by a; +a b +0 1 +17 18 +18 19 +20 21 +drop table t1; +CREATE TABLE t1 ( +a INT NOT NULL PRIMARY KEY, +b INT NOT NULL +) ENGINE=ndbcluster; +INSERT INTO t1 VALUES (0,1),(17,18); +select * from t1; +a b +17 18 +0 1 +alter table t1 add c int not null unique auto_increment; +select * from t1 order by a; +a b c +0 1 2 +17 18 1 +INSERT INTO t1 VALUES (18,19,3),(20,21,0); +select * from t1 order by a; +a b c +0 1 2 +17 18 1 +18 19 3 +20 21 4 +drop table t1; diff --git a/mysql-test/t/ndb_alter_table.test b/mysql-test/t/ndb_alter_table.test index 9128d0c3811..aa3da77a1da 100644 --- a/mysql-test/t/ndb_alter_table.test +++ b/mysql-test/t/ndb_alter_table.test @@ -74,19 +74,45 @@ connect (con2,localhost,,,test); connection con1; ALTER TABLE t1 ADD COLUMN c int not null; -select * from t1; +select * from t1 order by a; connection con2; -select * from t1; +select * from t1 order by a; alter table t1 drop c; connection con1; -select * from t1; +select * from t1 order by a; drop table t1; connection con2; --error 1146 +select * from t1 order by a; + +CREATE TABLE t1 ( + a INT NOT NULL PRIMARY KEY, + b INT NOT NULL +) ENGINE=ndbcluster; + +INSERT INTO t1 VALUES (0,1),(17,18); +select * from t1 order by a; +alter table t1 modify column a int not null auto_increment; +select * from t1 order by a; +INSERT INTO t1 VALUES (0,19),(20,21); +select * from t1 order by a; +drop table t1; + +CREATE TABLE t1 ( + a INT NOT NULL PRIMARY KEY, + b INT NOT NULL +) ENGINE=ndbcluster; + +INSERT INTO t1 VALUES (0,1),(17,18); select * from t1; +alter table t1 add c int not null unique auto_increment; +select * from t1 order by a; +INSERT INTO t1 VALUES (18,19,3),(20,21,0); +select * from t1 order by a; +drop table t1; #--disable_warnings #DROP TABLE IF EXISTS t2; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 2c330fae84d..356c26f3e20 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -3402,7 +3402,9 @@ longlong ha_ndbcluster::get_auto_increment() DBUG_ENTER("get_auto_increment"); DBUG_PRINT("enter", ("m_tabname: %s", m_tabname)); int cache_size= - (rows_to_insert > autoincrement_prefetch) ? + (rows_to_insert - rows_inserted < autoincrement_prefetch) ? + rows_to_insert - rows_inserted + : (rows_to_insert > autoincrement_prefetch) ? rows_to_insert : autoincrement_prefetch; Uint64 auto_value=