diff options
-rw-r--r-- | mysql-test/r/key.result | 10 | ||||
-rw-r--r-- | mysql-test/t/key.test | 1 | ||||
-rw-r--r-- | sql/table.cc | 21 |
3 files changed, 31 insertions, 1 deletions
diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index 0bc241c0d19..75fc469460e 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -332,8 +332,16 @@ UNIQUE i1idx (i1), UNIQUE i2idx (i2)); desc t1; Field Type Null Key Default Extra -i1 int(11) UNI 0 +i1 int(11) PRI 0 i2 int(11) UNI 0 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i1` int(11) NOT NULL default '0', + `i2` int(11) NOT NULL default '0', + UNIQUE KEY `i1idx` (`i1`), + UNIQUE KEY `i2idx` (`i2`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; create table t1 ( c1 int, diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 796e36cb608..9aab8a13b06 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -330,6 +330,7 @@ create table t1 ( UNIQUE i1idx (i1), UNIQUE i2idx (i2)); desc t1; +show create table t1; drop table t1; # diff --git a/sql/table.cc b/sql/table.cc index 513f42665a6..8ac64ac198d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -567,6 +567,27 @@ int openfrm(const char *name, const char *alias, uint db_stat, uint prgflag, if (outparam->key_info[key].flags & HA_FULLTEXT) outparam->key_info[key].algorithm= HA_KEY_ALG_FULLTEXT; + if (primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME)) + { + /* + If the UNIQUE key doesn't have NULL columns and is not a part key + declare this as a primary key. + */ + primary_key=key; + for (i=0 ; i < keyinfo->key_parts ;i++) + { + uint fieldnr= key_part[i].fieldnr; + if (!fieldnr || + outparam->field[fieldnr-1]->null_ptr || + outparam->field[fieldnr-1]->key_length() != + key_part[i].length) + { + primary_key=MAX_KEY; // Can't be used + break; + } + } + } + for (i=0 ; i < keyinfo->key_parts ; key_part++,i++) { if (new_field_pack_flag <= 1) |