summaryrefslogtreecommitdiff
path: root/myisam/mi_packrec.c
diff options
context:
space:
mode:
authorunknown <istruewing@chilla.local>2006-10-09 20:03:12 +0200
committerunknown <istruewing@chilla.local>2006-10-09 20:03:12 +0200
commit91be4f6f0c0771bc18f46dfd63e01b116ec7cf62 (patch)
treeddc4b70cec5efe547e1b808aa7e197604f09e845 /myisam/mi_packrec.c
parent9397becc6d9c5af98ba1fd89a699b389d83a91c3 (diff)
parent679b5848f3af7e1833385ef20d099dfde277b8c0 (diff)
downloadmariadb-git-91be4f6f0c0771bc18f46dfd63e01b116ec7cf62.tar.gz
Merge chilla.local:/home/mydev/mysql-4.1-bug8283-one
into chilla.local:/home/mydev/mysql-5.0-bug8283 include/my_sys.h: Auto merged include/myisam.h: Auto merged myisam/mi_check.c: Auto merged myisam/mi_open.c: Auto merged myisam/mi_packrec.c: Auto merged myisam/sort.c: Auto merged mysql-test/t/myisam.test: Auto merged myisam/myisamdef.h: Bug#8283 - OPTIMIZE TABLE causes data loss Merge from 4.1 mysql-test/r/myisam.result: Bug#8283 - OPTIMIZE TABLE causes data loss Merge from 4.1 mysys/mf_iocache.c: Bug#8283 - OPTIMIZE TABLE causes data loss Merge from 4.1
Diffstat (limited to 'myisam/mi_packrec.c')
-rw-r--r--myisam/mi_packrec.c76
1 files changed, 44 insertions, 32 deletions
diff --git a/myisam/mi_packrec.c b/myisam/mi_packrec.c
index c9653eadc28..13898df0466 100644
--- a/myisam/mi_packrec.c
+++ b/myisam/mi_packrec.c
@@ -103,7 +103,8 @@ static uint fill_and_get_bits(MI_BIT_BUFF *bit_buff,uint count);
static void fill_buffer(MI_BIT_BUFF *bit_buff);
static uint max_bit(uint value);
#ifdef HAVE_MMAP
-static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
+static uchar *_mi_mempack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
uchar *header);
#endif
@@ -449,13 +450,15 @@ int _mi_read_pack_record(MI_INFO *info, my_off_t filepos, byte *buf)
DBUG_RETURN(-1); /* _search() didn't find record */
file=info->dfile;
- if (_mi_pack_get_block_info(info, &block_info, file, filepos))
+ if (_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, file, filepos))
goto err;
if (my_read(file,(byte*) info->rec_buff + block_info.offset ,
block_info.rec_len - block_info.offset, MYF(MY_NABP)))
goto panic;
info->update|= HA_STATE_AKTIV;
- DBUG_RETURN(_mi_pack_rec_unpack(info,buf,info->rec_buff,block_info.rec_len));
+ DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ info->rec_buff, block_info.rec_len));
panic:
my_errno=HA_ERR_WRONG_IN_RECORD;
err:
@@ -464,8 +467,8 @@ err:
-int _mi_pack_rec_unpack(register MI_INFO *info, register byte *to, byte *from,
- ulong reclength)
+int _mi_pack_rec_unpack(register MI_INFO *info, MI_BIT_BUFF *bit_buff,
+ register byte *to, byte *from, ulong reclength)
{
byte *end_field;
reg3 MI_COLUMNDEF *end;
@@ -473,18 +476,18 @@ int _mi_pack_rec_unpack(register MI_INFO *info, register byte *to, byte *from,
MYISAM_SHARE *share=info->s;
DBUG_ENTER("_mi_pack_rec_unpack");
- init_bit_buffer(&info->bit_buff, (uchar*) from,reclength);
+ init_bit_buffer(bit_buff, (uchar*) from, reclength);
for (current_field=share->rec, end=current_field+share->base.fields ;
current_field < end ;
current_field++,to=end_field)
{
end_field=to+current_field->length;
- (*current_field->unpack)(current_field,&info->bit_buff,(uchar*) to,
+ (*current_field->unpack)(current_field, bit_buff, (uchar*) to,
(uchar*) end_field);
}
- if (! info->bit_buff.error &&
- info->bit_buff.pos - info->bit_buff.bits/8 == info->bit_buff.end)
+ if (!bit_buff->error &&
+ bit_buff->pos - bit_buff->bits / 8 == bit_buff->end)
DBUG_RETURN(0);
info->update&= ~HA_STATE_AKTIV;
DBUG_RETURN(my_errno=HA_ERR_WRONG_IN_RECORD);
@@ -1015,13 +1018,16 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
if (info->opt_flag & READ_CACHE_USED)
{
- if (_mi_read_cache(&info->rec_cache,(byte*) block_info.header,filepos,
- share->pack.ref_length, skip_deleted_blocks))
+ if (_mi_read_cache(&info->rec_cache, (byte*) block_info.header,
+ filepos, share->pack.ref_length,
+ skip_deleted_blocks ? READING_NEXT : 0))
goto err;
- b_type=_mi_pack_get_block_info(info,&block_info,-1, filepos);
+ b_type=_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, -1, filepos);
}
else
- b_type=_mi_pack_get_block_info(info,&block_info,info->dfile,filepos);
+ b_type=_mi_pack_get_block_info(info, &info->bit_buff, &block_info,
+ &info->rec_buff, info->dfile, filepos);
if (b_type)
goto err; /* Error code is already set */
#ifndef DBUG_OFF
@@ -1034,9 +1040,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
if (info->opt_flag & READ_CACHE_USED)
{
- if (_mi_read_cache(&info->rec_cache,(byte*) info->rec_buff,
- block_info.filepos, block_info.rec_len,
- skip_deleted_blocks))
+ if (_mi_read_cache(&info->rec_cache, (byte*) info->rec_buff,
+ block_info.filepos, block_info.rec_len,
+ skip_deleted_blocks ? READING_NEXT : 0))
goto err;
}
else
@@ -1051,8 +1057,8 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
info->nextpos=block_info.filepos+block_info.rec_len;
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
- DBUG_RETURN (_mi_pack_rec_unpack(info,buf,info->rec_buff,
- block_info.rec_len));
+ DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ info->rec_buff, block_info.rec_len));
err:
DBUG_RETURN(my_errno);
}
@@ -1060,8 +1066,9 @@ int _mi_read_rnd_pack_record(MI_INFO *info, byte *buf,
/* Read and process header from a huff-record-file */
-uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file,
- my_off_t filepos)
+uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
+ File file, my_off_t filepos)
{
uchar *header=info->header;
uint head_length,ref_length;
@@ -1086,17 +1093,17 @@ uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BLOCK_INFO *info, File file,
head_length+= read_pack_length((uint) myisam->s->pack.version,
header + head_length, &info->blob_len);
if (!(mi_alloc_rec_buff(myisam,info->rec_len + info->blob_len,
- &myisam->rec_buff)))
+ rec_buff_p)))
return BLOCK_FATAL_ERROR; /* not enough memory */
- myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff+info->rec_len;
- myisam->bit_buff.blob_end= myisam->bit_buff.blob_pos+info->blob_len;
+ bit_buff->blob_pos= (uchar*) *rec_buff_p + info->rec_len;
+ bit_buff->blob_end= bit_buff->blob_pos + info->blob_len;
myisam->blob_length=info->blob_len;
}
info->filepos=filepos+head_length;
if (file > 0)
{
info->offset=min(info->rec_len, ref_length - head_length);
- memcpy(myisam->rec_buff, header+head_length, info->offset);
+ memcpy(*rec_buff_p, header + head_length, info->offset);
}
return 0;
}
@@ -1237,7 +1244,8 @@ void _mi_unmap_file(MI_INFO *info)
}
-static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
+static uchar *_mi_mempack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
+ MI_BLOCK_INFO *info, byte **rec_buff_p,
uchar *header)
{
header+= read_pack_length((uint) myisam->s->pack.version, header,
@@ -1248,10 +1256,10 @@ static uchar *_mi_mempack_get_block_info(MI_INFO *myisam,MI_BLOCK_INFO *info,
&info->blob_len);
/* mi_alloc_rec_buff sets my_errno on error */
if (!(mi_alloc_rec_buff(myisam, info->blob_len,
- &myisam->rec_buff)))
+ rec_buff_p)))
return 0; /* not enough memory */
- myisam->bit_buff.blob_pos=(uchar*) myisam->rec_buff;
- myisam->bit_buff.blob_end= (uchar*) myisam->rec_buff + info->blob_len;
+ bit_buff->blob_pos= (uchar*) *rec_buff_p;
+ bit_buff->blob_end= (uchar*) *rec_buff_p + info->blob_len;
}
return header;
}
@@ -1267,11 +1275,13 @@ static int _mi_read_mempack_record(MI_INFO *info, my_off_t filepos, byte *buf)
if (filepos == HA_OFFSET_ERROR)
DBUG_RETURN(-1); /* _search() didn't find record */
- if (!(pos= (byte*) _mi_mempack_get_block_info(info,&block_info,
+ if (!(pos= (byte*) _mi_mempack_get_block_info(info, &info->bit_buff,
+ &block_info, &info->rec_buff,
(uchar*) share->file_map+
filepos)))
DBUG_RETURN(-1);
- DBUG_RETURN(_mi_pack_rec_unpack(info, buf, pos, block_info.rec_len));
+ DBUG_RETURN(_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ pos, block_info.rec_len));
}
@@ -1291,7 +1301,8 @@ static int _mi_read_rnd_mempack_record(MI_INFO *info, byte *buf,
my_errno=HA_ERR_END_OF_FILE;
goto err;
}
- if (!(pos= (byte*) _mi_mempack_get_block_info(info,&block_info,
+ if (!(pos= (byte*) _mi_mempack_get_block_info(info, &info->bit_buff,
+ &block_info, &info->rec_buff,
(uchar*)
(start=share->file_map+
filepos))))
@@ -1308,7 +1319,8 @@ static int _mi_read_rnd_mempack_record(MI_INFO *info, byte *buf,
info->nextpos=filepos+(uint) (pos-start)+block_info.rec_len;
info->update|= HA_STATE_AKTIV | HA_STATE_KEY_CHANGED;
- DBUG_RETURN (_mi_pack_rec_unpack(info,buf,pos, block_info.rec_len));
+ DBUG_RETURN (_mi_pack_rec_unpack(info, &info->bit_buff, buf,
+ pos, block_info.rec_len));
err:
DBUG_RETURN(my_errno);
}