Skip to content

Commit d5e3ba7

Browse files
author
ramil@mysql.com
committed
merging
2 parents 021f8d2 + 04328c3 commit d5e3ba7

File tree

6 files changed

+87
-8
lines changed

6 files changed

+87
-8
lines changed

heap/hp_create.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
168168
keyinfo->write_key= hp_write_key;
169169
keyinfo->hash_buckets= 0;
170170
}
171+
if ((keyinfo->flag & HA_AUTO_KEY) && create_info->with_auto_increment)
172+
share->auto_key= i + 1;
171173
}
172174
share->min_records= min_records;
173175
share->max_records= max_records;
@@ -178,7 +180,6 @@ int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
178180
share->keys= keys;
179181
share->max_key_length= max_length;
180182
share->changed= 0;
181-
share->auto_key= create_info->auto_key;
182183
share->auto_key_type= create_info->auto_key_type;
183184
share->auto_increment= create_info->auto_increment;
184185
/* Must be allocated separately for rename to work */

include/heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ typedef struct st_heap_info
183183

184184
typedef struct st_heap_create_info
185185
{
186-
uint auto_key;
187186
uint auto_key_type;
188187
ulong max_table_size;
189188
ulonglong auto_increment;
189+
my_bool with_auto_increment;
190190
} HP_CREATE_INFO;
191191

192192
/* Prototypes for heap-functions */

mysql-test/r/heap.result

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,3 +665,45 @@ length(v)
665665
65530
666666
drop table t1;
667667
set storage_engine=MyISAM;
668+
create table t1 (a bigint unsigned auto_increment primary key, b int,
669+
key (b, a)) engine=heap;
670+
insert t1 (b) values (1);
671+
insert t1 (b) values (1);
672+
insert t1 (b) values (1);
673+
insert t1 (b) values (1);
674+
insert t1 (b) values (1);
675+
insert t1 (b) values (1);
676+
insert t1 (b) values (1);
677+
insert t1 (b) values (1);
678+
select * from t1;
679+
a b
680+
1 1
681+
2 1
682+
3 1
683+
4 1
684+
5 1
685+
6 1
686+
7 1
687+
8 1
688+
drop table t1;
689+
create table t1 (a int not null, b int not null auto_increment,
690+
primary key(a, b), key(b)) engine=heap;
691+
insert t1 (a) values (1);
692+
insert t1 (a) values (1);
693+
insert t1 (a) values (1);
694+
insert t1 (a) values (1);
695+
insert t1 (a) values (1);
696+
insert t1 (a) values (1);
697+
insert t1 (a) values (1);
698+
insert t1 (a) values (1);
699+
select * from t1;
700+
a b
701+
1 1
702+
1 2
703+
1 3
704+
1 4
705+
1 5
706+
1 6
707+
1 7
708+
1 8
709+
drop table t1;

mysql-test/t/heap.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,32 @@ drop table t1;
406406
# Reset varchar test
407407
#
408408
eval set storage_engine=$default;
409+
410+
#
411+
# Bug #8489: Strange auto_increment behaviour
412+
#
413+
414+
create table t1 (a bigint unsigned auto_increment primary key, b int,
415+
key (b, a)) engine=heap;
416+
insert t1 (b) values (1);
417+
insert t1 (b) values (1);
418+
insert t1 (b) values (1);
419+
insert t1 (b) values (1);
420+
insert t1 (b) values (1);
421+
insert t1 (b) values (1);
422+
insert t1 (b) values (1);
423+
insert t1 (b) values (1);
424+
select * from t1;
425+
drop table t1;
426+
create table t1 (a int not null, b int not null auto_increment,
427+
primary key(a, b), key(b)) engine=heap;
428+
insert t1 (a) values (1);
429+
insert t1 (a) values (1);
430+
insert t1 (a) values (1);
431+
insert t1 (a) values (1);
432+
insert t1 (a) values (1);
433+
insert t1 (a) values (1);
434+
insert t1 (a) values (1);
435+
insert t1 (a) values (1);
436+
select * from t1;
437+
drop table t1;

sql/filesort.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,11 @@ static ha_rows find_all_keys(SORTPARAM *param, SQL_SELECT *select,
475475
if (*killed)
476476
{
477477
DBUG_PRINT("info",("Sort killed by user"));
478-
(void) file->extra(HA_EXTRA_NO_CACHE);
479-
file->ha_rnd_end();
478+
if (!indexfile && !quick_select)
479+
{
480+
(void) file->extra(HA_EXTRA_NO_CACHE);
481+
file->ha_rnd_end();
482+
}
480483
DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */
481484
}
482485
if (error == 0)

sql/ha_heap.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ int ha_heap::create(const char *name, TABLE *table_arg,
457457
char buff[FN_REFLEN];
458458
int error;
459459
TABLE_SHARE *share= table_arg->s;
460+
bool found_real_auto_increment= 0;
460461

461462
for (key= parts= 0; key < keys; key++)
462463
parts+= table_arg->key_info[key].key_parts;
@@ -520,19 +521,22 @@ int ha_heap::create(const char *name, TABLE *table_arg,
520521
seg->null_bit= 0;
521522
seg->null_pos= 0;
522523
}
524+
// We have to store field->key_type() as seg->type can differ from it
523525
if (field->flags & AUTO_INCREMENT_FLAG)
524-
{
525-
auto_key= key + 1;
526526
auto_key_type= field->key_type();
527-
}
528527
}
529528
}
530529
mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
531530
max_rows = (ha_rows) (table->in_use->variables.max_heap_table_size /
532531
mem_per_row);
532+
if (table_arg->found_next_number_field)
533+
{
534+
keydef[table_arg->next_number_index].flag|= HA_AUTO_KEY;
535+
found_real_auto_increment= table_arg->next_number_key_offset == 0;
536+
}
533537
HP_CREATE_INFO hp_create_info;
534-
hp_create_info.auto_key= auto_key;
535538
hp_create_info.auto_key_type= auto_key_type;
539+
hp_create_info.with_auto_increment= found_real_auto_increment;
536540
hp_create_info.auto_increment= (create_info->auto_increment_value ?
537541
create_info->auto_increment_value - 1 : 0);
538542
hp_create_info.max_table_size=current_thd->variables.max_heap_table_size;

0 commit comments

Comments
 (0)