20
20
#ifndef DRIZZLED_SQL_BASE_H
21
21
#define DRIZZLED_SQL_BASE_H
23
24
#include <drizzled/table.h>
24
#include <drizzled/table/concurrent.h>
29
class Name_resolution_context;
31
28
void table_cache_free(void);
32
29
bool table_cache_init(void);
30
bool table_def_init(void);
31
void table_def_free(void);
32
void assign_new_table_id(TABLE_SHARE *share);
33
33
uint32_t cached_open_tables(void);
34
34
uint32_t cached_table_definitions(void);
36
table::Cache &get_open_cache();
38
36
void kill_drizzle(void);
39
#define TMP_TABLE_KEY_EXTRA 8
41
40
void set_item_name(Item *item,char *pos,uint32_t length);
42
41
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum enum_field_types type,
43
char *length, char *decimal,
44
uint32_t type_modifier,
42
char *length, char *decimal,
43
uint32_t type_modifier,
45
44
enum column_format_type column_format,
46
Item *default_value, Item *on_update_value,
48
char *change, List<String> *interval_list,
49
const CHARSET_INFO * const cs);
50
CreateField * new_create_field(Session *session, char *field_name, enum_field_types type,
51
char *length, char *decimals,
52
uint32_t type_modifier,
53
Item *default_value, Item *on_update_value,
54
LEX_STRING *comment, char *change,
55
List<String> *interval_list, CHARSET_INFO *cs);
45
Item *default_value, Item *on_update_value,
47
char *change, List<String> *interval_list,
48
const CHARSET_INFO * const cs,
49
virtual_column_info *vcol_info);
50
Create_field * new_create_field(Session *session, char *field_name, enum_field_types type,
51
char *length, char *decimals,
52
uint32_t type_modifier,
53
Item *default_value, Item *on_update_value,
54
LEX_STRING *comment, char *change,
55
List<String> *interval_list, CHARSET_INFO *cs,
56
virtual_column_info *vcol_info);
56
57
void store_position_for_column(const char *name);
58
bool add_to_list(Session *session, SQL_LIST &list,Item *group,bool asc);
57
59
bool push_new_name_resolution_context(Session *session,
58
60
TableList *left_op,
59
61
TableList *right_op);
60
62
void add_join_on(TableList *b,Item *expr);
61
63
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
65
bool add_proc_to_list(Session *session, Item *item);
66
void unlink_open_table(Session *session, Table *find, bool unlock);
67
void drop_open_table(Session *session, Table *table, const char *db_name,
68
const char *table_name);
69
void update_non_unique_table_error(TableList *update,
70
const char *operation,
71
TableList *duplicate);
73
SQL_SELECT *make_select(Table *head, table_map const_tables,
74
table_map read_tables, COND *conds,
75
bool allow_null_cond, int *error);
63
76
extern Item **not_found_item;
66
79
A set of constants used for checking non aggregated fields and sum
67
80
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
69
enum enum_group_by_mode_type
71
NON_AGG_FIELD_USED= 0,
82
#define NON_AGG_FIELD_USED 1
83
#define SUM_FUNC_USED 2
76
86
This enumeration type is used only by the function find_item_in_list
77
87
to return the info on how an item has been resolved against a list
78
88
of possibly aliased items.
91
101
RESOLVED_WITH_NO_ALIAS,
92
102
RESOLVED_AGAINST_ALIAS
94
Item ** find_item_in_list(Session *session,
95
Item *item, List<Item> &items, uint32_t *counter,
104
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
96
105
find_item_error_report_type report_error,
97
106
enum_resolution_type *resolution);
107
bool get_key_map_from_key_list(key_map *map, Table *table,
108
List<String> *index_list);
98
109
bool insert_fields(Session *session, Name_resolution_context *context,
99
const char *db_name, const char *table_name,
110
const char *db_name, const char *table_name,
100
111
List_iterator<Item> *it, bool any_privileges);
101
112
bool setup_tables(Session *session, Name_resolution_context *context,
102
113
List<TableList> *from_clause, TableList *tables,
127
int setup_conds(Session *session, TableList *leaves, COND **conds);
137
int setup_conds(Session *session, TableList *tables, TableList *leaves,
139
int setup_ftfuncs(Select_Lex* select);
140
int init_ftfuncs(Session *session, Select_Lex* select, bool no_order);
141
void wait_for_condition(Session *session, pthread_mutex_t *mutex,
142
pthread_cond_t *cond);
143
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
128
144
/* open_and_lock_tables with optional derived handling */
145
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
146
/* simple open_and_lock_tables without derived handling */
147
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
149
return open_and_lock_tables_derived(session, tables, false);
151
/* open_and_lock_tables with derived handling */
152
inline int open_and_lock_tables(Session *session, TableList *tables)
154
return open_and_lock_tables_derived(session, tables, true);
156
/* simple open_and_lock_tables without derived handling for single table */
157
Table *open_n_lock_single_table(Session *session, TableList *table_l,
158
thr_lock_type lock_type);
159
bool open_normal_and_derived_tables(Session *session, TableList *tables, uint32_t flags);
160
int lock_tables(Session *session, TableList *tables, uint32_t counter, bool *need_reopen);
161
int decide_logging_format(Session *session);
162
Table *open_temporary_table(Session *session, const char *path, const char *db,
163
const char *table_name, bool link_in_list,
164
open_table_mode open_mode);
165
bool rm_temporary_table(handlerton *base, char *path);
166
void free_io_cache(Table *entry);
167
void intern_close_table(Table *entry);
168
bool close_thread_table(Session *session, Table **table_ptr);
169
void close_temporary_tables(Session *session);
170
void close_tables_for_reopen(Session *session, TableList **tables);
129
171
TableList *find_table_in_list(TableList *table,
130
172
TableList *TableList::*link,
131
173
const char *db_name,
132
174
const char *table_name);
133
TableList *unique_table(TableList *table, TableList *table_list,
134
bool check_alias= false);
175
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
177
Table *find_temporary_table(Session *session, const char *db, const char *table_name);
178
Table *find_temporary_table(Session *session, TableList *table_list);
179
int drop_temporary_table(Session *session, TableList *table_list);
180
void close_temporary_table(Session *session, Table *table, bool free_share,
182
void close_temporary(Table *table, bool free_share, bool delete_table);
183
bool rename_temporary_table(Session* session, Table *table, const char *new_db,
184
const char *table_name);
185
void remove_db_from_cache(const char *db);
187
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
136
/* bits for last argument to table::Cache::singleton().removeTable() */
189
/* bits for last argument to remove_table_from_cache() */
137
190
#define RTFC_NO_FLAG 0x0000
138
191
#define RTFC_OWNED_BY_Session_FLAG 0x0001
139
192
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
140
193
#define RTFC_CHECK_KILLED_FLAG 0x0004
194
bool remove_table_from_cache(Session *session, const char *db, const char *table,
197
#define NORMAL_PART_NAME 0
198
#define TEMP_PART_NAME 1
199
#define RENAMED_PART_NAME 2
142
201
void mem_alloc_error(size_t size);
144
bool fill_record(Session* session, List<Item> &fields, List<Item> &values, bool ignore_errors= false);
145
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors= false);
203
#define WFRM_WRITE_SHADOW 1
204
#define WFRM_INSTALL_SHADOW 2
205
#define WFRM_PACK_FRM 4
206
#define WFRM_KEEP_SHARE 8
208
bool close_cached_tables(Session *session, TableList *tables, bool have_lock,
209
bool wait_for_refresh, bool wait_for_placeholders);
210
bool close_cached_connection_tables(Session *session, bool wait_for_refresh,
211
LEX_STRING *connect_string,
212
bool have_lock= false);
213
void copy_field_from_tmp_record(Field *field,int offset);
214
bool fill_record(Session * session, List<Item> &fields, List<Item> &values, bool ignore_errors);
215
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors);
216
OPEN_TableList *list_open_tables(const char *db, const char *wild);
146
218
inline TableList *find_table_in_global_list(TableList *table,
147
219
const char *db_name,
148
220
const char *table_name)