Commit 37b188cd authored by unknown's avatar unknown

BUG#30417 Cluster misbehaves on auto-inc w/o PK.


storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp:
  The check that how many auto_increment columns in table are there should be preceded creating the table.
  If there are more than one auto_increment columns, the table shouldn't be created.
mysql-test/suite/ndb/r/ndb_autoinc.result:
  Adding test case for auto_increment isn't the default primary key columns
mysql-test/suite/ndb/t/ndb_autoinc.test:
  Adding test case for auto_increment isn't the default primary key columns
parent 115e1a1f
DROP TABLE IF EXISTS t1,t2,t3;
USE test;
CREATE TABLE t1 (
id INT AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE=NDBCLUSTER;
CREATE TABLE t2 (
id INT AUTO_INCREMENT,
KEY(id)
) ENGINE=NDBCLUSTER;
ERROR HY000: Can't create table 'test.t2' (errno: 4335)
SHOW TABLES;
Tables_in_test
t1
CREATE TABLE t3 (
id INT AUTO_INCREMENT,
KEY(id)
) ENGINE=MYISAM;
ALTER TABLE t3
ENGINE NDBCLUSTER;
ERROR HY000: Can't create table 'test.#sql-7b9e_3' (errno: 4335)
SHOW CREATE TABLE t3;
Table Create Table
t3 CREATE TABLE `t3` (
`id` int(11) NOT NULL AUTO_INCREMENT,
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
ALTER TABLE t3
ADD PRIMARY KEY (id);
SHOW CREATE TABLE t3;
Table Create Table
t3 CREATE TABLE `t3` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1, t3;
End of 5.1 tests
-- source include/have_ndb.inc
-- source include/not_embedded.inc
--disable_warnings
DROP TABLE IF EXISTS t1,t2,t3;
--enable_warnings
USE test;
CREATE TABLE t1 (
id INT AUTO_INCREMENT,
PRIMARY KEY(id)
) ENGINE=NDBCLUSTER;
# Test For bug#30417
--error 1005
CREATE TABLE t2 (
id INT AUTO_INCREMENT,
KEY(id)
) ENGINE=NDBCLUSTER;
SHOW TABLES;
CREATE TABLE t3 (
id INT AUTO_INCREMENT,
KEY(id)
) ENGINE=MYISAM;
--error 1005
ALTER TABLE t3
ENGINE NDBCLUSTER;
SHOW CREATE TABLE t3;
ALTER TABLE t3
ADD PRIMARY KEY (id);
SHOW CREATE TABLE t3;
DROP TABLE t1, t3;
--echo End of 5.1 tests
......@@ -2340,6 +2340,22 @@ NdbDictionaryImpl::createTable(NdbTableImpl &t)
{
DBUG_ENTER("NdbDictionaryImpl::createTable");
bool autoIncrement = false;
Uint64 initialValue = 0;
for (Uint32 i = 0; i < t.m_columns.size(); i++) {
const NdbColumnImpl* c = t.m_columns[i];
assert(c != NULL);
if (c->m_autoIncrement) {
if (autoIncrement) {
m_error.code = 4335;
DBUG_RETURN(-1);
}
autoIncrement = true;
initialValue = c->m_autoIncrementInitialValue;
}
}
// if the new name has not been set, use the copied name
if (t.m_newExternalName.empty())
{
......@@ -2377,21 +2393,6 @@ NdbDictionaryImpl::createTable(NdbTableImpl &t)
// auto-increment - use "t" because initial value is not in DICT
{
bool autoIncrement = false;
Uint64 initialValue = 0;
for (Uint32 i = 0; i < t.m_columns.size(); i++) {
const NdbColumnImpl* c = t.m_columns[i];
assert(c != NULL);
if (c->m_autoIncrement) {
if (autoIncrement) {
m_error.code = 4335;
delete t2;
DBUG_RETURN(-1);
}
autoIncrement = true;
initialValue = c->m_autoIncrementInitialValue;
}
}
if (autoIncrement) {
// XXX unlikely race condition - t.m_id may no longer be same table
// the tuple id range is not used on input
......
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