Below is the list of changes that have just been committed into a local
4.1 repository of marty. When marty does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet
1.2474 06/05/05 17:18:47 mskold@stripped +7 -0
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
sql/ha_ndbcluster.cc
1.180 06/05/05 17:18:37 mskold@stripped +40 -1
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
ndb/src/ndbapi/NdbDictionaryImpl.hpp
1.22 06/05/05 17:18:37 mskold@stripped +16 -6
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
ndb/src/ndbapi/NdbDictionaryImpl.cpp
1.55 06/05/05 17:18:37 mskold@stripped +5 -22
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
ndb/src/ndbapi/NdbDictionary.cpp
1.23 06/05/05 17:18:37 mskold@stripped +16 -0
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
ndb/include/ndbapi/NdbDictionary.hpp
1.23 06/05/05 17:18:37 mskold@stripped +20 -3
Bug#16997 Table rename that changes database does not rename indexes, recreate indexes in new database
mysql-test/t/ndb_rename.test
1.1 06/05/05 17:15:34 mskold@stripped +32 -0
mysql-test/r/ndb_rename.result
1.1 06/05/05 17:15:34 mskold@stripped +14 -0
mysql-test/t/ndb_rename.test
1.0 06/05/05 17:15:34 mskold@stripped +0 -0
BitKeeper file /home/marty/MySQL/mysql-4.1/mysql-test/t/ndb_rename.test
mysql-test/r/ndb_rename.result
1.0 06/05/05 17:15:34 mskold@stripped +0 -0
BitKeeper file /home/marty/MySQL/mysql-4.1/mysql-test/r/ndb_rename.result
# This is a BitKeeper patch. What follows are the unified diffs for the
# set of deltas contained in the patch. The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mskold
# Host: linux.site
# Root: /home/marty/MySQL/mysql-4.1
--- 1.22/ndb/include/ndbapi/NdbDictionary.hpp 2005-08-18 14:02:19 +02:00
+++ 1.23/ndb/include/ndbapi/NdbDictionary.hpp 2006-05-05 17:18:37 +02:00
@@ -956,14 +956,14 @@
/**
* 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 &);
@@ -1027,7 +1027,15 @@
*/
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.
@@ -1036,6 +1044,15 @@
*/
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
/**
--- 1.22/ndb/src/ndbapi/NdbDictionary.cpp 2005-02-16 12:43:56 +01:00
+++ 1.23/ndb/src/ndbapi/NdbDictionary.cpp 2006-05-05 17:18:37 +02:00
@@ -786,11 +786,27 @@
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)
{
NdbIndexImpl * i = m_impl.getIndex(indexName, tableName);
+ if(i)
+ return i->m_facade;
+ 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;
--- 1.54/ndb/src/ndbapi/NdbDictionaryImpl.cpp 2005-08-18 14:02:20 +02:00
+++ 1.55/ndb/src/ndbapi/NdbDictionaryImpl.cpp 2006-05-05 17:18:37 +02:00
@@ -2147,7 +2147,7 @@
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,40 +2169,23 @@
}
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
--- 1.21/ndb/src/ndbapi/NdbDictionaryImpl.hpp 2004-12-20 12:36:03 +01:00
+++ 1.22/ndb/src/ndbapi/NdbDictionaryImpl.hpp 2006-05-05 17:18:37 +02:00
@@ -379,7 +379,8 @@
int createIndex(NdbIndexImpl &ix);
int dropIndex(const char * indexName,
const char * tableName);
- int dropIndex(NdbIndexImpl &, const char * tableName);
+ // int dropIndex(NdbIndexImpl &, const char * tableName);
+ int dropIndex(NdbIndexImpl &);
NdbTableImpl * getIndexTable(NdbIndexImpl * index,
NdbTableImpl * table);
@@ -397,6 +398,8 @@
bool do_add_blob_tables);
NdbIndexImpl * getIndex(const char * indexName,
const char * tableName);
+ NdbIndexImpl * getIndex(const char * indexName,
+ NdbTableImpl * table);
NdbIndexImpl * getIndexImpl(const char * name, const char * internalName);
NdbEventImpl * getEvent(const char * eventName);
NdbEventImpl * getEventImpl(const char * internalName);
@@ -643,17 +646,24 @@
return info; // autoincrement already initialized
}
+
inline
NdbIndexImpl *
NdbDictionaryImpl::getIndex(const char * indexName,
const char * tableName)
{
- if (tableName || m_ndb.usingFullyQualifiedNames()) {
+ return getIndex(indexName, (tableName) ? getTable(tableName) : NULL);
+}
+
+inline
+NdbIndexImpl *
+NdbDictionaryImpl::getIndex(const char * indexName,
+ NdbTableImpl * table)
+{
+ if (table || m_ndb.usingFullyQualifiedNames()) {
const char * internalIndexName = 0;
- if (tableName) {
- NdbTableImpl * t = getTable(tableName);
- if (t != 0)
- internalIndexName = m_ndb.internalizeIndexName(t, indexName);
+ if (table) {
+ internalIndexName = m_ndb.internalizeIndexName(table, indexName);
} else {
internalIndexName =
m_ndb.internalizeTableName(indexName); // Index is also a table
--- 1.179/sql/ha_ndbcluster.cc 2006-02-10 17:40:18 +01:00
+++ 1.180/sql/ha_ndbcluster.cc 2006-05-05 17:18:37 +02:00
@@ -898,6 +898,8 @@
DBUG_RETURN(0);
}
+
+
int ha_ndbcluster::build_index_list(Ndb *ndb, TABLE *tab, enum ILBP phase)
{
uint i;
@@ -3926,7 +3928,6 @@
DBUG_RETURN(0);
}
-
/*
Rename a table in NDB Cluster
*/
@@ -3935,12 +3936,16 @@
{
NDBDICT *dict;
char new_tabname[FN_HEADLEN];
+ char new_dbname[FN_HEADLEN];
const NDBTAB *orig_tab;
int result;
+ bool recreate_indexes= FALSE;
+ NDBDICT::List index_list;
DBUG_ENTER("ha_ndbcluster::rename_table");
DBUG_PRINT("info", ("Renaming %s to %s", from, to));
set_dbname(from);
+ set_dbname(to, new_dbname);
set_tabname(from);
set_tabname(to, new_tabname);
@@ -3958,6 +3963,12 @@
if (!(orig_tab= dict->getTable(m_tabname)))
ERR_RETURN(dict->getNdbError());
}
+ if (my_strcasecmp(system_charset_info, new_dbname, m_dbname))
+ {
+ dict->listIndexes(index_list, m_tabname);
+ recreate_indexes= TRUE;
+ }
+
m_table= (void *)orig_tab;
// Change current database to that of target table
set_dbname(to);
@@ -3966,6 +3977,34 @@
{
// Rename .ndb file
result= handler::rename_table(from, to);
+ }
+
+ // If we are moving tables between databases, we need to recreate
+ // indexes
+ if (recreate_indexes)
+ {
+ const NDBTAB *new_tab;
+ set_tabname(to);
+ if (!(new_tab= dict->getTable(m_tabname)))
+ ERR_RETURN(dict->getNdbError());
+
+ for (unsigned i = 0; i < index_list.count; i++) {
+ NDBDICT::List::Element& index_el = index_list.elements[i];
+ set_dbname(from);
+ ndb->setDatabaseName(m_dbname);
+ const NDBINDEX * index= dict->getIndex(index_el.name, *new_tab);
+ set_dbname(to);
+ ndb->setDatabaseName(m_dbname);
+ DBUG_PRINT("info", ("Creating index %s/%s",
+ m_dbname, index->getName()));
+ dict->createIndex(*index);
+ DBUG_PRINT("info", ("Dropping index %s/%s",
+ m_dbname, index->getName()));
+
+ set_dbname(from);
+ ndb->setDatabaseName(m_dbname);
+ dict->dropIndex(*index);
+ }
}
DBUG_RETURN(result);
--- New file ---
+++ mysql-test/r/ndb_rename.result 06/05/05 17:15:34
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;
--- New file ---
+++ mysql-test/t/ndb_rename.test 06/05/05 17:15:34
-- 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
| Thread |
|---|
| • bk commit into 4.1 tree (mskold:1.2474) BUG#16997 | Martin Skold | 5 May |