diff options
author | unknown <serg@sergbook.mysql.com> | 2002-07-14 13:51:03 +0200 |
---|---|---|
committer | unknown <serg@sergbook.mysql.com> | 2002-07-14 13:51:03 +0200 |
commit | d8093cf6ff17e146e33e91ba16f46992859a5cc9 (patch) | |
tree | 2226fafc5c59c90673606fdbec9b7fb6bad5fab8 | |
parent | 9a1ff13ea4a494d90b505b6d6e7b288d7390b5d0 (diff) | |
download | mariadb-git-d8093cf6ff17e146e33e91ba16f46992859a5cc9.tar.gz |
yet another generalization for rec_buff handling, MI_INFO doesn't need rec_alloc anymore
myisam/mi_close.c:
yet another generalization for rec_buff handling
myisam/mi_dynrec.c:
yet another generalization for rec_buff handling
myisam/mi_extra.c:
yet another generalization for rec_buff handling
myisam/mi_open.c:
yet another generalization for rec_buff handling
myisam/myisamdef.h:
yet another generalization for rec_buff handling
-rw-r--r-- | myisam/mi_close.c | 2 | ||||
-rw-r--r-- | myisam/mi_dynrec.c | 38 | ||||
-rw-r--r-- | myisam/mi_extra.c | 6 | ||||
-rw-r--r-- | myisam/mi_open.c | 37 | ||||
-rw-r--r-- | myisam/myisamdef.h | 14 |
5 files changed, 50 insertions, 47 deletions
diff --git a/myisam/mi_close.c b/myisam/mi_close.c index 7197d0ba069..5250acf1375 100644 --- a/myisam/mi_close.c +++ b/myisam/mi_close.c @@ -101,7 +101,7 @@ int mi_close(register MI_INFO *info) error = my_errno; myisam_log_command(MI_LOG_CLOSE,info,NULL,0,error); - my_free((gptr) info->rec_alloc,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mi_get_rec_buff_ptr(info, info->rec_buff), MYF(MY_ALLOW_ZERO_PTR)); my_free((gptr) info,MYF(0)); if (error) diff --git a/myisam/mi_dynrec.c b/myisam/mi_dynrec.c index 180a5a65a3d..cdff9d1339b 100644 --- a/myisam/mi_dynrec.c +++ b/myisam/mi_dynrec.c @@ -724,8 +724,8 @@ uint _mi_rec_pack(MI_INFO *info, register byte *to, register const byte *from) /* -** Check if a record was correctly packed. Used only by isamchk -** Returns 0 if record is ok. + Check if a record was correctly packed. Used only by myisamchk + Returns 0 if record is ok. */ my_bool _mi_rec_check(MI_INFO *info,const char *record) @@ -1090,39 +1090,12 @@ err: DBUG_RETURN(-1); } - -byte *mi_fix_rec_buff_for_blob(MI_INFO *info, ulong length) -{ - uint extra; - - /* to simplify initial init of info->rec_buf in mi_open and mi_extra */ - if (!length) - length=max(info->s->base.pack_reclength,info->s->base.max_key_length); - - if (! info->rec_buff || length > info->alloced_rec_buff_length) - { - byte *newptr; - extra= ((info->s->options & HA_OPTION_PACK_RECORD) ? - ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+ - MI_DYN_DELETE_BLOCK_HEADER : 0); - if (!(newptr=(byte*) my_realloc((gptr) info->rec_alloc,length+extra+8, - MYF(MY_ALLOW_ZERO_PTR)))) - return (byte *)0; - info->rec_alloc=newptr; - info->rec_buff=newptr+(extra ? - ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER) : 0); - info->alloced_rec_buff_length=length; - } - return info->rec_buff; -} - - /* compare unique constraint between stored rows */ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, const byte *record, my_off_t pos) { - byte *rec_buff,*rec_alloc,*old_record; + byte *rec_buff,*old_record; uint alloced_rec_buff_length; int error; DBUG_ENTER("_mi_cmp_dynamic_unique"); @@ -1132,12 +1105,10 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, /* Don't let the compare destroy blobs that may be in use */ rec_buff=info->rec_buff; - rec_alloc=info->rec_alloc; alloced_rec_buff_length=info->alloced_rec_buff_length; if (info->s->base.blobs) { info->rec_buff=0; - info->rec_alloc=0; info->alloced_rec_buff_length=0; } error=_mi_read_dynamic_record(info,pos,old_record); @@ -1145,9 +1116,8 @@ int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, error=mi_unique_comp(def, record, old_record, def->null_are_equal); if (info->s->base.blobs) { - my_free(info->rec_alloc,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_alloc=rec_alloc; info->alloced_rec_buff_length=alloced_rec_buff_length; } my_afree(old_record); diff --git a/myisam/mi_extra.c b/myisam/mi_extra.c index a1fe68f7087..9e514a6c055 100644 --- a/myisam/mi_extra.c +++ b/myisam/mi_extra.c @@ -328,11 +328,7 @@ int mi_extra(MI_INFO *info, enum ha_extra_function function) } } if (share->base.blobs) - { - my_free(info->rec_alloc,MYF(MY_ALLOW_ZERO_PTR)); - info->rec_alloc=info->rec_buff=0; - mi_fix_rec_buff_for_blob(info, 0); - } + mi_fix_rec_buff_for_blob(info, -1); break; case HA_EXTRA_NORMAL: /* Theese isn't in use */ info->quick_mode=0; diff --git a/myisam/mi_open.c b/myisam/mi_open.c index c417186de6a..c9ecdaab47f 100644 --- a/myisam/mi_open.c +++ b/myisam/mi_open.c @@ -507,9 +507,9 @@ MI_INFO *mi_open(const char *name, int mode, uint open_flags) /* Allocate buffer for one record */ /* prerequisites: bzero(info) && info->s=share; are met. */ - if (!mi_fix_rec_buff_for_blob(&info, 0)) + if (!mi_fix_rec_buff_for_blob(&info, -1)) goto err; - bzero(info.rec_alloc, info.alloced_rec_buff_length); + bzero(info.rec_buff, info.alloced_rec_buff_length); *m_info=info; #ifdef THREAD @@ -559,6 +559,39 @@ err: DBUG_RETURN (NULL); } /* mi_open */ +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; + + if (! *buf || length > *buf_len) + { + byte *newptr = *buf; + + /* to simplify initial init of info->rec_buf in mi_open and mi_extra */ + if (length == (ulong)-1) + length=max(info->s->base.pack_reclength,info->s->base.max_key_length); + + extra= ((info->s->options & HA_OPTION_PACK_RECORD) ? + ALIGN_SIZE(MI_MAX_DYN_BLOCK_HEADER)+MI_SPLIT_LENGTH+ + MI_REC_BUFF_OFFSET : 0); + if (extra && newptr) + newptr-=MI_REC_BUFF_OFFSET; + if (!(newptr=(byte*) my_realloc((gptr)newptr, length+extra+8, + MYF(MY_ALLOW_ZERO_PTR)))) + return 0; + *buf=newptr+(extra ? MI_REC_BUFF_OFFSET : 0); + *buf_len=length; + } + return *buf; +} ulonglong mi_safe_mul(ulonglong a, ulonglong b) { diff --git a/myisam/myisamdef.h b/myisam/myisamdef.h index cef864e6efb..72bffab78c2 100644 --- a/myisam/myisamdef.h +++ b/myisam/myisamdef.h @@ -222,12 +222,11 @@ struct st_myisam_info { MI_BLOB *blobs; /* Pointer to blobs */ MI_BIT_BUFF bit_buff; /* accumulate indexfile changes between write's */ - TREE *bulk_insert; + TREE *bulk_insert; char *filename; /* parameter to open filename */ uchar *buff, /* Temp area for key */ *lastkey,*lastkey2; /* Last used search key */ - byte *rec_buff, /* Tempbuff for recordpack */ - *rec_alloc; /* Malloced area for record */ + byte *rec_buff; /* Tempbuff for recordpack */ uchar *int_keypos, /* Save position for next/previous */ *int_maxpos; /* -""- */ int (*read_record)(struct st_myisam_info*, my_off_t, byte*); @@ -249,7 +248,7 @@ struct st_myisam_info { uint opt_flag; /* Optim. for space/speed */ 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 */ uint lastkey_length; /* Length of key in lastkey */ uint last_rkey_length; /* Last length in mi_rkey() */ @@ -360,6 +359,7 @@ struct st_myisam_info { #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_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 MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */ @@ -523,7 +523,11 @@ 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, uint length,int re_read_if_possibly); extern void update_auto_increment(MI_INFO *info,const byte *record); -extern byte *mi_fix_rec_buff_for_blob(MI_INFO *info,ulong blob_length); +extern byte *mi_alloc_rec_buff(MI_INFO *,ulong, byte**, uint*); +extern gptr mi_get_rec_buff_ptr(MI_INFO *, byte *); +#define mi_fix_rec_buff_for_blob(INFO,LENGTH) \ + mi_alloc_rec_buff((INFO),(LENGTH), \ + &((INFO)->rec_buff), &((INFO)->alloced_rec_buff_length)) extern ulong _mi_rec_unpack(MI_INFO *info,byte *to,byte *from, ulong reclength); extern my_bool _mi_rec_check(MI_INFO *info,const char *from); |