Commit eb06bee5 authored by gni@dev3-221.dev.cn.tlan's avatar gni@dev3-221.dev.cn.tlan
Browse files

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

parent 3f3be4f3
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
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
+43 −0
Original line number Diff line number Diff line
-- 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
+16 −15
Original line number Diff line number Diff line
@@ -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