#At file:///home/marty/MySQL/mysql-5.1-telco-6.3_merge/
3340 Martin Skold 2010-12-15 [merge]
Bug#38914 permanent table crash after truncate table with slash in keyname: merge
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 2010-03-01 19:26:45 +0000
+++ b/mysql-test/suite/ndb/r/ndb_index.result 2010-12-15 14:06:31 +0000
@@ -269,3 +269,23 @@ b
5
6
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 2010-03-01 19:26:45 +0000
+++ b/mysql-test/suite/ndb/t/ndb_index.test 2010-12-15 14:06:31 +0000
@@ -170,3 +170,27 @@ select distinct b from t1;
select distinct b from t1 group by b;
drop table t1;
+
+# 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 14:01:08 +0000
+++ b/sql/ha_ndbcluster.cc 2010-12-15 14:06:31 +0000
@@ -1593,20 +1593,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));
@@ -7323,6 +7351,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;
@@ -7331,7 +7360,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-09-15 18:26:11 +0000
+++ b/sql/ha_ndbcluster.h 2010-12-15 14:06:31 +0000
@@ -625,7 +625,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.3 branch (Martin.Skold:3340) Bug#38914 | Martin Skold | 15 Dec |