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 myrg_info(). The next record can be read with pos= -1 */
24
static MYRG_TABLE *find_table(MYRG_TABLE *start,MYRG_TABLE *end,ulonglong pos);
27
If filepos == HA_OFFSET_ERROR, read next
28
Returns same as mi_rrnd:
30
HA_ERR_RECORD_DELETED = Record is deleted.
31
HA_ERR_END_OF_FILE = EOF.
34
int myrg_rrnd(MYRG_INFO *info,byte *buf,ulonglong filepos)
38
DBUG_ENTER("myrg_rrnd");
39
DBUG_PRINT("info",("offset: %lu", (ulong) filepos));
41
if (filepos == HA_OFFSET_ERROR)
43
if (!info->current_table)
45
if (info->open_tables == info->end_table)
47
DBUG_RETURN(my_errno=HA_ERR_END_OF_FILE);
49
isam_info=(info->current_table=info->open_tables)->table;
50
if (info->cache_in_use)
51
mi_extra(isam_info,HA_EXTRA_CACHE,(byte*) &info->cache_size);
52
filepos=isam_info->s->pack.header_length;
53
isam_info->lastinx= (uint) -1; /* Can't forward or backward */
57
isam_info=info->current_table->table;
58
filepos= isam_info->nextpos;
63
isam_info->update&= HA_STATE_CHANGED;
64
if ((error=(*isam_info->s->read_rnd)(isam_info,(byte*) buf,
65
(my_off_t) filepos,1)) !=
68
if (info->cache_in_use)
69
mi_extra(info->current_table->table, HA_EXTRA_NO_CACHE,
70
(byte*) &info->cache_size);
71
if (info->current_table+1 == info->end_table)
72
DBUG_RETURN(HA_ERR_END_OF_FILE);
73
info->current_table++;
74
info->last_used_table=info->current_table;
75
if (info->cache_in_use)
76
mi_extra(info->current_table->table, HA_EXTRA_CACHE,
77
(byte*) &info->cache_size);
78
info->current_table->file_offset=
79
info->current_table[-1].file_offset+
80
info->current_table[-1].table->state->data_file_length;
82
isam_info=info->current_table->table;
83
filepos=isam_info->s->pack.header_length;
84
isam_info->lastinx= (uint) -1;
87
info->current_table=find_table(info->open_tables,
88
info->end_table-1,filepos);
89
isam_info=info->current_table->table;
90
isam_info->update&= HA_STATE_CHANGED;
91
DBUG_RETURN((*isam_info->s->read_rnd)
92
(isam_info, (byte*) buf,
93
(my_off_t) (filepos - info->current_table->file_offset),
98
/* Find which table to use according to file-pos */
100
static MYRG_TABLE *find_table(MYRG_TABLE *start, MYRG_TABLE *end,
104
DBUG_ENTER("find_table");
108
mid=start+((uint) (end-start)+1)/2;
109
if (mid->file_offset > pos)
114
DBUG_PRINT("info",("offset: %lu, table: %s",
115
(ulong) pos, start->table->filename));