1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
Mostly this file is used in the server. But a little part of it is used in
25
mysqlbinlog too (definition of SELECT_DISTINCT and others).
27
@TODO Name this file better. "priv" could mean private, privileged, privileges.
30
#ifndef DRIZZLE_SERVER_SERVER_INCLUDES_H
31
#define DRIZZLE_SERVER_SERVER_INCLUDES_H
33
/* Some forward declarations just for the server */
36
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
39
* Contains all headers, definitions, and declarations common to
40
* the server and the plugin infrastructure, and not the client
42
#include <drizzled/common_includes.h>
43
/* Range optimization API/library */
44
#include <drizzled/opt_range.h>
45
/* Simple error injection (crash) module */
46
#include <drizzled/error_injection.h>
47
/* API for connecting, logging in to a drizzled server */
48
#include <drizzled/connect.h>
49
/* Routines for dropping, repairing, checking schema tables */
50
#include <drizzled/sql_table.h>
53
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
54
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
55
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
56
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
58
bool mysql_opt_change_db(THD *thd,
59
const LEX_STRING *new_db_name,
60
LEX_STRING *saved_db_name,
62
bool *cur_db_changed);
65
void write_bin_log(THD *thd, bool clear_error,
66
char const *query, ulong query_length);
67
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, uint16_t flags);
68
void mysql_client_binlog_statement(THD *thd);
71
bool mysql_rename_tables(THD *thd, TableList *table_list, bool silent);
72
bool do_rename(THD *thd, TableList *ren_table, char *new_db,
73
char *new_table_name, char *new_table_alias,
77
void mysql_parse(THD *thd, const char *inBuf, uint32_t length,
78
const char ** semicolon);
80
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint32_t length);
83
bool is_update_query(enum enum_sql_command command);
85
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length);
87
void mysql_reset_thd_for_next_command(THD *thd);
89
void create_select_for_variable(const char *var_name);
91
void mysql_init_multi_delete(LEX *lex);
93
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
95
void init_update_queries(void);
97
bool do_command(THD *thd);
99
bool dispatch_command(enum enum_server_command command, THD *thd,
100
char* packet, uint32_t packet_length);
102
void log_slow_statement(THD *thd);
104
bool append_file_to_dir(THD *thd, const char **filename_ptr,
105
const char *table_name);
107
bool reload_cache(THD *thd, ulong options, TableList *tables, bool *write_to_binlog);
109
bool check_simple_select();
111
void mysql_init_select(LEX *lex);
112
bool mysql_new_select(LEX *lex, bool move_down);
115
void table_cache_free(void);
116
bool table_cache_init(void);
117
bool table_def_init(void);
118
void table_def_free(void);
119
void assign_new_table_id(TABLE_SHARE *share);
120
uint32_t cached_open_tables(void);
121
uint32_t cached_table_definitions(void);
124
void kill_mysql(void);
125
void close_connection(THD *thd, uint32_t errcode, bool lock);
128
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
131
bool mysql_xa_recover(THD *thd);
133
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
134
SORT_FIELD *sortorder);
135
int setup_order(THD *thd, Item **ref_pointer_array, TableList *tables,
136
List<Item> &fields, List <Item> &all_fields, order_st *order);
137
int setup_group(THD *thd, Item **ref_pointer_array, TableList *tables,
138
List<Item> &fields, List<Item> &all_fields, order_st *order,
139
bool *hidden_group_fields);
140
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
141
Item **ref_pointer_array);
143
bool handle_select(THD *thd, LEX *lex, select_result *result,
144
ulong setup_tables_done_option);
145
bool mysql_select(THD *thd, Item ***rref_pointer_array,
146
TableList *tables, uint32_t wild_num, List<Item> &list,
147
COND *conds, uint32_t og_num, order_st *order, order_st *group,
148
Item *having, order_st *proc_param, uint64_t select_type,
149
select_result *result, SELECT_LEX_UNIT *unit,
150
SELECT_LEX *select_lex);
151
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
152
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
153
select_result *result);
154
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
155
select_result *result);
156
bool mysql_union(THD *thd, LEX *lex, select_result *result,
157
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
158
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
161
bool mysql_derived_prepare(THD *thd, LEX *lex, TableList *t);
162
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *t);
163
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
164
Item ***copy_func, Field **from_field,
166
bool group, bool modify_item,
167
bool table_cant_handle_bit_fields,
168
bool make_copy_field,
169
uint32_t convert_blob_length);
170
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
171
int prepare_create_field(Create_field *sql_field,
172
uint32_t *blob_columns,
173
int *timestamps, int *timestamps_with_niladic,
174
int64_t table_flags);
175
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
176
HA_CREATE_INFO *create_info,
177
Alter_info *alter_info,
178
bool tmp_table, uint32_t select_field_count);
179
bool mysql_create_table_no_lock(THD *thd, const char *db,
180
const char *table_name,
181
HA_CREATE_INFO *create_info,
182
Alter_info *alter_info,
183
bool tmp_table, uint32_t select_field_count,
184
bool lock_open_lock);
186
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
187
HA_CREATE_INFO *create_info,
188
TableList *table_list,
189
Alter_info *alter_info,
190
uint32_t order_num, order_st *order, bool ignore);
191
bool mysql_recreate_table(THD *thd, TableList *table_list);
192
bool mysql_create_like_table(THD *thd, TableList *table,
193
TableList *src_table,
194
HA_CREATE_INFO *create_info);
195
bool mysql_rename_table(handlerton *base, const char *old_db,
196
const char * old_name, const char *new_db,
197
const char * new_name, uint32_t flags);
198
bool mysql_prepare_update(THD *thd, TableList *table_list,
199
Item **conds, uint32_t order_num, order_st *order);
200
int mysql_update(THD *thd,TableList *tables,List<Item> &fields,
201
List<Item> &values,COND *conds,
202
uint32_t order_num, order_st *order, ha_rows limit,
203
enum enum_duplicates handle_duplicates, bool ignore);
204
bool mysql_multi_update(THD *thd, TableList *table_list,
205
List<Item> *fields, List<Item> *values,
206
COND *conds, uint64_t options,
207
enum enum_duplicates handle_duplicates, bool ignore,
208
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
209
bool mysql_prepare_insert(THD *thd, TableList *table_list, Table *table,
210
List<Item> &fields, List_item *values,
211
List<Item> &update_fields,
212
List<Item> &update_values, enum_duplicates duplic,
213
COND **where, bool select_insert,
214
bool check_fields, bool abort_on_warning);
215
bool mysql_insert(THD *thd,TableList *table,List<Item> &fields,
216
List<List_item> &values, List<Item> &update_fields,
217
List<Item> &update_values, enum_duplicates flag,
219
int check_that_all_fields_are_given_values(THD *thd, Table *entry,
220
TableList *table_list);
221
void prepare_triggers_for_insert_stmt(Table *table);
222
int mysql_prepare_delete(THD *thd, TableList *table_list, Item **conds);
223
bool mysql_delete(THD *thd, TableList *table_list, COND *conds,
224
SQL_LIST *order, ha_rows rows, uint64_t options,
225
bool reset_auto_increment);
226
bool mysql_truncate(THD *thd, TableList *table_list, bool dont_send_ok);
227
uint32_t create_table_def_key(THD *thd, char *key, TableList *table_list,
229
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
230
uint32_t key_length, uint32_t db_flags, int *error);
231
void release_table_share(TABLE_SHARE *share, enum release_type type);
232
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
233
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type update,
234
uint32_t lock_flags);
235
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint32_t flags);
236
bool name_lock_locked_table(THD *thd, TableList *tables);
237
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in);
238
Table *table_cache_insert_placeholder(THD *thd, const char *key,
239
uint32_t key_length);
240
bool lock_table_name_if_not_cached(THD *thd, const char *db,
241
const char *table_name, Table **table);
242
Table *find_locked_table(THD *thd, const char *db,const char *table_name);
243
void detach_merge_children(Table *table, bool clear_refs);
244
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
245
TableList *new_child_list, TableList **new_last);
246
bool reopen_table(Table *table);
247
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
248
void close_data_files_and_morph_locks(THD *thd, const char *db,
249
const char *table_name);
250
void close_handle_and_leave_table_as_lock(Table *table);
251
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
252
uint32_t db_stat, uint32_t prgflag,
253
uint32_t ha_open_flags, Table *outparam,
254
TableList *table_desc, MEM_ROOT *mem_root);
255
bool wait_for_tables(THD *thd);
256
bool table_is_used(Table *table, bool wait_for_name_lock);
257
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name);
258
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
259
void execute_init_command(THD *thd, sys_var_str *init_command_var,
260
rw_lock_t *var_mutex);
261
extern Field *not_found_field;
262
extern Field *view_ref_found;
264
enum find_item_error_report_type {REPORT_ALL_ERRORS, REPORT_EXCEPT_NOT_FOUND,
265
IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
266
IGNORE_EXCEPT_NON_UNIQUE};
268
find_field_in_tables(THD *thd, Item_ident *item,
269
TableList *first_table, TableList *last_table,
270
Item **ref, find_item_error_report_type report_error,
271
bool check_privileges, bool register_tree_change);
273
find_field_in_table_ref(THD *thd, TableList *table_list,
274
const char *name, uint32_t length,
275
const char *item_name, const char *db_name,
276
const char *table_name, Item **ref,
277
bool check_privileges, bool allow_rowid,
278
uint32_t *cached_field_index_ptr,
279
bool register_tree_change, TableList **actual_table);
281
find_field_in_table(THD *thd, Table *table, const char *name, uint32_t length,
282
bool allow_rowid, uint32_t *cached_field_index_ptr);
284
find_field_in_table_sef(Table *table, const char *name);
285
int update_virtual_fields_marked_for_write(Table *table,
286
bool ignore_stored=true);
289
bool mysql_do(THD *thd, List<Item> &values);
292
bool append_escaped(String *to_str, String *from_str);
294
#include <drizzled/show.h>
296
/* information schema */
297
extern LEX_STRING INFORMATION_SCHEMA_NAME;
299
extern LEX_STRING DRIZZLE_SCHEMA_NAME;
300
extern LEX_STRING GENERAL_LOG_NAME;
301
extern LEX_STRING SLOW_LOG_NAME;
303
extern const LEX_STRING partition_keywords[];
304
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
305
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
306
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
307
enum enum_schema_tables schema_table_idx);
308
int make_schema_select(THD *thd, SELECT_LEX *sel,
309
enum enum_schema_tables schema_table_idx);
310
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list);
311
bool get_schema_tables_result(JOIN *join,
312
enum enum_schema_table_state executed_place);
313
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
315
#define is_schema_db(X) \
316
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
319
bool mysql_ha_open(THD *thd, TableList *tables, bool reopen);
320
bool mysql_ha_close(THD *thd, TableList *tables);
321
bool mysql_ha_read(THD *, TableList *,enum enum_ha_read_modes,char *,
322
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
323
void mysql_ha_flush(THD *thd);
324
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked);
325
void mysql_ha_cleanup(THD *thd);
328
#define TMP_TABLE_KEY_EXTRA 8
329
void set_item_name(Item *item,char *pos,uint32_t length);
330
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
331
char *length, char *decimal,
332
uint32_t type_modifier,
333
enum column_format_type column_format,
334
Item *default_value, Item *on_update_value,
336
char *change, List<String> *interval_list,
337
const CHARSET_INFO * const cs,
338
virtual_column_info *vcol_info);
339
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
340
char *length, char *decimals,
341
uint32_t type_modifier,
342
Item *default_value, Item *on_update_value,
343
LEX_STRING *comment, char *change,
344
List<String> *interval_list, CHARSET_INFO *cs,
345
virtual_column_info *vcol_info);
346
void store_position_for_column(const char *name);
347
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
348
bool push_new_name_resolution_context(THD *thd,
350
TableList *right_op);
351
void add_join_on(TableList *b,Item *expr);
352
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
354
bool add_proc_to_list(THD *thd, Item *item);
355
void unlink_open_table(THD *thd, Table *find, bool unlock);
356
void drop_open_table(THD *thd, Table *table, const char *db_name,
357
const char *table_name);
358
void update_non_unique_table_error(TableList *update,
359
const char *operation,
360
TableList *duplicate);
362
SQL_SELECT *make_select(Table *head, table_map const_tables,
363
table_map read_tables, COND *conds,
364
bool allow_null_cond, int *error);
365
extern Item **not_found_item;
368
A set of constants used for checking non aggregated fields and sum
369
functions mixture in the ONLY_FULL_GROUP_BY_MODE.
371
#define NON_AGG_FIELD_USED 1
372
#define SUM_FUNC_USED 2
375
This enumeration type is used only by the function find_item_in_list
376
to return the info on how an item has been resolved against a list
377
of possibly aliased items.
378
The item can be resolved:
379
- against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
380
- against non-aliased field name of the list (RESOLVED_WITH_NO_ALIAS)
381
- against an aliased field name of the list (RESOLVED_BEHIND_ALIAS)
382
- ignoring the alias name in cases when SQL requires to ignore aliases
383
(e.g. when the resolved field reference contains a table name or
384
when the resolved item is an expression) (RESOLVED_IGNORING_ALIAS)
386
enum enum_resolution_type {
388
RESOLVED_IGNORING_ALIAS,
389
RESOLVED_BEHIND_ALIAS,
390
RESOLVED_WITH_NO_ALIAS,
391
RESOLVED_AGAINST_ALIAS
393
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
394
find_item_error_report_type report_error,
395
enum_resolution_type *resolution);
396
bool get_key_map_from_key_list(key_map *map, Table *table,
397
List<String> *index_list);
398
bool insert_fields(THD *thd, Name_resolution_context *context,
399
const char *db_name, const char *table_name,
400
List_iterator<Item> *it, bool any_privileges);
401
bool setup_tables(THD *thd, Name_resolution_context *context,
402
List<TableList> *from_clause, TableList *tables,
403
TableList **leaves, bool select_insert);
404
bool setup_tables_and_check_access(THD *thd,
405
Name_resolution_context *context,
406
List<TableList> *from_clause,
410
int setup_wild(THD *thd, TableList *tables, List<Item> &fields,
411
List<Item> *sum_func_list, uint32_t wild_num);
412
bool setup_fields(THD *thd, Item** ref_pointer_array,
413
List<Item> &item, enum_mark_columns mark_used_columns,
414
List<Item> *sum_func_list, bool allow_sum_func);
415
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
417
enum_mark_columns mark_used_columns,
418
List<Item> *sum_func_list,
422
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
426
int setup_conds(THD *thd, TableList *tables, TableList *leaves,
428
int setup_ftfuncs(SELECT_LEX* select);
429
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
430
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
431
pthread_cond_t *cond);
432
int open_tables(THD *thd, TableList **tables, uint32_t *counter, uint32_t flags);
433
/* open_and_lock_tables with optional derived handling */
434
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived);
435
/* simple open_and_lock_tables without derived handling */
436
inline int simple_open_n_lock_tables(THD *thd, TableList *tables)
438
return open_and_lock_tables_derived(thd, tables, false);
440
/* open_and_lock_tables with derived handling */
441
inline int open_and_lock_tables(THD *thd, TableList *tables)
443
return open_and_lock_tables_derived(thd, tables, true);
445
/* simple open_and_lock_tables without derived handling for single table */
446
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
447
thr_lock_type lock_type);
448
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint32_t flags);
449
int lock_tables(THD *thd, TableList *tables, uint32_t counter, bool *need_reopen);
450
int decide_logging_format(THD *thd, TableList *tables);
451
Table *open_temporary_table(THD *thd, const char *path, const char *db,
452
const char *table_name, bool link_in_list,
453
open_table_mode open_mode);
454
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
455
void free_io_cache(Table *entry);
456
void intern_close_table(Table *entry);
457
bool close_thread_table(THD *thd, Table **table_ptr);
458
void close_temporary_tables(THD *thd);
459
void close_tables_for_reopen(THD *thd, TableList **tables);
460
TableList *find_table_in_list(TableList *table,
461
TableList *TableList::*link,
463
const char *table_name);
464
TableList *unique_table(THD *thd, TableList *table, TableList *table_list,
466
Table *find_temporary_table(THD *thd, const char *db, const char *table_name);
467
Table *find_temporary_table(THD *thd, TableList *table_list);
468
int drop_temporary_table(THD *thd, TableList *table_list);
469
void close_temporary_table(THD *thd, Table *table, bool free_share,
471
void close_temporary(Table *table, bool free_share, bool delete_table);
472
bool rename_temporary_table(THD* thd, Table *table, const char *new_db,
473
const char *table_name);
474
void remove_db_from_cache(const char *db);
476
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
477
char *make_default_log_name(char *buff,const char* log_ext);
479
/* bits for last argument to remove_table_from_cache() */
480
#define RTFC_NO_FLAG 0x0000
481
#define RTFC_OWNED_BY_THD_FLAG 0x0001
482
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
483
#define RTFC_CHECK_KILLED_FLAG 0x0004
484
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
487
#define NORMAL_PART_NAME 0
488
#define TEMP_PART_NAME 1
489
#define RENAMED_PART_NAME 2
491
void mem_alloc_error(size_t size);
493
#define WFRM_WRITE_SHADOW 1
494
#define WFRM_INSTALL_SHADOW 2
495
#define WFRM_PACK_FRM 4
496
#define WFRM_KEEP_SHARE 8
498
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
499
bool wait_for_refresh, bool wait_for_placeholders);
500
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
501
LEX_STRING *connect_string,
502
bool have_lock= false);
503
void copy_field_from_tmp_record(Field *field,int offset);
504
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
505
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
506
OPEN_TableList *list_open_tables(THD *thd, const char *db, const char *wild);
508
inline TableList *find_table_in_global_list(TableList *table,
510
const char *table_name)
512
return find_table_in_list(table, &TableList::next_global,
513
db_name, table_name);
516
inline TableList *find_table_in_local_list(TableList *table,
518
const char *table_name)
520
return find_table_in_list(table, &TableList::next_local,
521
db_name, table_name);
526
bool eval_const_cond(COND *cond);
529
int mysql_load(THD *thd, sql_exchange *ex, TableList *table_list,
530
List<Item> &fields_vars, List<Item> &set_fields,
531
List<Item> &set_values_list,
532
enum enum_duplicates handle_duplicates, bool ignore,
534
int write_record(THD *thd, Table *table, COPY_INFO *info);
538
void print_where(COND *cond,const char *info, enum_query_type query_type);
539
void print_cached_tables(void);
540
void TEST_filesort(SORT_FIELD *sortorder,uint32_t s_length);
541
void print_plan(JOIN* join,uint32_t idx, double record_count, double read_time,
542
double current_read_time, const char *info);
543
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
544
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
545
void mysql_print_status();
548
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
549
uint32_t *key_length, uint32_t *keypart);
550
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
551
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
552
uint16_t key_length);
553
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
554
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
555
void key_unpack(String *to,Table *form,uint32_t index);
556
bool is_key_used(Table *table, uint32_t idx, const MY_BITMAP *fields);
557
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
558
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
560
bool init_errmessage(void);
561
File open_binlog(IO_CACHE *log, const char *log_file_name,
562
const char **errmsg);
565
extern void MYSQLerror(const char*);
566
void refresh_status(THD *thd);
567
bool mysql_rm_tmp_tables(void);
568
void handle_connection_in_main_thread(THD *thd);
569
void create_thread_to_handle_connection(THD *thd);
570
void unlink_thd(THD *thd);
571
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
572
void flush_thread_cache();
575
extern bool check_reserved_words(LEX_STRING *name);
576
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
579
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
580
char **err_pos, uint32_t *err_len, bool *set_warning);
581
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
583
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
584
const CHARSET_INFO *cs);
585
void unhex_type2(TYPELIB *lib);
586
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
587
const char **end_of_word);
588
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
589
const CHARSET_INFO * const cs);
592
bool is_keyword(const char *name, uint32_t len);
594
#define MY_DB_OPT_FILE "db.opt"
595
bool my_database_names_init(void);
596
void my_database_names_free(void);
597
bool check_db_dir_existence(const char *db_name);
598
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
599
bool load_db_opt_by_name(THD *thd, const char *db_name,
600
HA_CREATE_INFO *db_create_info);
601
const CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
602
bool my_dbopt_init(void);
603
void my_dbopt_cleanup(void);
604
extern int creating_database; // How many database locks are made
605
extern int creating_table; // How many mysql_create_table() are running
611
extern time_t server_start_time, flush_status_time;
612
extern char *opt_mysql_tmpdir;
614
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
615
extern MY_TMPDIR mysql_tmpdir_list;
616
extern const LEX_STRING command_name[];
617
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
618
extern const char *myisam_recover_options_str;
619
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
620
extern const char * const TRG_EXT;
621
extern const char * const TRN_EXT;
622
extern Eq_creator eq_creator;
623
extern Ne_creator ne_creator;
624
extern Gt_creator gt_creator;
625
extern Lt_creator lt_creator;
626
extern Ge_creator ge_creator;
627
extern Le_creator le_creator;
628
extern char language[FN_REFLEN];
629
extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
630
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
631
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
632
extern const double log_10[309];
633
extern uint64_t log_10_int[20];
634
extern uint64_t keybuff_size;
635
extern uint64_t thd_startup_options;
636
extern ulong thread_id;
637
extern ulong binlog_cache_use, binlog_cache_disk_use;
638
extern ulong aborted_threads,aborted_connects;
639
extern ulong slave_open_temp_tables;
640
extern ulong slow_launch_threads, slow_launch_time;
641
extern ulong table_cache_size, table_def_size;
642
extern ulong max_connections,max_connect_errors, connect_timeout;
643
extern bool slave_allow_batching;
644
extern ulong slave_net_timeout, slave_trans_retries;
645
extern uint32_t max_user_connections;
646
extern ulong what_to_log,flush_time;
647
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
648
extern ulong max_binlog_size, max_relay_log_size;
649
extern ulong opt_binlog_rows_event_max_size;
650
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
651
extern ulong back_log;
652
extern ulong current_pid;
653
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
654
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
655
extern ulong tc_log_page_waits;
656
extern bool relay_log_purge;
657
extern bool opt_innodb_safe_binlog, opt_innodb;
658
extern uint32_t test_flags,select_errors,ha_open_options;
659
extern uint32_t protocol_version, mysqld_port, dropping_tables;
660
extern uint32_t delay_key_write_options;
661
extern bool opt_endinfo, using_udf_functions;
662
extern bool locked_in_memory;
663
extern bool opt_using_transactions;
664
extern bool using_update_log, server_id_supplied;
665
extern bool opt_update_log, opt_bin_log, opt_error_log;
667
extern bool opt_slow_log;
668
extern ulong log_output_options;
669
extern bool opt_log_queries_not_using_indexes;
670
extern bool opt_character_set_client_handshake;
671
extern bool volatile abort_loop, shutdown_in_progress;
672
extern uint32_t volatile thread_count, thread_running, global_read_lock;
673
extern uint32_t connection_count;
674
extern bool opt_sql_bin_update;
675
extern bool opt_safe_user_create;
676
extern bool opt_no_mix_types;
677
extern bool opt_safe_show_db, opt_myisam_use_mmap;
678
extern bool opt_local_infile;
679
extern bool opt_slave_compressed_protocol;
680
extern bool use_temp_pool;
681
extern ulong slave_exec_mode_options;
682
extern bool opt_readonly;
683
extern char* opt_secure_file_priv;
684
extern bool opt_noacl;
685
extern bool opt_old_style_user_limits;
686
extern uint32_t opt_crash_binlog_innodb;
687
extern char *default_tz_name;
688
extern char *opt_logname, *opt_slow_logname;
689
extern const char *log_output_str;
691
extern DRIZZLE_BIN_LOG mysql_bin_log;
692
extern LOGGER logger;
693
extern TableList general_log, slow_log;
694
extern FILE *stderror_file;
695
extern pthread_key(MEM_ROOT**,THR_MALLOC);
696
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_open, LOCK_lock_db,
697
LOCK_thread_count,LOCK_user_locks, LOCK_status,
698
LOCK_error_log, LOCK_uuid_generator,
699
LOCK_crypt, LOCK_timezone,
700
LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
701
LOCK_global_system_variables, LOCK_user_conn,
702
LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
703
extern pthread_mutex_t LOCK_server_started;
704
extern rw_lock_t LOCK_sys_init_connect, LOCK_sys_init_slave;
705
extern rw_lock_t LOCK_system_variables_hash;
706
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
707
extern pthread_cond_t COND_global_read_lock;
708
extern pthread_attr_t connection_attrib;
709
extern I_List<THD> threads;
710
extern I_List<NAMED_LIST> key_caches;
711
extern MY_BITMAP temp_pool;
712
extern String my_empty_string;
713
extern const String my_null_string;
714
extern SHOW_VAR status_vars[];
715
extern struct system_variables max_system_variables;
716
extern struct system_status_var global_status_var;
717
extern struct rand_struct sql_rand;
719
extern const char *opt_date_time_formats[];
720
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
722
extern HASH open_cache, lock_db_cache;
723
extern Table *unused_tables;
724
extern const char* any_db;
725
extern struct my_option my_long_options[];
726
extern const LEX_STRING view_type;
727
extern scheduler_functions thread_scheduler;
728
extern TYPELIB thread_handling_typelib;
729
extern uint8_t uc_update_queries[SQLCOM_END+1];
730
extern uint32_t sql_command_flags[];
731
extern TYPELIB log_output_typelib;
733
/* optional things, have_* variables */
734
extern SHOW_COMP_OPTION have_community_features;
736
extern handlerton *myisam_hton;
737
extern handlerton *heap_hton;
739
extern SHOW_COMP_OPTION have_symlink;
740
extern SHOW_COMP_OPTION have_compress;
743
extern pthread_t signal_thread;
745
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, Table **table, uint32_t count,
746
uint32_t flags, bool *need_reopen);
747
/* mysql_lock_tables() and open_table() flags bits */
748
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001
749
#define DRIZZLE_LOCK_IGNORE_FLUSH 0x0002
750
#define DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN 0x0004
751
#define DRIZZLE_OPEN_TEMPORARY_ONLY 0x0008
752
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0010
753
#define DRIZZLE_LOCK_PERF_SCHEMA 0x0020
755
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
756
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
757
void mysql_unlock_some_tables(THD *thd, Table **table,uint32_t count);
758
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,Table *table,
760
void mysql_lock_abort(THD *thd, Table *table, bool upgrade_lock);
761
void mysql_lock_downgrade_write(THD *thd, Table *table,
762
thr_lock_type new_lock_type);
763
bool mysql_lock_abort_for_thread(THD *thd, Table *table);
764
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
765
TableList *mysql_lock_have_duplicate(THD *thd, TableList *needle,
766
TableList *haystack);
767
bool lock_global_read_lock(THD *thd);
768
void unlock_global_read_lock(THD *thd);
769
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
771
void start_waiting_global_read_lock(THD *thd);
772
bool make_global_read_lock_block_commit(THD *thd);
773
bool set_protect_against_global_read_lock(void);
774
void unset_protect_against_global_read_lock(void);
775
void broadcast_refresh(void);
776
int try_transactional_lock(THD *thd, TableList *table_list);
777
int check_transactional_lock(THD *thd, TableList *table_list);
778
int set_handler_table_locks(THD *thd, TableList *table_list,
781
/* Lock based on name */
782
int lock_and_wait_for_table_name(THD *thd, TableList *table_list);
783
int lock_table_name(THD *thd, TableList *table_list, bool check_in_use);
784
void unlock_table_name(THD *thd, TableList *table_list);
785
bool wait_for_locked_table_names(THD *thd, TableList *table_list);
786
bool lock_table_names(THD *thd, TableList *table_list);
787
void unlock_table_names(THD *thd, TableList *table_list,
788
TableList *last_table);
789
bool lock_table_names_exclusively(THD *thd, TableList *table_list);
790
bool is_table_name_exclusively_locked_by_this_thread(THD *thd,
791
TableList *table_list);
792
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, unsigned char *key,
796
/* old unireg functions */
798
void unireg_init(ulong options);
799
void unireg_end(void) __attribute__((noreturn));
800
bool mysql_create_frm(THD *thd, const char *file_name,
801
const char *db, const char *table,
802
HA_CREATE_INFO *create_info,
803
List<Create_field> &create_field,
804
uint32_t key_count,KEY *key_info,handler *db_type);
805
int rea_create_table(THD *thd, const char *path,
806
const char *db, const char *table_name,
807
HA_CREATE_INFO *create_info,
808
List<Create_field> &create_field,
809
uint32_t key_count,KEY *key_info,
811
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
815
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
816
uint32_t key_length);
817
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
819
const char *table_name, const char *path);
820
void free_table_share(TABLE_SHARE *share);
821
int open_table_def(THD *thd, TABLE_SHARE *share, uint32_t db_flags);
822
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
823
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
824
uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
825
Table *outparam, open_table_mode open_mode);
826
int readfrm(const char *name, unsigned char **data, size_t *length);
827
int writefrm(const char* name, const unsigned char* data, size_t len);
828
int closefrm(Table *table, bool free_share);
829
int read_string(File file, unsigned char* *to, size_t length);
830
void free_blobs(Table *table);
831
int set_zone(int nr,int min_zone,int max_zone);
832
ulong convert_period_to_month(ulong period);
833
ulong convert_month_to_period(ulong month);
834
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
836
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
837
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
838
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
839
DRIZZLE_TIME *l_time, uint32_t flags);
840
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
841
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
843
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
845
uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
846
const char *field_name);
848
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
849
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
850
int64_t *seconds_out, long *microseconds_out);
852
extern LEX_STRING interval_type_to_name[];
854
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
855
const char *format_str,
856
uint32_t format_length);
857
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
858
DATE_TIME_FORMAT *format);
859
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
860
enum enum_drizzle_timestamp_type type);
861
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
862
enum enum_drizzle_timestamp_type type, String *str);
863
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
865
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
867
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
869
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
870
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
871
Item *warn_item, bool *is_null);
873
int test_if_number(char *str,int *res,bool allow_wildcards);
874
void change_byte(unsigned char *,uint,char,char);
875
void init_read_record(READ_RECORD *info, THD *thd, Table *reg_form,
877
int use_record_cache, bool print_errors);
878
void init_read_record_idx(READ_RECORD *info, THD *thd, Table *table,
879
bool print_error, uint32_t idx);
880
void end_read_record(READ_RECORD *info);
881
ha_rows filesort(THD *thd, Table *form,struct st_sort_field *sortorder,
882
uint32_t s_length, SQL_SELECT *select,
883
ha_rows max_rows, bool sort_positions,
884
ha_rows *examined_rows);
885
void filesort_free_buffers(Table *table, bool full);
886
void change_double_for_sort(double nr,unsigned char *to);
887
double my_double_round(double value, int64_t dec, bool dec_unsigned,
889
int get_quick_record(SQL_SELECT *select);
891
int calc_weekday(long daynr,bool sunday_first_day_of_week);
892
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
893
void find_date(char *pos,uint32_t *vek,uint32_t flag);
894
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
895
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
896
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
897
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
898
const char *newname);
899
ulong next_io_size(ulong pos);
900
void append_unescaped(String *res, const char *pos, uint32_t length);
901
int create_frm(THD *thd, const char *name, const char *db, const char *table,
902
uint32_t reclength, unsigned char *fileinfo,
903
HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
904
int rename_file_ext(const char * from,const char * to,const char * ext);
905
bool check_db_name(LEX_STRING *db);
906
bool check_column_name(const char *name);
907
bool check_table_name(const char *name, uint32_t length);
908
char *get_field(MEM_ROOT *mem, Field *field);
909
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
910
char *fn_rext(char *name);
912
/* Conversion functions */
913
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
914
const char *table, const char *ext, uint32_t flags);
916
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
917
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9
919
/* Flags for conversion functions. */
920
#define FN_FROM_IS_TMP (1 << 0)
921
#define FN_TO_IS_TMP (1 << 1)
922
#define FN_IS_TMP (FN_FROM_IS_TMP | FN_TO_IS_TMP)
923
#define NO_FRM_RENAME (1 << 2)
926
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
927
LEX_STRING component);
928
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
929
LEX_STRING &name, user_var_entry **out_entry);
931
bool flush_error_log(void);
934
void free_list(I_List <i_string_pair> *list);
935
void free_list(I_List <i_string> *list);
937
/* Some inline functions for more speed */
939
inline bool add_item_to_list(THD *thd, Item *item)
941
return thd->lex->current_select->add_item_to_list(thd, item);
944
inline bool add_value_to_list(THD *thd, Item *value)
946
return thd->lex->value_list.push_back(value);
949
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
951
return thd->lex->current_select->add_order_to_list(thd, item, asc);
954
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
956
return thd->lex->current_select->add_group_to_list(thd, item, asc);
959
inline void mark_as_null_row(Table *table)
962
table->status|=STATUS_NULL_ROW;
963
memset(table->null_flags, 255, table->s->null_bytes);
966
inline void table_case_convert(char * name, uint32_t length)
968
if (lower_case_table_names)
969
files_charset_info->cset->casedn(files_charset_info,
970
name, length, name, length);
973
inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
975
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
978
inline ulong sql_rnd()
980
ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
985
Comp_creator *comp_eq_creator(bool invert);
986
Comp_creator *comp_ge_creator(bool invert);
987
Comp_creator *comp_gt_creator(bool invert);
988
Comp_creator *comp_le_creator(bool invert);
989
Comp_creator *comp_lt_creator(bool invert);
990
Comp_creator *comp_ne_creator(bool invert);
992
Item * all_any_subquery_creator(Item *left_expr,
993
chooser_compare_func_creator cmp,
995
SELECT_LEX *select_lex);
998
clean/setup table fields and map.
1000
@param table Table structure pointer (which should be setup)
1001
@param table_list TableList structure pointer (owner of Table)
1002
@param tablenr table number
1004
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
1006
table->used_fields= 0;
1007
table->const_table= 0;
1009
table->status= STATUS_NO_RECORD;
1010
table->maybe_null= table_list->outer_join;
1011
TableList *embedding= table_list->embedding;
1012
while (!table->maybe_null && embedding)
1014
table->maybe_null= embedding->outer_join;
1015
embedding= embedding->embedding;
1017
table->tablenr= tablenr;
1018
table->map= (table_map) 1 << tablenr;
1019
table->force_index= table_list->force_index;
1020
table->covering_keys= table->s->keys_for_keyread;
1021
table->merge_keys.clear_all();
1024
#include <drizzled/item_create.h> /* Factory API for creating Item_* instances */
1027
convert a hex digit into number.
1030
inline int hexchar_to_int(char c)
1032
if (c <= '9' && c >= '0')
1035
if (c <= 'f' && c >= 'a')
1041
Some functions that are different in the embedded library and the normal
1045
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
1046
void kill_delayed_threads(void);
1047
bool check_stack_overrun(THD *thd, long margin, unsigned char *dummy);
1049
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */