Commit b1e20006 authored by unknown's avatar unknown
Browse files

Bug#16997 Table rename that changes database does not rename indexes,...

Bug#16997  Table rename that changes database does not rename indexes, recreate indexes in new database


parent 38b1f7c7
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
DROP TABLE IF EXISTS t1,t2;
drop database if exists mysqltest;
CREATE TABLE t1 (
pk1 INT NOT NULL PRIMARY KEY,
attr1 INT NOT NULL,
attr2 INT,
attr3 VARCHAR(10),
INDEX i1(attr1)
) ENGINE=ndbcluster;
alter table t1 rename t2;
create database ndbtest;
alter table t2 rename ndbtest.t2;
drop table ndbtest.t2;
drop database ndbtest;
+32 −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;
drop database if exists mysqltest;
--enable_warnings

#
# Table rename tests
#

#
# Create a normal table with primary key
#
CREATE TABLE t1 (
  pk1 INT NOT NULL PRIMARY KEY,
  attr1 INT NOT NULL,
  attr2 INT,
  attr3 VARCHAR(10),
  INDEX i1(attr1)
) ENGINE=ndbcluster;

alter table t1 rename t2;

create database ndbtest;
alter table t2 rename ndbtest.t2;

drop table ndbtest.t2;
drop database ndbtest;

# End of 4.1 tests
+20 −3
Original line number Diff line number Diff line
@@ -956,14 +956,14 @@ public:

    /**
     * Create defined table given defined Table instance
     * @param Table Table to create
     * @param Table instance to create
     * @return 0 if successful otherwise -1.
     */
    int createTable(const Table &);

    /**
     * Drop table given retrieved Table instance
     * @param Table Table to drop
     * @param Table instance to drop
     * @return 0 if successful otherwise -1.
     */
    int dropTable(Table &);
@@ -1028,6 +1028,14 @@ public:
    int dropIndex(const char * indexName,
		  const char * tableName);


    /**
     * Drop index the defined Index instance
     * @param Index to drop
     * @return 0 if successful otherwise -1.
     */
    int dropIndex(const Index &);    

    /**
     * Get index with given name, NULL if undefined
     * @param indexName  Name of index to get.
@@ -1037,6 +1045,15 @@ public:
    const Index * getIndex(const char * indexName,
			   const char * tableName);

    /**
     * Get index with given name, NULL if undefined
     * @param indexName  Name of index to get.
     * @param Table instance table that index belongs to.
     * @return  index if successful, otherwise 0.
     */
    const Index * getIndex(const char * indexName,
			   const Table & table);

#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
    /**
     * Invalidate cached index object
+16 −0
Original line number Diff line number Diff line
@@ -786,6 +786,12 @@ NdbDictionary::Dictionary::dropIndex(const char * indexName,
  return m_impl.dropIndex(indexName, tableName);
}

int 
NdbDictionary::Dictionary::dropIndex(const Index & ind)
{
  return m_impl.dropIndex(NdbIndexImpl::getImpl(ind));
}

const NdbDictionary::Index * 
NdbDictionary::Dictionary::getIndex(const char * indexName,
				    const char * tableName)
@@ -796,6 +802,16 @@ NdbDictionary::Dictionary::getIndex(const char * indexName,
  return 0;
}

const NdbDictionary::Index * 
NdbDictionary::Dictionary::getIndex(const char * indexName,
				    const Table & t)
{
  NdbIndexImpl * i = m_impl.getIndex(indexName, & NdbTableImpl::getImpl(t));
  if(i)
    return i->m_facade;
  return 0;
}

void
NdbDictionary::Dictionary::invalidateIndex(const char * indexName,
                                           const char * tableName){
+5 −22
Original line number Diff line number Diff line
@@ -2147,7 +2147,7 @@ NdbDictionaryImpl::dropIndex(const char * indexName,
    m_error.code = 4243;
    return -1;
  }
  int ret = dropIndex(*idx, tableName);
  int ret = dropIndex(*idx); //, tableName);
  // If index stored in cache is incompatible with the one in the kernel
  // we must clear the cache and try again
  if (ret == INCOMPATIBLE_VERSION) {
@@ -2169,42 +2169,25 @@ NdbDictionaryImpl::dropIndex(const char * indexName,
}

int
NdbDictionaryImpl::dropIndex(NdbIndexImpl & impl, const char * tableName)
NdbDictionaryImpl::dropIndex(NdbIndexImpl & impl)
{
  const char * indexName = impl.getName();
  if (tableName || m_ndb.usingFullyQualifiedNames()) {
    NdbTableImpl * timpl = impl.m_table;
    
    if (timpl == 0) {
      m_error.code = 709;
      return -1;
    }

    const char * internalIndexName = (tableName)
      ?
      m_ndb.internalizeIndexName(getTable(tableName), indexName)
      :
      m_ndb.internalizeTableName(indexName); // Index is also a table

    if(impl.m_status == NdbDictionary::Object::New){
      return dropIndex(indexName, tableName);
    }
    
    int ret = m_receiver.dropIndex(impl, *timpl);
    if(ret == 0){
      m_localHash.drop(internalIndexName);
      m_localHash.drop(timpl->m_internalName.c_str());
      m_globalHash->lock();
      impl.m_table->m_status = NdbDictionary::Object::Invalid;
      m_globalHash->drop(impl.m_table);
      timpl->m_status = NdbDictionary::Object::Invalid;
      m_globalHash->drop(timpl);
      m_globalHash->unlock();
    }
    return ret;
}

  m_error.code = 4243;
  return -1;
}

int
NdbDictInterface::dropIndex(const NdbIndexImpl & impl, 
			    const NdbTableImpl & timpl)
Loading