diff options
author | tomas@poseidon.ndb.mysql.com <> | 2005-01-26 11:31:46 +0100 |
---|---|---|
committer | tomas@poseidon.ndb.mysql.com <> | 2005-01-26 11:31:46 +0100 |
commit | 5779a6a576100fa008f51bcd9ad50bce6007c037 (patch) | |
tree | 4e04933cc990354077d53b898f92e4a29019b6f6 /sql | |
parent | 9259dd1d819bc70ff4ee249494cc25967e7f18c5 (diff) | |
download | mariadb-git-5779a6a576100fa008f51bcd9ad50bce6007c037.tar.gz |
Bug#8101 unique indexes which attribute are _not_ specified in the order of the table does not work
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_ndbcluster.cc | 54 | ||||
-rw-r--r-- | sql/ha_ndbcluster.h | 1 |
2 files changed, 50 insertions, 5 deletions
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index c5bb4984f40..437b5ebcdf7 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -765,6 +765,42 @@ int ha_ndbcluster::get_metadata(const char *path) DBUG_RETURN(build_index_list(table, ILBP_OPEN)); } +static int fix_unique_index_attr_order(NDB_INDEX_DATA &data, + const NDBINDEX *index, + KEY *key_info) +{ + DBUG_ENTER("fix_unique_index_attr_order"); + unsigned sz= index->getNoOfIndexColumns(); + + if (data.unique_index_attrid_map) + my_free((char*)data.unique_index_attrid_map, MYF(0)); + data.unique_index_attrid_map= (unsigned char*)my_malloc(sz,MYF(MY_WME)); + + KEY_PART_INFO* key_part= key_info->key_part; + KEY_PART_INFO* end= key_part+key_info->key_parts; + DBUG_ASSERT(key_info->key_parts == sz); + for (unsigned i= 0; key_part != end; key_part++, i++) + { + const char *field_name= key_part->field->field_name; + unsigned name_sz= strlen(field_name); + if (name_sz >= NDB_MAX_ATTR_NAME_SIZE) + name_sz= NDB_MAX_ATTR_NAME_SIZE-1; +#ifndef DBUG_OFF + data.unique_index_attrid_map[i]= 255; +#endif + for (unsigned j= 0; j < sz; j++) + { + const NdbDictionary::Column *c= index->getColumn(j); + if (strncmp(field_name, c->getName(), name_sz) == 0) + { + data.unique_index_attrid_map[i]= j; + break; + } + } + DBUG_ASSERT(data.unique_index_attrid_map[i] != 255); + } + DBUG_RETURN(0); +} int ha_ndbcluster::build_index_list(TABLE *tab, enum ILBP phase) { @@ -839,7 +875,8 @@ int ha_ndbcluster::build_index_list(TABLE *tab, enum ILBP phase) const NDBINDEX *index= dict->getIndex(unique_index_name, m_tabname); if (!index) DBUG_RETURN(1); m_index[i].unique_index= (void *) index; - } + error= fix_unique_index_attr_order(m_index[i], index, key_info); + } } DBUG_RETURN(error); @@ -897,6 +934,11 @@ void ha_ndbcluster::release_metadata() { m_index[i].unique_index= NULL; m_index[i].index= NULL; + if (m_index[i].unique_index_attrid_map) + { + my_free((char *)m_index[i].unique_index_attrid_map, MYF(0)); + m_index[i].unique_index_attrid_map= NULL; + } } DBUG_VOID_RETURN; @@ -1209,7 +1251,8 @@ int ha_ndbcluster::unique_index_read(const byte *key, for (i= 0; key_part != end; key_part++, i++) { - if (set_ndb_key(op, key_part->field, i, + if (set_ndb_key(op, key_part->field, + m_index[active_index].unique_index_attrid_map[i], key_part->null_bit ? key_ptr + 1 : key_ptr)) ERR_RETURN(trans->getNdbError()); key_ptr+= key_part->store_length; @@ -3836,9 +3879,10 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): for (i= 0; i < MAX_KEY; i++) { - m_index[i].type= UNDEFINED_INDEX; - m_index[i].unique_index= NULL; - m_index[i].index= NULL; + m_index[i].type= UNDEFINED_INDEX; + m_index[i].unique_index= NULL; + m_index[i].index= NULL; + m_index[i].unique_index_attrid_map= NULL; } DBUG_VOID_RETURN; diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 15e61a93574..07b305bad3e 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -52,6 +52,7 @@ typedef struct ndb_index_data { NDB_INDEX_TYPE type; void *index; void *unique_index; + unsigned char *unique_index_attrid_map; } NDB_INDEX_DATA; typedef struct st_ndbcluster_share { |