Commit 8046747c authored by unknown's avatar unknown

Merge mskold@bk-internal.mysql.com:/home/bk/mysql-5.0-ndb

into  mysql.com:/windows/Linux_space/MySQL/mysql-5.0-ndb


sql/handler.cc:
  Auto merged
sql/ha_ndbcluster.cc:
  Merge
parents b1a5f427 10e329ff
...@@ -657,3 +657,172 @@ a b ...@@ -657,3 +657,172 @@ a b
2 NULL 2 NULL
3 NULL 3 NULL
drop table t1; drop table t1;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
1 1 0
11 2 1
21 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
TRUNCATE t1;
TRUNCATE t2;
SET @@session.auto_increment_offset=5;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t1 (pk,b,c) VALUES (27,4,3),(NULL,5,4),(99,6,5),(NULL,7,6);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (pk,b,c) VALUES (27,4,3),(NULL,5,4),(99,6,5),(NULL,7,6);
SELECT * FROM t1 ORDER BY pk;
pk b c
5 1 0
15 2 1
25 3 2
27 4 3
35 5 4
99 6 5
105 7 6
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
7
TRUNCATE t1;
TRUNCATE t2;
SET @@session.auto_increment_increment=2;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
1 1 0
3 2 1
5 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 7;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 7;
SET @@session.auto_increment_offset=1;
SET @@session.auto_increment_increment=1;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
7 1 0
8 2 1
9 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 3;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 3;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
5 1 0
15 2 1
25 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 7;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 7;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
15 1 0
25 2 1
35 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 5;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 5;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
5 1 0
15 2 1
25 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 100;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 100;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
pk b c
105 1 0
115 2 1
125 3 2
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
COUNT(t1.pk)
3
DROP TABLE t1, t2;
...@@ -639,4 +639,141 @@ insert ignore into t1 values (1,0), (2,0), (2,null), (3,null); ...@@ -639,4 +639,141 @@ insert ignore into t1 values (1,0), (2,0), (2,null), (3,null);
select * from t1 order by a; select * from t1 order by a;
drop table t1; drop table t1;
# Bug#26342 auto_increment_increment AND auto_increment_offset REALLY REALLY anger NDB cluster
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
TRUNCATE t1;
TRUNCATE t2;
SET @@session.auto_increment_offset=5;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t1 (pk,b,c) VALUES (27,4,3),(NULL,5,4),(99,6,5),(NULL,7,6);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (pk,b,c) VALUES (27,4,3),(NULL,5,4),(99,6,5),(NULL,7,6);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
TRUNCATE t1;
TRUNCATE t2;
SET @@session.auto_increment_increment=2;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 7;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 7;
SET @@session.auto_increment_offset=1;
SET @@session.auto_increment_increment=1;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 3;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 3;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 7;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 7;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 5;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 5;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
CREATE TABLE t1 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=NDBCLUSTER AUTO_INCREMENT = 100;
CREATE TABLE t2 (
pk INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
b INT NOT NULL,
c INT NOT NULL UNIQUE
) ENGINE=MYISAM AUTO_INCREMENT = 100;
SET @@session.auto_increment_offset=5;
SET @@session.auto_increment_increment=10;
INSERT INTO t1 (b,c) VALUES (1,0),(2,1),(3,2);
INSERT INTO t2 (b,c) VALUES (1,0),(2,1),(3,2);
SELECT * FROM t1 ORDER BY pk;
SELECT COUNT(t1.pk) FROM t1, t2 WHERE t1.pk = t2.pk AND t1.b = t2.b AND t1.c = t1.c;
DROP TABLE t1, t2;
# End of 4.1 tests # End of 4.1 tests
...@@ -1388,9 +1388,11 @@ public: ...@@ -1388,9 +1388,11 @@ public:
* @return 0 or -1 on error, and tupleId in out parameter * @return 0 or -1 on error, and tupleId in out parameter
*/ */
int getAutoIncrementValue(const char* aTableName, int getAutoIncrementValue(const char* aTableName,
Uint64 & tupleId, Uint32 cacheSize); Uint64 & tupleId, Uint32 cacheSize,
Uint64 step = 1, Uint64 start = 1);
int getAutoIncrementValue(const NdbDictionary::Table * aTable, int getAutoIncrementValue(const NdbDictionary::Table * aTable,
Uint64 & tupleId, Uint32 cacheSize); Uint64 & tupleId, Uint32 cacheSize,
Uint64 step = 1, Uint64 start = 1);
int readAutoIncrementValue(const char* aTableName, int readAutoIncrementValue(const char* aTableName,
Uint64 & tupleId); Uint64 & tupleId);
int readAutoIncrementValue(const NdbDictionary::Table * aTable, int readAutoIncrementValue(const NdbDictionary::Table * aTable,
...@@ -1401,7 +1403,8 @@ public: ...@@ -1401,7 +1403,8 @@ public:
Uint64 tupleId, bool increase); Uint64 tupleId, bool increase);
private: private:
int getTupleIdFromNdb(Ndb_local_table_info* info, int getTupleIdFromNdb(Ndb_local_table_info* info,
Uint64 & tupleId, Uint32 cacheSize); Uint64 & tupleId, Uint32 cacheSize,
Uint64 step = 1, Uint64 start = 1 );
int readTupleIdFromNdb(Ndb_local_table_info* info, int readTupleIdFromNdb(Ndb_local_table_info* info,
Uint64 & tupleId); Uint64 & tupleId);
int setTupleIdInNdb(Ndb_local_table_info* info, int setTupleIdInNdb(Ndb_local_table_info* info,
......
...@@ -767,17 +767,27 @@ Ndb::getNodeId() ...@@ -767,17 +767,27 @@ Ndb::getNodeId()
} }
/**************************************************************************** /****************************************************************************
Uint64 getTupleIdFromNdb( Uint32 aTableId, Uint32 cacheSize ); Uint64 getAutoIncrementValue( const char* aTableName,
Uint64 & tupleId,
Parameters: aTableId : The TableId. Uint32 cacheSize,
cacheSize: Prefetch this many values Uint64 step,
Remark: Returns a new TupleId to the application. Uint64 start);
The TupleId comes from SYSTAB_0 where SYSKEY_0 = TableId.
It is initialized to (TableId << 48) + 1 in NdbcntrMain.cpp. Parameters: aTableName (IN) : The table name.
autoValue (OUT) : Returns new autoincrement value
cacheSize (IN) : Prefetch this many values
step (IN) : Specifies the step between the
autoincrement values.
start (IN) : Start value for first value
Remark: Returns a new autoincrement value to the application.
The autoincrement values can be increased by steps
(default 1) and a number of values can be prefetched
by specifying cacheSize (default 10).
****************************************************************************/ ****************************************************************************/
int int
Ndb::getAutoIncrementValue(const char* aTableName, Ndb::getAutoIncrementValue(const char* aTableName,
Uint64 & tupleId, Uint32 cacheSize) Uint64 & autoValue, Uint32 cacheSize,
Uint64 step, Uint64 start)
{ {
DBUG_ENTER("Ndb::getAutoIncrementValue"); DBUG_ENTER("Ndb::getAutoIncrementValue");
BaseString internal_tabname(internalize_table_name(aTableName)); BaseString internal_tabname(internalize_table_name(aTableName));
...@@ -788,15 +798,17 @@ Ndb::getAutoIncrementValue(const char* aTableName, ...@@ -788,15 +798,17 @@ Ndb::getAutoIncrementValue(const char* aTableName,
theError.code = theDictionary->getNdbError().code; theError.code = theDictionary->getNdbError().code;
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (getTupleIdFromNdb(info, tupleId, cacheSize) == -1) DBUG_PRINT("info", ("step %lu", (ulong) step));
if (getTupleIdFromNdb(info, autoValue, cacheSize, step, start) == -1)
DBUG_RETURN(-1); DBUG_RETURN(-1);
DBUG_PRINT("info", ("value %lu", (ulong) tupleId)); DBUG_PRINT("info", ("value %lu", (ulong) autoValue));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
int int
Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable,
Uint64 & tupleId, Uint32 cacheSize) Uint64 & autoValue, Uint32 cacheSize,
Uint64 step, Uint64 start)
{ {
DBUG_ENTER("Ndb::getAutoIncrementValue"); DBUG_ENTER("Ndb::getAutoIncrementValue");
assert(aTable != 0); assert(aTable != 0);
...@@ -809,36 +821,73 @@ Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable, ...@@ -809,36 +821,73 @@ Ndb::getAutoIncrementValue(const NdbDictionary::Table * aTable,
theError.code = theDictionary->getNdbError().code; theError.code = theDictionary->getNdbError().code;
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
if (getTupleIdFromNdb(info, tupleId, cacheSize) == -1) DBUG_PRINT("info", ("step %lu", (ulong) step));
if (getTupleIdFromNdb(info, autoValue, cacheSize, step, start) == -1)
DBUG_RETURN(-1); DBUG_RETURN(-1);
DBUG_PRINT("info", ("value %lu", (ulong)tupleId)); DBUG_PRINT("info", ("value %lu", (ulong) autoValue));
DBUG_RETURN(0); DBUG_RETURN(0);
} }
int int
Ndb::getTupleIdFromNdb(Ndb_local_table_info* info, Ndb::getTupleIdFromNdb(Ndb_local_table_info* info,
Uint64 & tupleId, Uint32 cacheSize) Uint64 & tupleId, Uint32 cacheSize,
Uint64 step, Uint64 start)
{ {
/*
Returns a new TupleId to the application.
The TupleId comes from SYSTAB_0 where SYSKEY_0 = TableId.
It is initialized to (TableId << 48) + 1 in NdbcntrMain.cpp.
In most cases step= start= 1, in which case we get:
1,2,3,4,5,...
If step=10 and start=5 and first number is 1, we get:
5,15,25,35,...
*/
DBUG_ENTER("Ndb::getTupleIdFromNdb"); DBUG_ENTER("Ndb::getTupleIdFromNdb");
if (info->m_first_tuple_id != info->m_last_tuple_id) DBUG_PRINT("info", ("Step %lu (%lu,%lu)", (ulong) step, (ulong) info->m_first_tuple_id, (ulong) info->m_last_tuple_id));
/*
Check if the next value can be taken from the pre-fetched
sequence.
*/
if (info->m_first_tuple_id != info->m_last_tuple_id &&
info->m_first_tuple_id + step <= info->m_last_tuple_id)
{ {
assert(info->m_first_tuple_id < info->m_last_tuple_id); assert(info->m_first_tuple_id < info->m_last_tuple_id);
tupleId = ++info->m_first_tuple_id; info->m_first_tuple_id += step;
DBUG_PRINT("info", ("next cached value %lu", (ulong)tupleId)); tupleId = info->m_first_tuple_id;
DBUG_PRINT("info", ("Next cached value %lu", (ulong) tupleId));
} }
else else
{ {
/*
If start value is greater than step it is ignored
*/
Uint64 offset = (start > step) ? 1 : start;
/*
Pre-fetch a number of values depending on cacheSize
*/
if (cacheSize == 0) if (cacheSize == 0)
cacheSize = 1; cacheSize = 1;
DBUG_PRINT("info", ("reading %u values from database", (uint)cacheSize));
DBUG_PRINT("info", ("Reading %u values from database", (uint)cacheSize));
/* /*
* reserve next cacheSize entries in db. adds cacheSize to NEXTID * reserve next cacheSize entries in db. adds cacheSize to NEXTID
* and returns first tupleId in the new range. * and returns first tupleId in the new range. If tupleId's are
* incremented in steps then multiply the cacheSize with step size.
*/ */
Uint64 opValue = cacheSize; Uint64 opValue = cacheSize * step;
if (opTupleIdOnNdb(info, opValue, 0) == -1) if (opTupleIdOnNdb(info, opValue, 0) == -1)
DBUG_RETURN(-1); DBUG_RETURN(-1);
tupleId = opValue; DBUG_PRINT("info", ("Next value fetched from database %lu", (ulong) opValue));
DBUG_PRINT("info", ("Increasing %lu by offset %lu, increment is %lu", (ulong) (ulong) opValue, (ulong) offset, (ulong) step));
Uint64 current, next;
next = ((Uint64) (opValue + step - offset)) / step;
next = next * step + offset;
current = (next < step) ? next : next - step;
tupleId = (opValue <= current) ? current : next;
DBUG_PRINT("info", ("Returning %lu", (ulong) tupleId));
info->m_first_tuple_id = tupleId;
} }
DBUG_RETURN(0); DBUG_RETURN(0);
} }
......
...@@ -2248,8 +2248,6 @@ int ha_ndbcluster::write_row(byte *record) ...@@ -2248,8 +2248,6 @@ int ha_ndbcluster::write_row(byte *record)
m_skip_auto_increment= FALSE; m_skip_auto_increment= FALSE;
if ((error= update_auto_increment())) if ((error= update_auto_increment()))
DBUG_RETURN(error); DBUG_RETURN(error);
/* Ensure that handler is always called for auto_increment values */
thd->next_insert_id= 0;
m_skip_auto_increment= !auto_increment_column_changed; m_skip_auto_increment= !auto_increment_column_changed;
} }
} }
...@@ -4830,6 +4828,8 @@ ulonglong ha_ndbcluster::get_auto_increment() ...@@ -4830,6 +4828,8 @@ ulonglong ha_ndbcluster::get_auto_increment()
{ {
int cache_size; int cache_size;
Uint64 auto_value; Uint64 auto_value;
Uint64 step= current_thd->variables.auto_increment_increment;
Uint64 start= current_thd->variables.auto_increment_offset;
DBUG_ENTER("get_auto_increment"); DBUG_ENTER("get_auto_increment");
DBUG_PRINT("enter", ("m_tabname: %s", m_tabname)); DBUG_PRINT("enter", ("m_tabname: %s", m_tabname));
Ndb *ndb= get_ndb(); Ndb *ndb= get_ndb();
...@@ -4851,7 +4851,7 @@ ulonglong ha_ndbcluster::get_auto_increment() ...@@ -4851,7 +4851,7 @@ ulonglong ha_ndbcluster::get_auto_increment()
if (m_skip_auto_increment && if (m_skip_auto_increment &&
ndb->readAutoIncrementValue((const NDBTAB *) m_table, auto_value) || ndb->readAutoIncrementValue((const NDBTAB *) m_table, auto_value) ||
ndb->getAutoIncrementValue((const NDBTAB *) m_table, ndb->getAutoIncrementValue((const NDBTAB *) m_table,
auto_value, cache_size)) auto_value, cache_size, step, start))
{ {
if (--retries && if (--retries &&
ndb->getNdbError().status == NdbError::TemporaryError); ndb->getNdbError().status == NdbError::TemporaryError);
...@@ -4888,7 +4888,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): ...@@ -4888,7 +4888,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
HA_NEED_READ_RANGE_BUFFER | HA_NEED_READ_RANGE_BUFFER |
HA_CAN_GEOMETRY | HA_CAN_GEOMETRY |
HA_CAN_BIT_FIELD | HA_CAN_BIT_FIELD |
HA_PARTIAL_COLUMN_READ), HA_PARTIAL_COLUMN_READ |
HA_EXTERNAL_AUTO_INCREMENT),
m_share(0), m_share(0),
m_use_write(FALSE), m_use_write(FALSE),
m_ignore_dup_key(FALSE), m_ignore_dup_key(FALSE),
......
...@@ -1598,6 +1598,8 @@ int handler::update_auto_increment() ...@@ -1598,6 +1598,8 @@ int handler::update_auto_increment()
ulonglong nr; ulonglong nr;
THD *thd= table->in_use; THD *thd= table->in_use;
struct system_variables *variables= &thd->variables; struct system_variables *variables= &thd->variables;
bool external_auto_increment=
table->file->table_flags() & HA_EXTERNAL_AUTO_INCREMENT;
DBUG_ENTER("handler::update_auto_increment"); DBUG_ENTER("handler::update_auto_increment");
/* /*
...@@ -1615,12 +1617,12 @@ int handler::update_auto_increment() ...@@ -1615,12 +1617,12 @@ int handler::update_auto_increment()
adjust_next_insert_id_after_explicit_value(nr); adjust_next_insert_id_after_explicit_value(nr);
DBUG_RETURN(0); DBUG_RETURN(0);
} }
if (!(nr= thd->next_insert_id)) if (external_auto_increment || !(nr= thd->next_insert_id))
{ {
if ((nr= get_auto_increment()) == ~(ulonglong) 0) if ((nr= get_auto_increment()) == ~(ulonglong) 0)
DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED); // Mark failure
if (variables->auto_increment_increment != 1) if (!external_auto_increment && variables->auto_increment_increment != 1)
nr= next_insert_id(nr-1, variables); nr= next_insert_id(nr-1, variables);
/* /*
Update next row based on the found value. This way we don't have to Update next row based on the found value. This way we don't have to
......
...@@ -93,7 +93,8 @@ ...@@ -93,7 +93,8 @@
#define HA_CAN_BIT_FIELD (1 << 28) /* supports bit fields */ #define HA_CAN_BIT_FIELD (1 << 28) /* supports bit fields */
#define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */ #define HA_NEED_READ_RANGE_BUFFER (1 << 29) /* for read_multi_range */
#define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30) #define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
/* The storage engine manages auto_increment itself */
#define HA_EXTERNAL_AUTO_INCREMENT (1 << 31)
/* bits in index_flags(index_number) for what you can do with index */ /* bits in index_flags(index_number) for what you can do with index */
#define HA_READ_NEXT 1 /* TODO really use this flag */ #define HA_READ_NEXT 1 /* TODO really use this flag */
......
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