diff -ru innodb_plugin/dict/dict0dict.c innodb_plugin/dict/dict0dict.c --- innodb_plugin/dict/dict0dict.c 2009-11-24 20:05:31.000000000 +0900 +++ innodb_plugin/dict/dict0dict.c 2009-11-24 23:43:30.000000000 +0900 @@ -1612,9 +1612,42 @@ dict_index_get_nth_field(new_index, i)->col->ord_part = 1; } + + if (dict_index_is_unique(new_index)) { + /* If the new index is unique index, it should be added + as the "last unique index" (but should skip default_clust_index)*/ + dict_index_t* ind; + dict_index_t* prev; + + ind = dict_table_get_first_index(table); + prev = NULL; + + if (ind && row_table_got_default_clust_index(table)) { + prev = ind; + ind = dict_table_get_next_index(ind); + } + + while (ind && dict_index_is_unique(ind)) { + prev = ind; + ind = dict_table_get_next_index(ind); + } + + if (ind) { + if (prev) { + UT_LIST_INSERT_AFTER(indexes, table->indexes, prev, new_index); + } else { + /* impossible? */ + UT_LIST_ADD_FIRST(indexes, table->indexes, new_index); + } + } else { + UT_LIST_ADD_LAST(indexes, table->indexes, new_index); + } + } else { /* Add the new index as the last index for the table */ UT_LIST_ADD_LAST(indexes, table->indexes, new_index); + } + new_index->table = table; new_index->table_name = table->name;