diff options
author | unknown <ramil@mysql.com> | 2005-03-15 13:32:12 +0400 |
---|---|---|
committer | unknown <ramil@mysql.com> | 2005-03-15 13:32:12 +0400 |
commit | 9c04a77e0c69728941387e88bd118adbc0374c45 (patch) | |
tree | 41e3f57ec9e5632602bbaf0aeb4a973e7c77dccb | |
parent | 2427f3695ccd495eb33ce10c3fb3a636823e8850 (diff) | |
download | mariadb-git-9c04a77e0c69728941387e88bd118adbc0374c45.tar.gz |
A fix (bug #8489: Strange auto_increment behaviour with HEAP table).
heap/hp_create.c:
A fix (bug #8489: Strange auto_increment behaviour with HEAP table).
Handle autoincrement keys MyISAM-way.
include/heap.h:
A fix (bug #8489: Strange auto_increment behaviour with HEAP table).
Handle autoincrement keys MyISAM-way.
sql/ha_heap.cc:
A fix (bug #8489: Strange auto_increment behaviour with HEAP table).
Handle autoincrement keys MyISAM-way.
-rw-r--r-- | heap/hp_create.c | 3 | ||||
-rw-r--r-- | include/heap.h | 2 | ||||
-rw-r--r-- | mysql-test/r/heap.result | 42 | ||||
-rw-r--r-- | mysql-test/t/heap.test | 29 | ||||
-rw-r--r-- | sql/ha_heap.cc | 12 |
5 files changed, 82 insertions, 6 deletions
diff --git a/heap/hp_create.c b/heap/hp_create.c index af32fefea1b..b1b132a16fb 100644 --- a/heap/hp_create.c +++ b/heap/hp_create.c @@ -137,6 +137,8 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, keyinfo->write_key= hp_write_key; keyinfo->hash_buckets= 0; } + if ((keyinfo->flag & HA_AUTO_KEY) && create_info->with_auto_increment) + share->auto_key= i + 1; } share->min_records= min_records; share->max_records= max_records; @@ -147,7 +149,6 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef, share->keys= keys; share->max_key_length= max_length; share->changed= 0; - share->auto_key= create_info->auto_key; share->auto_key_type= create_info->auto_key_type; share->auto_increment= create_info->auto_increment; /* Must be allocated separately for rename to work */ diff --git a/include/heap.h b/include/heap.h index ac2b38d1f2d..51f7b0cfa6a 100644 --- a/include/heap.h +++ b/include/heap.h @@ -183,10 +183,10 @@ typedef struct st_heap_info typedef struct st_heap_create_info { - uint auto_key; uint auto_key_type; ulong max_table_size; ulonglong auto_increment; + my_bool with_auto_increment; } HP_CREATE_INFO; /* Prototypes for heap-functions */ diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result index b1cd17b444c..29207a4ae98 100644 --- a/mysql-test/r/heap.result +++ b/mysql-test/r/heap.result @@ -249,3 +249,45 @@ a 3 2 drop table t1; +create table t1 (a bigint unsigned auto_increment primary key, b int, +key (b, a)) engine=heap; +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +select * from t1; +a b +1 1 +2 1 +3 1 +4 1 +5 1 +6 1 +7 1 +8 1 +drop table t1; +create table t1 (a int not null, b int not null auto_increment, +primary key(a, b), key(b)) engine=heap; +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +select * from t1; +a b +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +drop table t1; diff --git a/mysql-test/t/heap.test b/mysql-test/t/heap.test index bc0b28370ec..e082993a58e 100644 --- a/mysql-test/t/heap.test +++ b/mysql-test/t/heap.test @@ -195,3 +195,32 @@ delete from t1 where a is null; insert into t1 values ('2'), ('3'); select * from t1; drop table t1; + +# +# Bug #8489: Strange auto_increment behaviour +# + +create table t1 (a bigint unsigned auto_increment primary key, b int, + key (b, a)) engine=heap; +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +insert t1 (b) values (1); +select * from t1; +drop table t1; +create table t1 (a int not null, b int not null auto_increment, + primary key(a, b), key(b)) engine=heap; +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +insert t1 (a) values (1); +select * from t1; +drop table t1; diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index 3c2249ce281..c483ab8fffa 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -446,6 +446,7 @@ int ha_heap::create(const char *name, TABLE *table_arg, HA_KEYSEG *seg; char buff[FN_REFLEN]; int error; + bool found_real_auto_increment= 0; for (key= parts= 0; key < table_arg->keys; key++) parts+= table_arg->key_info[key].key_parts; @@ -506,17 +507,20 @@ int ha_heap::create(const char *name, TABLE *table_arg, seg->null_bit= 0; seg->null_pos= 0; } + // We have to store field->key_type() as seg->type can differ from it if (field->flags & AUTO_INCREMENT_FLAG) - { - auto_key= key + 1; auto_key_type= field->key_type(); - } } } + if (table_arg->found_next_number_field) + { + keydef[table_arg->next_number_index].flag|= HA_AUTO_KEY; + found_real_auto_increment= table_arg->next_number_key_offset == 0; + } mem_per_row+= MY_ALIGN(table_arg->reclength + 1, sizeof(char*)); HP_CREATE_INFO hp_create_info; - hp_create_info.auto_key= auto_key; hp_create_info.auto_key_type= auto_key_type; + hp_create_info.with_auto_increment= found_real_auto_increment; hp_create_info.auto_increment= (create_info->auto_increment_value ? create_info->auto_increment_value - 1 : 0); hp_create_info.max_table_size=current_thd->variables.max_heap_table_size; |