1
/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2 of the License, or
6
(at your option) any later version.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License
14
along with this program; if not, write to the Free Software
15
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
Read a record with random-access. The position to the record must
19
get by mrg_info(). The next record can be read with pos= -1 */
24
static MRG_TABLE *find_table(MRG_TABLE *start,MRG_TABLE *end,mrg_off_t pos);
27
If filepos == -1, read next
28
Returns same as nisam_rrnd:
31
-1 = EOF (or something, errno should be HA_ERR_END_OF_FILE)
34
int mrg_rrnd(MRG_INFO *info,byte *buf,mrg_off_t filepos)
39
if (filepos == ~(mrg_off_t) 0) /* Can't use HA_POS_ERROR */
41
if (!info->current_table)
43
if (info->open_tables == info->end_table)
45
my_errno=HA_ERR_END_OF_FILE;
48
isam_info=(info->current_table=info->open_tables)->table;
49
if (info->cache_in_use)
50
nisam_extra(isam_info,HA_EXTRA_CACHE);
51
filepos=isam_info->s->pack.header_length;
52
isam_info->lastinx= (uint) -1; /* Can't forward or backward */
56
isam_info=info->current_table->table;
57
filepos= isam_info->nextpos;
62
isam_info->update&= HA_STATE_CHANGED;
63
if ((error=(*isam_info->s->read_rnd)(isam_info,(byte*) buf,
65
my_errno != HA_ERR_END_OF_FILE)
67
if (info->cache_in_use)
68
nisam_extra(info->current_table->table,HA_EXTRA_NO_CACHE);
69
if (info->current_table+1 == info->end_table)
71
info->current_table++;
72
info->last_used_table=info->current_table;
73
if (info->cache_in_use)
74
nisam_extra(info->current_table->table,HA_EXTRA_CACHE);
75
info->current_table->file_offset=
76
info->current_table[-1].file_offset+
77
info->current_table[-1].table->s->state.data_file_length;
79
isam_info=info->current_table->table;
80
filepos=isam_info->s->pack.header_length;
81
isam_info->lastinx= (uint) -1;
84
info->current_table=find_table(info->open_tables,
85
info->last_used_table,filepos);
86
isam_info=info->current_table->table;
87
isam_info->update&= HA_STATE_CHANGED;
88
return ((*isam_info->s->read_rnd)(isam_info,(byte*) buf,
90
info->current_table->file_offset),
95
/* Find which table to use according to file-pos */
97
static MRG_TABLE *find_table(MRG_TABLE *start,MRG_TABLE *end,mrg_off_t pos)
103
mid=start+((uint) (end-start)+1)/2;
104
if (mid->file_offset > pos)