#At file:///home/marty/MySQL/mysql-5.1-telco-6.2/
3142 Martin Skold 2010-12-03
Bug#38914 permanent table crash after truncate table with slash in keyname: Ndb doesn't support '/' in index names so we need to transform that into the character code instead
modified:
mysql-test/suite/ndb/r/ndb_index.result
mysql-test/suite/ndb/t/ndb_index.test
sql/ha_ndbcluster.cc
sql/ha_ndbcluster.h
=== modified file 'mysql-test/suite/ndb/r/ndb_index.result'
--- a/mysql-test/suite/ndb/r/ndb_index.result 2007-06-27 12:28:02 +0000
+++ b/mysql-test/suite/ndb/r/ndb_index.result 2010-12-03 13:15:33 +0000
@@ -152,3 +152,23 @@ port67 node78 pop98 1
select port, accessnode, pop, accesstype from t1 where pop='pop98' and accessnode='node78' and port='port67' and customer_id='foo';
port accessnode pop accesstype
drop table t1;
+CREATE TABLE inleveroverzicht (
+id int(11) NOT NULL auto_increment,
+klantid int(11) NOT NULL default '0',
+productcode varchar(255) NOT NULL default '0',
+aantal int(11) NOT NULL default '0',
+PRIMARY KEY (id),
+KEY klantid (klantid),
+KEY `klantid/productcode` (klantid,productcode)
+) ENGINE=NDBCLUSTER DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
+INSERT INTO inleveroverzicht (id, klantid, productcode, aantal) VALUES
+(33, 31, '15674', 11),
+(32, 31, '0001256', 1);
+SELECT * from inleveroverzicht ORDER BY id;
+id klantid productcode aantal
+32 31 0001256 1
+33 31 15674 11
+TRUNCATE TABLE inleveroverzicht;
+SELECT * from inleveroverzicht ORDER BY id;
+id klantid productcode aantal
+DROP TABLE inleveroverzicht;
=== modified file 'mysql-test/suite/ndb/t/ndb_index.test'
--- a/mysql-test/suite/ndb/t/ndb_index.test 2007-07-04 20:38:53 +0000
+++ b/mysql-test/suite/ndb/t/ndb_index.test 2010-12-03 13:15:33 +0000
@@ -129,3 +129,27 @@ select port, accessnode, pop, accesstype
drop table t1;
# End of 4.1 tests
+
+
+# Bug#38914 permanent table crash after truncate table with slash in keyname
+CREATE TABLE inleveroverzicht (
+ id int(11) NOT NULL auto_increment,
+ klantid int(11) NOT NULL default '0',
+ productcode varchar(255) NOT NULL default '0',
+ aantal int(11) NOT NULL default '0',
+ PRIMARY KEY (id),
+ KEY klantid (klantid),
+ KEY `klantid/productcode` (klantid,productcode)
+) ENGINE=NDBCLUSTER DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
+
+INSERT INTO inleveroverzicht (id, klantid, productcode, aantal) VALUES
+(33, 31, '15674', 11),
+(32, 31, '0001256', 1);
+
+SELECT * from inleveroverzicht ORDER BY id;
+
+TRUNCATE TABLE inleveroverzicht;
+
+SELECT * from inleveroverzicht ORDER BY id;
+
+DROP TABLE inleveroverzicht;
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc 2010-10-20 12:13:52 +0000
+++ b/sql/ha_ndbcluster.cc 2010-12-03 13:15:33 +0000
@@ -1313,20 +1313,48 @@ static void ndb_clear_index(NDBDICT *dic
ndb_init_index(data);
}
+static
+void ndb_protect_char(const char* from, char* to, uint to_length, char protect)
+{
+ uint fpos= 0, tpos= 0;
+
+ while(from[fpos] != '\0' && tpos < to_length - 1)
+ {
+ if (from[fpos] == protect)
+ {
+ int len= 0;
+ to[tpos++]= '@';
+ if(tpos < to_length - 5)
+ {
+ len= sprintf(to+tpos, "00%u", (uint) protect);
+ tpos+= len;
+ }
+ }
+ else
+ {
+ to[tpos++]= from[fpos];
+ }
+ fpos++;
+ }
+ to[tpos]= '\0';
+}
+
/*
Associate a direct reference to an index handle
with an index (for faster access)
*/
int ha_ndbcluster::add_index_handle(THD *thd, NDBDICT *dict, KEY *key_info,
- const char *index_name, uint index_no)
+ const char *key_name, uint index_no)
{
+ char index_name[FN_LEN + 1];
int error= 0;
NDB_INDEX_TYPE idx_type= get_index_type_from_table(index_no);
m_index[index_no].type= idx_type;
DBUG_ENTER("ha_ndbcluster::add_index_handle");
DBUG_PRINT("enter", ("table %s", m_tabname));
-
+
+ ndb_protect_char(key_name, index_name, sizeof(index_name) - 1, '/');
if (idx_type != PRIMARY_KEY_INDEX && idx_type != UNIQUE_INDEX)
{
DBUG_PRINT("info", ("Get handle to index %s", index_name));
@@ -6056,6 +6084,7 @@ int ha_ndbcluster::create_ndb_index(THD
KEY *key_info,
bool unique)
{
+ char index_name[FN_LEN + 1];
Ndb *ndb= get_ndb(thd);
NdbDictionary::Dictionary *dict= ndb->getDictionary();
KEY_PART_INFO *key_part= key_info->key_part;
@@ -6064,7 +6093,10 @@ int ha_ndbcluster::create_ndb_index(THD
DBUG_ENTER("ha_ndbcluster::create_index");
DBUG_PRINT("enter", ("name: %s ", name));
- NdbDictionary::Index ndb_index(name);
+ ndb_protect_char(name, index_name, sizeof(index_name) - 1, '/');
+ DBUG_PRINT("info", ("index name: %s ", index_name));
+
+ NdbDictionary::Index ndb_index(index_name);
if (unique)
ndb_index.setType(NdbDictionary::Index::UniqueHashIndex);
else
=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h 2010-02-09 11:42:14 +0000
+++ b/sql/ha_ndbcluster.h 2010-12-03 13:15:33 +0000
@@ -514,7 +514,7 @@ private:
void renumber_indexes(Ndb *ndb, TABLE *tab);
int drop_indexes(Ndb *ndb, TABLE *tab);
int add_index_handle(THD *thd, NdbDictionary::Dictionary *dict,
- KEY *key_info, const char *index_name, uint index_no);
+ KEY *key_info, const char *key_name, uint index_no);
int add_table_ndb_record(NdbDictionary::Dictionary *dict);
int add_hidden_pk_ndb_record(NdbDictionary::Dictionary *dict);
int add_index_ndb_record(NdbDictionary::Dictionary *dict,
| Thread |
|---|
| • bzr commit into mysql-5.1-telco-6.2 branch (Martin.Skold:3142) Bug#38914 | Martin Skold | 3 Dec |