1/* Copyright (c) 2000-2002, 2004, 2006-2008 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/* This file should be included when using merge_isam_funktions */
18
19#ifndef _myisammrg_h
20#define _myisammrg_h
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#ifndef _my_base_h
26#include <my_base.h>
27#endif
28#ifndef _myisam_h
29#include <myisam.h>
30#endif
31
32#include <queues.h>
33
34#define MYRG_NAME_EXT ".MRG"
35#define MYRG_NAME_TMPEXT ".MRG_TMP"
36
37/* In which table to INSERT rows */
38#define MERGE_INSERT_DISABLED 0
39#define MERGE_INSERT_TO_FIRST 1
40#define MERGE_INSERT_TO_LAST 2
41
42extern TYPELIB merge_insert_method;
43
44 /* Param to/from myrg_info */
45
46typedef struct st_mymerge_info /* Struct from h_info */
47{
48 ulonglong records; /* Records in database */
49 ulonglong deleted; /* Deleted records in database */
50 ulonglong recpos; /* Pos for last used record */
51 ulonglong data_file_length;
52 ulonglong dupp_key_pos; /* Offset of the Duplicate key in the merge table */
53 uint reclength; /* Recordlength */
54 int errkey; /* With key was dupplicated on err */
55 uint options; /* HA_OPTION_... used */
56 ulong *rec_per_key; /* for sql optimizing */
57} MYMERGE_INFO;
58
59typedef struct st_myrg_table_info
60{
61 struct st_myisam_info *table;
62 ulonglong file_offset;
63} MYRG_TABLE;
64
65typedef struct st_myrg_info
66{
67 MYRG_TABLE *open_tables,*current_table,*end_table,*last_used_table;
68 ulonglong records; /* records in tables */
69 ulonglong del; /* Removed records */
70 ulonglong data_file_length;
71 ulong cache_size;
72 uint merge_insert_method;
73 uint tables,options,reclength,keys;
74 my_bool cache_in_use;
75 /* If MERGE children attached to parent. See top comment in ha_myisammrg.cc */
76 my_bool children_attached;
77 LIST open_list;
78 QUEUE by_key;
79 ulong *rec_per_key_part; /* for sql optimizing */
80 mysql_mutex_t mutex;
81} MYRG_INFO;
82
83
84 /* Prototypes for merge-functions */
85
86extern int myrg_close(MYRG_INFO *file);
87extern int myrg_delete(MYRG_INFO *file,const uchar *buff);
88extern MYRG_INFO *myrg_open(const char *name,int mode,int wait_if_locked);
89extern MYRG_INFO *myrg_parent_open(const char *parent_name,
90 int (*callback)(void*, const char*),
91 void *callback_param);
92extern int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
93 MI_INFO *(*callback)(void*),
94 void *callback_param,
95 my_bool *need_compat_check);
96extern int myrg_detach_children(MYRG_INFO *m_info);
97extern int myrg_panic(enum ha_panic_function function);
98extern int myrg_rfirst(MYRG_INFO *file,uchar *buf,int inx);
99extern int myrg_rlast(MYRG_INFO *file,uchar *buf,int inx);
100extern int myrg_rnext(MYRG_INFO *file,uchar *buf,int inx);
101extern int myrg_rprev(MYRG_INFO *file,uchar *buf,int inx);
102extern int myrg_rnext_same(MYRG_INFO *file,uchar *buf);
103extern int myrg_rkey(MYRG_INFO *info,uchar *buf,int inx, const uchar *key,
104 key_part_map keypart_map, enum ha_rkey_function search_flag);
105extern int myrg_rrnd(MYRG_INFO *file,uchar *buf,ulonglong pos);
106extern int myrg_rsame(MYRG_INFO *file,uchar *record,int inx);
107extern int myrg_update(MYRG_INFO *file,const uchar *old,
108 const uchar *new_rec);
109extern int myrg_write(MYRG_INFO *info,uchar *rec);
110extern int myrg_status(MYRG_INFO *file,MYMERGE_INFO *x,int flag);
111extern int myrg_lock_database(MYRG_INFO *file,int lock_type);
112extern int myrg_create(const char *name, const char **table_names,
113 uint insert_method, my_bool fix_names);
114extern int myrg_extra(MYRG_INFO *file,enum ha_extra_function function,
115 void *extra_arg);
116extern int myrg_reset(MYRG_INFO *info);
117extern void myrg_extrafunc(MYRG_INFO *info,invalidator_by_filename inv);
118extern ha_rows myrg_records_in_range(MYRG_INFO *info, int inx,
119 key_range *min_key, key_range *max_key);
120extern ha_rows myrg_records(MYRG_INFO *info);
121
122extern ulonglong myrg_position(MYRG_INFO *info);
123#ifdef __cplusplus
124}
125#endif
126#endif
127