Skip to content

Commit 7c6cf7f

Browse files
committed
bug: ha_heap was unilaterally increasing reclength
proper fix replacing the hack from b80fa40 don't confuse length of the data area (reclength) with the offset to the "deleted" mark.
1 parent 7a63ffa commit 7c6cf7f

File tree

9 files changed

+15
-21
lines changed

9 files changed

+15
-21
lines changed

include/heap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ typedef struct st_heap_share
144144
uint key_version; /* Updated on key change */
145145
uint file_version; /* Update on clear */
146146
uint reclength;/* Length of one record */
147+
uint visible; /* Offset to the visible/deleted mark */
147148
uint changed;
148149
uint keys,max_key_length;
149150
uint currently_disabled_keys; /* saved value from "keys" when disabled */

storage/heap/_check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int heap_check_heap(HP_INFO *info, my_bool print_status)
7979
}
8080
hp_find_record(info,pos);
8181

82-
if (!info->current_ptr[share->reclength])
82+
if (!info->current_ptr[share->visible])
8383
deleted++;
8484
else
8585
records++;

storage/heap/ha_heap.cc

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ const char **ha_heap::bas_ext() const
100100

101101
int ha_heap::open(const char *name, int mode, uint test_if_locked)
102102
{
103-
if (table->s->reclength < sizeof (char*))
104-
{
105-
MEM_UNDEFINED(table->s->default_values + table->s->reclength,
106-
sizeof(char*) - table->s->reclength);
107-
table->s->reclength= sizeof(char*);
108-
MEM_UNDEFINED(table->record[0], table->s->reclength);
109-
MEM_UNDEFINED(table->record[1], table->s->reclength);
110-
}
111-
112103
internal_table= test(test_if_locked & HA_OPEN_INTERNAL_TABLE);
113104
if (internal_table || (!(file= heap_open(name, mode)) && my_errno == ENOENT))
114105
{
@@ -736,7 +727,7 @@ heap_prepare_hp_create_info(TABLE *table_arg, bool internal_table,
736727
}
737728
}
738729
}
739-
mem_per_row+= MY_ALIGN(share->reclength + 1, sizeof(char*));
730+
mem_per_row+= MY_ALIGN(max(share->reclength, sizeof(char*)) + 1, sizeof(char*));
740731
if (table_arg->found_next_number_field)
741732
{
742733
keydef[share->next_number_index].flag|= HA_AUTO_KEY;

storage/heap/hp_create.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
3333
uint keys= create_info->keys;
3434
ulong min_records= create_info->min_records;
3535
ulong max_records= create_info->max_records;
36+
uint visible_offset;
3637
DBUG_ENTER("heap_create");
3738

3839
if (!create_info->internal_table)
@@ -58,9 +59,9 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
5859

5960
/*
6061
We have to store sometimes uchar* del_link in records,
61-
so the record length should be at least sizeof(uchar*)
62+
so the visible_offset must be least at sizeof(uchar*)
6263
*/
63-
set_if_bigger(reclength, sizeof (uchar*));
64+
visible_offset= max(reclength, sizeof (char*));
6465

6566
for (i= key_segs= max_length= 0, keyinfo= keydef; i < keys; i++, keyinfo++)
6667
{
@@ -152,7 +153,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
152153
share->keydef= (HP_KEYDEF*) (share + 1);
153154
share->key_stat_version= 1;
154155
keyseg= (HA_KEYSEG*) (share->keydef + keys);
155-
init_block(&share->block, reclength + 1, min_records, max_records);
156+
init_block(&share->block, visible_offset + 1, min_records, max_records);
156157
/* Fix keys */
157158
memcpy(share->keydef, keydef, (size_t) (sizeof(keydef[0]) * keys));
158159
for (i= 0, keyinfo= share->keydef; i < keys; i++, keyinfo++)
@@ -192,6 +193,7 @@ int heap_create(const char *name, HP_CREATE_INFO *create_info,
192193
share->max_table_size= create_info->max_table_size;
193194
share->data_length= share->index_length= 0;
194195
share->reclength= reclength;
196+
share->visible= visible_offset;
195197
share->blength= 1;
196198
share->keys= keys;
197199
share->max_key_length= max_length;

storage/heap/hp_delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int heap_delete(HP_INFO *info, const uchar *record)
4545
info->update=HA_STATE_DELETED;
4646
*((uchar**) pos)=share->del_link;
4747
share->del_link=pos;
48-
pos[share->reclength]=0;/* Record deleted */
48+
pos[share->visible]=0;/* Record deleted */
4949
share->deleted++;
5050
share->key_version++;
5151
#if !defined(DBUG_OFF) && defined(EXTRA_HEAP_DEBUG)

storage/heap/hp_rrnd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int heap_rrnd(register HP_INFO *info, uchar *record, uchar *pos)
3737
info->update= 0;
3838
DBUG_RETURN(my_errno= HA_ERR_END_OF_FILE);
3939
}
40-
if (!info->current_ptr[share->reclength])
40+
if (!info->current_ptr[share->visible])
4141
{
4242
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
4343
DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);
@@ -91,7 +91,7 @@ int heap_rrnd_old(register HP_INFO *info, uchar *record, ulong pos)
9191
hp_find_record(info, pos);
9292

9393
end:
94-
if (!info->current_ptr[share->reclength])
94+
if (!info->current_ptr[share->visible])
9595
{
9696
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;
9797
DBUG_RETURN(my_errno=HA_ERR_RECORD_DELETED);

storage/heap/hp_rsame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int heap_rsame(register HP_INFO *info, uchar *record, int inx)
3232
DBUG_ENTER("heap_rsame");
3333

3434
test_active(info);
35-
if (info->current_ptr[share->reclength])
35+
if (info->current_ptr[share->visible])
3636
{
3737
if (inx < -1 || inx >= (int) share->keys)
3838
{

storage/heap/hp_scan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int heap_scan(register HP_INFO *info, uchar *record)
6262
}
6363
hp_find_record(info, pos);
6464
}
65-
if (!info->current_ptr[share->reclength])
65+
if (!info->current_ptr[share->visible])
6666
{
6767
DBUG_PRINT("warning",("Found deleted record"));
6868
info->update= HA_STATE_PREV_FOUND | HA_STATE_NEXT_FOUND;

storage/heap/hp_write.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int heap_write(HP_INFO *info, const uchar *record)
5454
}
5555

5656
memcpy(pos,record,(size_t) share->reclength);
57-
pos[share->reclength]=1;/* Mark record as not deleted */
57+
pos[share->visible]= 1; /* Mark record as not deleted */
5858
if (++share->records == share->blength)
5959
share->blength+= share->blength;
6060
info->s->key_version++;
@@ -92,7 +92,7 @@ int heap_write(HP_INFO *info, const uchar *record)
9292
share->deleted++;
9393
*((uchar**) pos)=share->del_link;
9494
share->del_link=pos;
95-
pos[share->reclength]=0;/* Record deleted */
95+
pos[share->visible]= 0; /* Record deleted */
9696

9797
DBUG_RETURN(my_errno);
9898
} /* heap_write */

0 commit comments

Comments
 (0)