1/* Copyright (c) 2000, 2001, 2005, 2006 MySQL AB, 2009 Sun Microsystems, Inc.
2 Use is subject to license terms.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; version 2 of the License.
7
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.
12
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17#include "myrg_def.h"
18
19ulonglong myrg_position(MYRG_INFO *info)
20{
21 MYRG_TABLE *current_table;
22
23 if (!(current_table = info->current_table) &&
24 info->open_tables != info->end_table)
25 current_table = info->open_tables;
26 return current_table ?
27 current_table->table->lastpos + current_table->file_offset :
28 ~(ulonglong) 0;
29}
30
31int myrg_status(MYRG_INFO *info,register MYMERGE_INFO *x,int flag)
32{
33 MYRG_TABLE *current_table;
34 DBUG_ENTER("myrg_status");
35
36 if (!(current_table = info->current_table) &&
37 info->open_tables != info->end_table)
38 current_table = info->open_tables;
39 x->recpos = info->current_table ?
40 info->current_table->table->lastpos + info->current_table->file_offset :
41 (ulong) -1L;
42 if (flag != HA_STATUS_POS)
43 {
44 MYRG_TABLE *file;
45
46 info->records=info->del=info->data_file_length=0;
47 for (file=info->open_tables ; file != info->end_table ; file++)
48 {
49 file->file_offset=info->data_file_length;
50 info->data_file_length+=file->table->s->state.state.data_file_length;
51 info->records+=file->table->s->state.state.records;
52 info->del+=file->table->s->state.state.del;
53 DBUG_PRINT("info2",("table: %s, offset: %lu",
54 file->table->filename,(ulong) file->file_offset));
55 }
56 x->records= info->records;
57 x->deleted= info->del;
58 x->data_file_length= info->data_file_length;
59 x->reclength= info->reclength;
60 x->options= info->options;
61 if (current_table)
62 {
63 /*
64 errkey is set to the index number of the myisam tables. But
65 since the MERGE table can have less keys than the MyISAM
66 tables, errkey cannot be be used as an index into the key_info
67 on the server. This value will be overwritten with MAX_KEY by
68 the MERGE engine.
69 */
70 x->errkey= current_table->table->errkey;
71 /*
72 Calculate the position of the duplicate key to be the sum of the
73 offset of the myisam file and the offset into the file at which
74 the duplicate key is located.
75 */
76 x->dupp_key_pos= current_table->file_offset + current_table->table->dupp_key_pos;
77 }
78 else
79 {
80 x->errkey= 0;
81 x->dupp_key_pos= 0;
82 }
83 x->rec_per_key = info->rec_per_key_part;
84 }
85 DBUG_RETURN(0);
86}
87