1 /* Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License, version 2.0,
5    as published by the Free Software Foundation.
6 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 /**
24   @file include/myisammrg.h
25   This file should be included when using merge isam functions.
26 */
27 
28 #ifndef _myisammrg_h
29 #define _myisammrg_h
30 
31 #include <sys/types.h>
32 
33 #include "my_base.h"
34 #include "my_inttypes.h"
35 #include "my_list.h"
36 #include "my_macros.h"
37 #include "myisam.h"
38 #include "mysql/psi/mysql_mutex.h"
39 #include "storage/myisam/queues.h"
40 #include "typelib.h"
41 
42 #define MYRG_NAME_EXT ".MRG"
43 
44 /* In which table to INSERT rows */
45 #define MERGE_INSERT_DISABLED 0
46 #define MERGE_INSERT_TO_FIRST 1
47 #define MERGE_INSERT_TO_LAST 2
48 
49 extern TYPELIB merge_insert_method;
50 
51 /* Param to/from myrg_info */
52 
53 struct MYMERGE_INFO /* Struct from h_info */
54 {
55   ulonglong records; /* Records in database */
56   ulonglong deleted; /* Deleted records in database */
57   ulonglong recpos;  /* Pos for last used record */
58   ulonglong data_file_length;
59   ulonglong dupp_key_pos; /* Offset of the Duplicate key in the merge table */
60   uint reclength;         /* Recordlength */
61   int errkey;             /* With key was dupplicated on err */
62   uint options;           /* HA_OPTION_... used */
63   ulong *rec_per_key;     /* for sql optimizing */
64 };
65 
66 struct MYRG_TABLE {
67   MI_INFO *table;
68   ulonglong file_offset;
69 };
70 
71 struct MYRG_INFO {
72   MYRG_TABLE *open_tables, *current_table, *end_table, *last_used_table;
73   ulonglong records; /* records in tables */
74   ulonglong del;     /* Removed records */
75   ulonglong data_file_length;
76   ulong cache_size;
77   uint merge_insert_method;
78   uint tables, options, reclength, keys;
79   /* If MERGE children attached to parent. See top comment in ha_myisammrg.cc */
80   bool children_attached;
81   LIST open_list;
82   QUEUE by_key;
83   ulong *rec_per_key_part; /* for sql optimizing */
84   mysql_mutex_t mutex;
85 };
86 
87 /* Prototypes for merge-functions */
88 
89 extern int myrg_close(MYRG_INFO *file);
90 extern int myrg_delete(MYRG_INFO *file, const uchar *buff);
91 extern MYRG_INFO *myrg_open(const char *name, int mode, int wait_if_locked);
92 extern MYRG_INFO *myrg_parent_open(const char *parent_name,
93                                    int (*callback)(void *, const char *),
94                                    void *callback_param);
95 extern int myrg_attach_children(MYRG_INFO *m_info, int handle_locking,
96                                 MI_INFO *(*callback)(void *),
97                                 void *callback_param, bool *need_compat_check);
98 extern int myrg_detach_children(MYRG_INFO *m_info);
99 extern int myrg_panic(enum ha_panic_function function);
100 extern int myrg_rfirst(MYRG_INFO *file, uchar *buf, int inx);
101 extern int myrg_rlast(MYRG_INFO *file, uchar *buf, int inx);
102 extern int myrg_rnext(MYRG_INFO *file, uchar *buf, int inx);
103 extern int myrg_rprev(MYRG_INFO *file, uchar *buf, int inx);
104 extern int myrg_rnext_same(MYRG_INFO *file, uchar *buf);
105 extern int myrg_rkey(MYRG_INFO *info, uchar *buf, int inx, const uchar *key,
106                      key_part_map keypart_map,
107                      enum ha_rkey_function search_flag);
108 extern int myrg_rrnd(MYRG_INFO *file, uchar *buf, ulonglong pos);
109 extern int myrg_update(MYRG_INFO *file, const uchar *old, uchar *new_rec);
110 extern int myrg_write(MYRG_INFO *info, uchar *rec);
111 extern int myrg_status(MYRG_INFO *file, MYMERGE_INFO *x, int flag);
112 extern int myrg_lock_database(MYRG_INFO *file, int lock_type);
113 extern int myrg_create(const char *name, const char **table_names,
114                        uint insert_method, bool fix_names);
115 extern int myrg_extra(MYRG_INFO *file, enum ha_extra_function function,
116                       void *extra_arg);
117 extern int myrg_reset(MYRG_INFO *info);
118 extern ha_rows myrg_records_in_range(MYRG_INFO *info, int inx,
119                                      key_range *min_key, key_range *max_key);
120 extern ha_rows myrg_records(MYRG_INFO *info);
121 
122 extern ulonglong myrg_position(MYRG_INFO *info);
123 
124 #endif /* _myisammrg_h */
125