1/* -*- c-basic-offset: 2 -*- */
2/*
3 Copyright(C) 2011-2013 Kentoku SHIBA
4 Copyright(C) 2011-2015 Kouhei Sutou <kou@clear-code.com>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19*/
20
21#ifndef MRN_TABLE_HPP_
22#define MRN_TABLE_HPP_
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#include <groonga.h>
29
30typedef struct st_mroonga_long_term_share
31{
32 char *table_name;
33 uint table_name_length;
34
35 // for auto_increment (storage mode only)
36 mysql_mutex_t auto_inc_mutex;
37 bool auto_inc_inited;
38 ulonglong auto_inc_value;
39} MRN_LONG_TERM_SHARE;
40
41typedef struct st_mroonga_share
42{
43 char *table_name;
44 uint table_name_length;
45 uint use_count;
46 mysql_mutex_t record_mutex;
47 THR_LOCK lock;
48 TABLE_SHARE *table_share;
49 TABLE_SHARE *wrap_table_share;
50 MRN_LONG_TERM_SHARE *long_term_share;
51
52 char *engine;
53 int engine_length;
54 char *default_tokenizer;
55 int default_tokenizer_length;
56 char *normalizer;
57 int normalizer_length;
58 char *token_filters;
59 int token_filters_length;
60 plugin_ref plugin;
61 handlerton *hton;
62 char **index_table;
63 char **key_tokenizer;
64 char **col_flags;
65 char **col_type;
66 uint *index_table_length;
67 uint *key_tokenizer_length;
68 uint *col_flags_length;
69 uint *col_type_length;
70 uint *wrap_key_nr;
71 uint wrap_keys;
72 uint base_keys;
73 KEY *wrap_key_info;
74 KEY *base_key_info;
75 uint wrap_primary_key;
76 uint base_primary_key;
77 bool wrapper_mode;
78 bool disable_keys;
79} MRN_SHARE;
80
81struct st_mrn_wrap_hton
82{
83 char path[FN_REFLEN + 1];
84 handlerton *hton;
85 st_mrn_wrap_hton *next;
86};
87
88struct st_mrn_slot_data
89{
90 grn_id last_insert_record_id;
91 st_mrn_wrap_hton *first_wrap_hton;
92 HA_CREATE_INFO *alter_create_info;
93 HA_CREATE_INFO *disable_keys_create_info;
94 char *alter_connect_string;
95 char *alter_comment;
96};
97
98#define MRN_SET_WRAP_ALTER_KEY(file, ha_alter_info) \
99 alter_table_operations base_handler_flags = ha_alter_info->handler_flags; \
100 KEY *base_key_info_buffer = ha_alter_info->key_info_buffer; \
101 uint base_key_count = ha_alter_info->key_count; \
102 uint base_index_drop_count = ha_alter_info->index_drop_count; \
103 KEY **base_index_drop_buffer = ha_alter_info->index_drop_buffer; \
104 uint base_index_add_count = ha_alter_info->index_add_count; \
105 uint *base_index_add_buffer = ha_alter_info->index_add_buffer; \
106 ha_alter_info->handler_flags = file->alter_handler_flags; \
107 ha_alter_info->key_info_buffer = file->alter_key_info_buffer; \
108 ha_alter_info->key_count = file->alter_key_count; \
109 ha_alter_info->index_drop_count = file->alter_index_drop_count; \
110 ha_alter_info->index_drop_buffer = &file->alter_index_drop_buffer; \
111 ha_alter_info->index_add_count = file->alter_index_add_count; \
112 ha_alter_info->index_add_buffer = file->alter_index_add_buffer;
113
114#define MRN_SET_BASE_ALTER_KEY(share, table_share) \
115 ha_alter_info->handler_flags = base_handler_flags; \
116 ha_alter_info->key_info_buffer = base_key_info_buffer; \
117 ha_alter_info->key_count = base_key_count; \
118 ha_alter_info->index_drop_count = base_index_drop_count; \
119 ha_alter_info->index_drop_buffer = base_index_drop_buffer; \
120 ha_alter_info->index_add_count = base_index_add_count; \
121 ha_alter_info->index_add_buffer = base_index_add_buffer;
122
123#define MRN_SET_WRAP_SHARE_KEY(share, table_share)
124/*
125 table_share->keys = share->wrap_keys; \
126 table_share->key_info = share->wrap_key_info; \
127 table_share->primary_key = share->wrap_primary_key;
128*/
129
130#define MRN_SET_BASE_SHARE_KEY(share, table_share)
131/*
132 table_share->keys = share->base_keys; \
133 table_share->key_info = share->base_key_info; \
134 table_share->primary_key = share->base_primary_key;
135*/
136
137#define MRN_SET_WRAP_TABLE_KEY(file, table) \
138 table->key_info = file->wrap_key_info; \
139 table->s = share->wrap_table_share;
140
141#define MRN_SET_BASE_TABLE_KEY(file, table) \
142 table->key_info = file->base_key_info; \
143 table->s = share->table_share;
144
145#ifdef WITH_PARTITION_STORAGE_ENGINE
146void mrn_get_partition_info(const char *table_name, uint table_name_length,
147 const TABLE *table, partition_element **part_elem,
148 partition_element **sub_elem);
149#endif
150int mrn_parse_table_param(MRN_SHARE *share, TABLE *table);
151bool mrn_is_geo_key(const KEY *key_info);
152int mrn_add_index_param(MRN_SHARE *share, KEY *key_info, int i);
153int mrn_parse_index_param(MRN_SHARE *share, TABLE *table);
154int mrn_add_column_param(MRN_SHARE *share, Field *field, int i);
155int mrn_parse_column_param(MRN_SHARE *share, TABLE *table);
156MRN_SHARE *mrn_get_share(const char *table_name, TABLE *table, int *error);
157int mrn_free_share_alloc(MRN_SHARE *share);
158int mrn_free_share(MRN_SHARE *share);
159MRN_LONG_TERM_SHARE *mrn_get_long_term_share(const char *table_name,
160 uint table_name_length,
161 int *error);
162void mrn_free_long_term_share(MRN_LONG_TERM_SHARE *long_term_share);
163TABLE_SHARE *mrn_get_table_share(TABLE_LIST *table_list, int *error);
164TABLE_SHARE *mrn_create_tmp_table_share(TABLE_LIST *table_list, const char *path,
165 int *error);
166void mrn_free_tmp_table_share(TABLE_SHARE *table_share);
167KEY *mrn_create_key_info_for_table(MRN_SHARE *share, TABLE *table, int *error);
168void mrn_set_bitmap_by_key(MY_BITMAP *map, KEY *key_info);
169st_mrn_slot_data *mrn_get_slot_data(THD *thd, bool can_create);
170void mrn_clear_slot_data(THD *thd);
171
172#ifdef __cplusplus
173}
174#endif
175
176#endif /* MRN_TABLE_HPP_ */
177