Commit be580475 authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

fix auto-increment in sub-key and insert ... select

parent 58788787
......@@ -100,6 +100,7 @@ typedef struct st_mi_create_info
ulong raid_chunksize;
uint old_options;
uint8 language;
my_bool with_auto_increment;
} MI_CREATE_INFO;
struct st_myisam_info; /* For referense */
......
......@@ -3694,8 +3694,8 @@ void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows)
MI_KEYDEF *key=share->keyinfo;
for (i=0 ; i < share->base.keys ; i++,key++)
{
if (!(key->flag & HA_NOSAME) && ! mi_too_big_key_for_sort(key,rows) &&
info->s->base.auto_key != i+1)
if (!(key->flag & (HA_NOSAME|HA_AUTO_KEY)) &&
! mi_too_big_key_for_sort(key,rows))
{
share->state.key_map&= ~ ((ulonglong) 1 << i);
info->update|= HA_STATE_CHANGED;
......
......@@ -304,7 +304,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs,
if (keydef->flag & HA_BINARY_PACK_KEY)
options|=HA_OPTION_PACK_KEYS; /* Using packed keys */
if (keydef->flag & HA_AUTO_KEY)
if (keydef->flag & HA_AUTO_KEY && ci->with_auto_increment)
share.base.auto_key=i+1;
for (j=0, keyseg=keydef->seg ; j < keydef->keysegs ; j++, keyseg++)
{
......
......@@ -84,6 +84,16 @@ ordid ord
3 sdj
1 zzz
drop table t1;
create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid, id));
create table t2 (sid char(20), id int(2));
insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
insert into t1 select * from t2;
select * from t1;
sid id
skr 1
skr 2
test 1
drop table t1,t2;
create table t1 (a int not null primary key auto_increment);
insert into t1 values (0);
update t1 set a=0;
......
......@@ -52,6 +52,13 @@ insert into t1 values (NULL,'sdj'),(NULL,'sdj'),(NULL,"abc"),(NULL,'abc'),(NULL,
select * from t1;
drop table t1;
create table t1 (sid char(5), id int(2) NOT NULL auto_increment, key(sid, id));
create table t2 (sid char(20), id int(2));
insert into t2 values ('skr',NULL),('skr',NULL),('test',NULL);
insert into t1 select * from t2;
select * from t1;
drop table t1,t2;
#
# Test of auto_increment columns when they are set to 0
#
......@@ -62,3 +69,4 @@ update t1 set a=0;
select * from t1;
check table t1;
drop table t1;
......@@ -1021,7 +1021,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
{
int error;
uint i,j,recpos,minpos,fieldpos,temp_length,length;
bool found_auto_increment=0;
bool found_auto_increment=0, found_real_auto_increment=0;
enum ha_base_keytype type;
char buff[FN_REFLEN];
KEY *pos;
......@@ -1091,11 +1091,11 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
keydef[i].seg[j].null_bit=0;
keydef[i].seg[j].null_pos=0;
}
if (j == 0 && field->flags & AUTO_INCREMENT_FLAG &&
!found_auto_increment)
if (field->flags & AUTO_INCREMENT_FLAG && !found_auto_increment)
{
keydef[i].flag|=HA_AUTO_KEY;
found_auto_increment=1;
found_real_auto_increment=(j==0);
}
if (field->type() == FIELD_TYPE_BLOB)
{
......@@ -1177,6 +1177,7 @@ int ha_myisam::create(const char *name, register TABLE *table_arg,
bzero((char*) &create_info,sizeof(create_info));
create_info.max_rows=table_arg->max_rows;
create_info.reloc_rows=table_arg->min_rows;
create_info.with_auto_increment=found_real_auto_increment;
create_info.auto_increment=(info->auto_increment_value ?
info->auto_increment_value -1 :
(ulonglong) 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment