Commit b0f2b107 authored by unknown's avatar unknown

MyISAM: always store alloced_rec_buff_length with the buffer itself


include/myisam.h:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_check.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_dynrec.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_extra.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_key.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_open.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/mi_packrec.c:
  always store alloced_rec_buff_length with the buffer itself
myisam/myisamdef.h:
  always store alloced_rec_buff_length with the buffer itself
parent 520e9589
...@@ -379,7 +379,6 @@ typedef struct st_mi_sort_param ...@@ -379,7 +379,6 @@ typedef struct st_mi_sort_param
my_off_t pos,max_pos,filepos,start_recpos; my_off_t pos,max_pos,filepos,start_recpos;
uint key, key_length,real_key_length,sortbuff_size; uint key, key_length,real_key_length,sortbuff_size;
uint maxbuffers, keys, find_length, sort_keys_length; uint maxbuffers, keys, find_length, sort_keys_length;
uint alloced_rec_buff_length;
my_bool fix_datafile, master; my_bool fix_datafile, master;
MI_KEYDEF *keyinfo; MI_KEYDEF *keyinfo;
SORT_INFO *sort_info; SORT_INFO *sort_info;
......
...@@ -841,8 +841,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend) ...@@ -841,8 +841,7 @@ int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend)
if (info->s->base.blobs) if (info->s->base.blobs)
{ {
if (!(to= mi_alloc_rec_buff(info, block_info.rec_len, if (!(to= mi_alloc_rec_buff(info, block_info.rec_len,
&info->rec_buff, &info->rec_buff)))
&info->alloced_rec_buff_length)))
{ {
mi_check_print_error(param,"Not enough memory for blob at %s", mi_check_print_error(param,"Not enough memory for blob at %s",
llstr(start_recpos,llbuff)); llstr(start_recpos,llbuff));
...@@ -1146,7 +1145,6 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, ...@@ -1146,7 +1145,6 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info,
goto err; goto err;
info->opt_flag|=WRITE_CACHE_USED; info->opt_flag|=WRITE_CACHE_USED;
sort_param.rec_buff=info->rec_buff; sort_param.rec_buff=info->rec_buff;
sort_param.alloced_rec_buff_length=info->alloced_rec_buff_length;
if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength, if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength,
MYF(0)))) MYF(0))))
{ {
...@@ -1810,7 +1808,6 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, ...@@ -1810,7 +1808,6 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
info->rec_cache.file=info->dfile; /* for sort_delete_record */ info->rec_cache.file=info->dfile; /* for sort_delete_record */
sort_param.rec_buff=info->rec_buff; sort_param.rec_buff=info->rec_buff;
sort_param.alloced_rec_buff_length=info->alloced_rec_buff_length;
if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength, if (!(sort_param.record=(byte*) my_malloc((uint) share->base.pack_reclength,
MYF(0)))) MYF(0))))
{ {
...@@ -2793,8 +2790,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param) ...@@ -2793,8 +2790,7 @@ static int sort_get_next_record(MI_SORT_PARAM *sort_param)
if (share->base.blobs) if (share->base.blobs)
{ {
if (!(to=mi_alloc_rec_buff(info,block_info.rec_len, if (!(to=mi_alloc_rec_buff(info,block_info.rec_len,
&(sort_param->rec_buff), &(sort_param->rec_buff))))
&(sort_param->alloced_rec_buff_length))))
{ {
mi_check_print_error(param,"Not enough memory for blob at %s", mi_check_print_error(param,"Not enough memory for blob at %s",
llstr(sort_param->start_recpos,llbuff)); llstr(sort_param->start_recpos,llbuff));
......
...@@ -1060,8 +1060,7 @@ int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, byte *buf) ...@@ -1060,8 +1060,7 @@ int _mi_read_dynamic_record(MI_INFO *info, my_off_t filepos, byte *buf)
if (info->s->base.blobs) if (info->s->base.blobs)
{ {
if (!(to=mi_alloc_rec_buff(info, block_info.rec_len, if (!(to=mi_alloc_rec_buff(info, block_info.rec_len,
&info->rec_buff, &info->rec_buff)))
&info->alloced_rec_buff_length)))
goto err; goto err;
} }
else else
...@@ -1107,12 +1106,8 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, ...@@ -1107,12 +1106,8 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
/* Don't let the compare destroy blobs that may be in use */ /* Don't let the compare destroy blobs that may be in use */
rec_buff=info->rec_buff; rec_buff=info->rec_buff;
alloced_rec_buff_length=info->alloced_rec_buff_length;
if (info->s->base.blobs) if (info->s->base.blobs)
{
info->rec_buff=0; info->rec_buff=0;
info->alloced_rec_buff_length=0;
}
error=_mi_read_dynamic_record(info,pos,old_record); error=_mi_read_dynamic_record(info,pos,old_record);
if (!error) if (!error)
error=mi_unique_comp(def, record, old_record, def->null_are_equal); error=mi_unique_comp(def, record, old_record, def->null_are_equal);
...@@ -1120,7 +1115,6 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, ...@@ -1120,7 +1115,6 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
{ {
my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR));
info->rec_buff=rec_buff; info->rec_buff=rec_buff;
info->alloced_rec_buff_length=alloced_rec_buff_length;
} }
my_afree(old_record); my_afree(old_record);
DBUG_RETURN(error); DBUG_RETURN(error);
...@@ -1331,8 +1325,7 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, byte *buf, ...@@ -1331,8 +1325,7 @@ int _mi_read_rnd_dynamic_record(MI_INFO *info, byte *buf,
if (share->base.blobs) if (share->base.blobs)
{ {
if (!(to= mi_alloc_rec_buff(info, block_info.rec_len, if (!(to= mi_alloc_rec_buff(info, block_info.rec_len,
&info->rec_buff, &info->rec_buff)))
&info->alloced_rec_buff_length)))
goto err; goto err;
} }
else else
......
...@@ -344,8 +344,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg) ...@@ -344,8 +344,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function, void *extra_arg)
} }
} }
if (share->base.blobs) if (share->base.blobs)
mi_alloc_rec_buff(info, -1, &info->rec_buff, mi_alloc_rec_buff(info, -1, &info->rec_buff);
&info->alloced_rec_buff_length);
break; break;
case HA_EXTRA_NORMAL: /* Theese isn't in use */ case HA_EXTRA_NORMAL: /* Theese isn't in use */
info->quick_mode=0; info->quick_mode=0;
......
...@@ -251,8 +251,7 @@ static int _mi_put_key_in_record(register MI_INFO *info, uint keynr, ...@@ -251,8 +251,7 @@ static int _mi_put_key_in_record(register MI_INFO *info, uint keynr,
{ {
if (!(blob_ptr= if (!(blob_ptr=
mi_alloc_rec_buff(info, info->s->keyinfo[keynr].keylength, mi_alloc_rec_buff(info, info->s->keyinfo[keynr].keylength,
&info->rec_buff, &info->rec_buff)))
&info->alloced_rec_buff_length)))
goto err; goto err;
} }
key=(byte*) info->lastkey; key=(byte*) info->lastkey;
......
...@@ -507,10 +507,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -507,10 +507,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
/* Allocate buffer for one record */ /* Allocate buffer for one record */
/* prerequisites: bzero(info) && info->s=share; are met. */ /* prerequisites: bzero(info) && info->s=share; are met. */
if (!mi_alloc_rec_buff(&info, -1, &info.rec_buff, if (!mi_alloc_rec_buff(&info, -1, &info.rec_buff))
&info.alloced_rec_buff_length))
goto err; goto err;
bzero(info.rec_buff, info.alloced_rec_buff_length); bzero(info.rec_buff, mi_get_rec_buff_len(&info, info.rec_buff));
*m_info=info; *m_info=info;
#ifdef THREAD #ifdef THREAD
...@@ -560,21 +559,11 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) ...@@ -560,21 +559,11 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags)
DBUG_RETURN (NULL); DBUG_RETURN (NULL);
} /* mi_open */ } /* mi_open */
byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf)
gptr mi_get_rec_buff_ptr(MI_INFO *info, byte *buf)
{
if (info->s->options & HA_OPTION_PACK_RECORD && buf)
return buf - MI_REC_BUFF_OFFSET;
else
return buf;
}
byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf, uint *buf_len)
{ {
uint extra; uint extra;
if (! *buf || length > *buf_len) if (! *buf || length > mi_get_rec_buff_len(info, *buf))
{ {
byte *newptr = *buf; byte *newptr = *buf;
...@@ -588,10 +577,10 @@ byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf, uint *buf_len) ...@@ -588,10 +577,10 @@ byte *mi_alloc_rec_buff(MI_INFO *info, ulong length, byte **buf, uint *buf_len)
if (extra && newptr) if (extra && newptr)
newptr-=MI_REC_BUFF_OFFSET; newptr-=MI_REC_BUFF_OFFSET;
if (!(newptr=(byte*) my_realloc((gptr)newptr, length+extra+8, if (!(newptr=(byte*) my_realloc((gptr)newptr, length+extra+8,
MYF(MY_ALLOW_ZERO_PTR)))) MYF(MY_ALLOW_ZERO_PTR))))
return 0; return newptr;
*((uint *)newptr)=length;
*buf= newptr+(extra ? MI_REC_BUFF_OFFSET : 0); *buf= newptr+(extra ? MI_REC_BUFF_OFFSET : 0);
*buf_len= length;
} }
return *buf; return *buf;
} }
......
...@@ -1058,8 +1058,7 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file, ...@@ -1058,8 +1058,7 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file,
head_length+=4; head_length+=4;
} }
if (!(mi_alloc_rec_buff(myisam,info->rec_len + info->blob_len, if (!(mi_alloc_rec_buff(myisam,info->rec_len + info->blob_len,
&myisam->rec_buff, &myisam->rec_buff)))
&myisam->alloced_rec_buff_length)))
return BLOCK_FATAL_ERROR; /* not enough memory */ return BLOCK_FATAL_ERROR; /* not enough memory */
myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff+info->rec_len; myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff+info->rec_len;
myisam->blob_length=info->blob_len; myisam->blob_length=info->blob_len;
...@@ -1235,8 +1234,7 @@ static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info, ...@@ -1235,8 +1234,7 @@ static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
} }
/* mi_alloc_rec_buff sets my_errno on error */ /* mi_alloc_rec_buff sets my_errno on error */
if (!(mi_alloc_rec_buff(myisam, info->blob_len, if (!(mi_alloc_rec_buff(myisam, info->blob_len,
&myisam->rec_buff, &myisam->rec_buff)))
&myisam->alloced_rec_buff_length)))
return 0; /* not enough memory */ return 0; /* not enough memory */
myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff; myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff;
} }
......
...@@ -247,7 +247,6 @@ struct st_myisam_info { ...@@ -247,7 +247,6 @@ struct st_myisam_info {
int dfile; /* The datafile */ int dfile; /* The datafile */
uint opt_flag; /* Optim. for space/speed */ uint opt_flag; /* Optim. for space/speed */
uint update; /* If file changed since open */ uint update; /* If file changed since open */
uint alloced_rec_buff_length; /* Max recordlength malloced */
uint int_nod_flag; /* -""- */ uint int_nod_flag; /* -""- */
int lastinx; /* Last used index */ int lastinx; /* Last used index */
uint lastkey_length; /* Length of key in lastkey */ uint lastkey_length; /* Length of key in lastkey */
...@@ -359,7 +358,7 @@ struct st_myisam_info { ...@@ -359,7 +358,7 @@ struct st_myisam_info {
#define MI_DYN_ALIGN_SIZE 4 /* Align blocks on this */ #define MI_DYN_ALIGN_SIZE 4 /* Align blocks on this */
#define MI_MAX_DYN_HEADER_BYTE 13 /* max header byte for dynamic rows */ #define MI_MAX_DYN_HEADER_BYTE 13 /* max header byte for dynamic rows */
#define MI_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1))) #define MI_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1)))
#define MI_REC_BUFF_OFFSET ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER) #define MI_REC_BUFF_OFFSET ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER+sizeof(uint))
#define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */ #define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */
...@@ -523,8 +522,14 @@ extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf); ...@@ -523,8 +522,14 @@ extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf);
extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos, extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos,
uint length,int re_read_if_possibly); uint length,int re_read_if_possibly);
extern void update_auto_increment(MI_INFO *info,const byte *record); extern void update_auto_increment(MI_INFO *info,const byte *record);
extern byte *mi_alloc_rec_buff(MI_INFO *,ulong, byte**, uint*);
extern gptr mi_get_rec_buff_ptr(MI_INFO *, byte *); extern byte *mi_alloc_rec_buff(MI_INFO *,ulong, byte**);
#define mi_get_rec_buff_ptr(info,buf) \
((((info)->s->options & HA_OPTION_PACK_RECORD) && (buf)) ? \
(buf) - MI_REC_BUFF_OFFSET : (buf))
#define mi_get_rec_buff_len(info,buf) \
(*((uint *)(mi_get_rec_buff_ptr(info,buf))))
extern ulong _mi_rec_unpack(MI_INFO *info,byte *to,byte *from, extern ulong _mi_rec_unpack(MI_INFO *info,byte *to,byte *from,
ulong reclength); ulong reclength);
extern my_bool _mi_rec_check(MI_INFO *info,const char *record, byte *packpos); extern my_bool _mi_rec_check(MI_INFO *info,const char *record, byte *packpos);
......
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