50
54
#include <drizzled/sql_table.h>
53
int mysql_create_db(Session *session, char *db, HA_CREATE_INFO *create, bool silent);
54
bool mysql_alter_db(Session *session, const char *db, HA_CREATE_INFO *create);
55
bool mysql_rm_db(Session *session,char *db,bool if_exists, bool silent);
56
bool mysql_change_db(Session *session, const LEX_STRING *new_db_name,
57
int mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create, bool silent);
58
bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create);
59
bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent);
60
bool mysql_change_db(THD *thd, const LEX_STRING *new_db_name,
57
61
bool force_switch);
58
bool mysql_opt_change_db(Session *session,
62
bool mysql_opt_change_db(THD *thd,
59
63
const LEX_STRING *new_db_name,
60
64
LEX_STRING *saved_db_name,
62
66
bool *cur_db_changed);
65
void write_bin_log(Session *session, bool clear_error,
69
void write_bin_log(THD *thd, bool clear_error,
66
70
char const *query, ulong query_length);
67
void mysql_binlog_send(Session* session, char* log_ident, my_off_t pos, uint16_t flags);
68
void mysql_client_binlog_statement(Session *session);
71
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
72
void mysql_client_binlog_statement(THD *thd);
70
74
/* sql_rename.cc */
71
bool mysql_rename_tables(Session *session, TableList *table_list, bool silent);
72
bool do_rename(Session *session, TableList *ren_table, char *new_db,
75
bool mysql_rename_tables(THD *thd, TableList *table_list, bool silent);
76
bool do_rename(THD *thd, TableList *ren_table, char *new_db,
73
77
char *new_table_name, char *new_table_alias,
77
void mysql_parse(Session *session, const char *inBuf, uint32_t length,
81
void mysql_parse(THD *thd, const char *inBuf, uint length,
78
82
const char ** semicolon);
80
bool mysql_test_parse_for_slave(Session *session,char *inBuf,uint32_t length);
84
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
83
87
bool is_update_query(enum enum_sql_command command);
85
bool alloc_query(Session *session, const char *packet, uint32_t packet_length);
89
bool alloc_query(THD *thd, const char *packet, uint packet_length);
87
void mysql_reset_session_for_next_command(Session *session);
91
void mysql_reset_thd_for_next_command(THD *thd);
89
93
void create_select_for_variable(const char *var_name);
117
142
bool table_def_init(void);
118
143
void table_def_free(void);
119
144
void assign_new_table_id(TABLE_SHARE *share);
120
uint32_t cached_open_tables(void);
121
uint32_t cached_table_definitions(void);
145
uint cached_open_tables(void);
146
uint cached_table_definitions(void);
123
148
/* drizzled.cc */
124
149
void kill_mysql(void);
125
void close_connection(Session *session, uint32_t errcode, bool lock);
150
void close_connection(THD *thd, uint errcode, bool lock);
127
152
/* sql_select.cc */
128
Table *create_virtual_tmp_table(Session *session, List<Create_field> &field_list);
153
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
131
bool mysql_xa_recover(Session *session);
156
bool mysql_xa_recover(THD *thd);
133
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
158
SORT_FIELD * make_unireg_sortorder(order_st *order, uint *length,
134
159
SORT_FIELD *sortorder);
135
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
160
int setup_order(THD *thd, Item **ref_pointer_array, TableList *tables,
136
161
List<Item> &fields, List <Item> &all_fields, order_st *order);
137
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
162
int setup_group(THD *thd, Item **ref_pointer_array, TableList *tables,
138
163
List<Item> &fields, List<Item> &all_fields, order_st *order,
139
164
bool *hidden_group_fields);
140
bool fix_inner_refs(Session *session, List<Item> &all_fields, SELECT_LEX *select,
165
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
141
166
Item **ref_pointer_array);
143
bool handle_select(Session *session, LEX *lex, select_result *result,
168
bool handle_select(THD *thd, LEX *lex, select_result *result,
144
169
ulong setup_tables_done_option);
145
bool mysql_select(Session *session, 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,
170
bool mysql_select(THD *thd, Item ***rref_pointer_array,
171
TableList *tables, uint wild_num, List<Item> &list,
172
COND *conds, uint og_num, order_st *order, order_st *group,
148
173
Item *having, order_st *proc_param, uint64_t select_type,
149
174
select_result *result, SELECT_LEX_UNIT *unit,
150
175
SELECT_LEX *select_lex);
151
void free_underlaid_joins(Session *session, SELECT_LEX *select);
152
bool mysql_explain_union(Session *session, SELECT_LEX_UNIT *unit,
176
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
177
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
153
178
select_result *result);
154
int mysql_explain_select(Session *session, SELECT_LEX *sl, char const *type,
179
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
155
180
select_result *result);
156
bool mysql_union(Session *session, LEX *lex, select_result *result,
181
bool mysql_union(THD *thd, LEX *lex, select_result *result,
157
182
SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
158
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
183
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
160
185
TableList *table));
161
bool mysql_derived_prepare(Session *session, LEX *lex, TableList *t);
162
bool mysql_derived_filling(Session *session, LEX *lex, TableList *t);
163
Field *create_tmp_field(Session *session, Table *table,Item *item, Item::Type type,
186
bool mysql_derived_prepare(THD *thd, LEX *lex, TableList *t);
187
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *t);
188
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
164
189
Item ***copy_func, Field **from_field,
165
190
Field **def_field,
166
191
bool group, bool modify_item,
167
192
bool table_cant_handle_bit_fields,
168
193
bool make_copy_field,
169
uint32_t convert_blob_length);
170
void sp_prepare_create_field(Session *session, Create_field *sql_field);
194
uint convert_blob_length);
195
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
171
196
int prepare_create_field(Create_field *sql_field,
172
uint32_t *blob_columns,
173
198
int *timestamps, int *timestamps_with_niladic,
174
199
int64_t table_flags);
175
bool mysql_create_table(Session *session,const char *db, const char *table_name,
200
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
176
201
HA_CREATE_INFO *create_info,
177
202
Alter_info *alter_info,
178
bool tmp_table, uint32_t select_field_count);
179
bool mysql_create_table_no_lock(Session *session, const char *db,
203
bool tmp_table, uint select_field_count);
204
bool mysql_create_table_no_lock(THD *thd, const char *db,
180
205
const char *table_name,
181
206
HA_CREATE_INFO *create_info,
182
207
Alter_info *alter_info,
183
bool tmp_table, uint32_t select_field_count,
184
bool lock_open_lock);
208
bool tmp_table, uint select_field_count);
186
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
210
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
187
211
HA_CREATE_INFO *create_info,
188
212
TableList *table_list,
189
213
Alter_info *alter_info,
190
uint32_t order_num, order_st *order, bool ignore);
191
bool mysql_recreate_table(Session *session, TableList *table_list);
192
bool mysql_create_like_table(Session *session, TableList *table,
214
uint order_num, order_st *order, bool ignore);
215
bool mysql_recreate_table(THD *thd, TableList *table_list);
216
bool mysql_create_like_table(THD *thd, TableList *table,
193
217
TableList *src_table,
194
218
HA_CREATE_INFO *create_info);
195
219
bool mysql_rename_table(handlerton *base, const char *old_db,
196
220
const char * old_name, const char *new_db,
197
const char * new_name, uint32_t flags);
198
bool mysql_prepare_update(Session *session, TableList *table_list,
199
Item **conds, uint32_t order_num, order_st *order);
200
int mysql_update(Session *session,TableList *tables,List<Item> &fields,
221
const char * new_name, uint flags);
222
bool mysql_prepare_update(THD *thd, TableList *table_list,
223
Item **conds, uint order_num, order_st *order);
224
int mysql_update(THD *thd,TableList *tables,List<Item> &fields,
201
225
List<Item> &values,COND *conds,
202
uint32_t order_num, order_st *order, ha_rows limit,
226
uint order_num, order_st *order, ha_rows limit,
203
227
enum enum_duplicates handle_duplicates, bool ignore);
204
bool mysql_multi_update(Session *session, TableList *table_list,
228
bool mysql_multi_update(THD *thd, TableList *table_list,
205
229
List<Item> *fields, List<Item> *values,
206
230
COND *conds, uint64_t options,
207
231
enum enum_duplicates handle_duplicates, bool ignore,
208
232
SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
209
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
233
bool mysql_prepare_insert(THD *thd, TableList *table_list, Table *table,
210
234
List<Item> &fields, List_item *values,
211
235
List<Item> &update_fields,
212
236
List<Item> &update_values, enum_duplicates duplic,
213
237
COND **where, bool select_insert,
214
238
bool check_fields, bool abort_on_warning);
215
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
239
bool mysql_insert(THD *thd,TableList *table,List<Item> &fields,
216
240
List<List_item> &values, List<Item> &update_fields,
217
241
List<Item> &update_values, enum_duplicates flag,
219
int check_that_all_fields_are_given_values(Session *session, Table *entry,
243
int check_that_all_fields_are_given_values(THD *thd, Table *entry,
220
244
TableList *table_list);
221
245
void prepare_triggers_for_insert_stmt(Table *table);
222
int mysql_prepare_delete(Session *session, TableList *table_list, Item **conds);
223
bool mysql_delete(Session *session, TableList *table_list, COND *conds,
246
int mysql_prepare_delete(THD *thd, TableList *table_list, Item **conds);
247
bool mysql_delete(THD *thd, TableList *table_list, COND *conds,
224
248
SQL_LIST *order, ha_rows rows, uint64_t options,
225
249
bool reset_auto_increment);
226
bool mysql_truncate(Session *session, TableList *table_list, bool dont_send_ok);
227
uint32_t create_table_def_key(Session *session, char *key, TableList *table_list,
250
bool mysql_truncate(THD *thd, TableList *table_list, bool dont_send_ok);
251
uint create_table_def_key(THD *thd, char *key, TableList *table_list,
229
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
230
uint32_t key_length, uint32_t db_flags, int *error);
253
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
254
uint key_length, uint db_flags, int *error);
231
255
void release_table_share(TABLE_SHARE *share, enum release_type type);
232
256
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
233
Table *open_ltable(Session *session, TableList *table_list, thr_lock_type update,
234
uint32_t lock_flags);
235
Table *open_table(Session *session, TableList *table_list, bool *refresh, uint32_t flags);
236
bool name_lock_locked_table(Session *session, TableList *tables);
237
bool reopen_name_locked_table(Session* session, TableList* table_list, bool link_in);
238
Table *table_cache_insert_placeholder(Session *session, const char *key,
239
uint32_t key_length);
240
bool lock_table_name_if_not_cached(Session *session, const char *db,
257
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type update,
259
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint flags);
260
bool name_lock_locked_table(THD *thd, TableList *tables);
261
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in);
262
Table *table_cache_insert_placeholder(THD *thd, const char *key,
264
bool lock_table_name_if_not_cached(THD *thd, const char *db,
241
265
const char *table_name, Table **table);
242
Table *find_locked_table(Session *session, const char *db,const char *table_name);
266
Table *find_locked_table(THD *thd, const char *db,const char *table_name);
243
267
void detach_merge_children(Table *table, bool clear_refs);
244
268
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
245
269
TableList *new_child_list, TableList **new_last);
246
270
bool reopen_table(Table *table);
247
bool reopen_tables(Session *session,bool get_locks,bool in_refresh);
248
void close_data_files_and_morph_locks(Session *session, const char *db,
271
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
272
void close_data_files_and_morph_locks(THD *thd, const char *db,
249
273
const char *table_name);
250
274
void close_handle_and_leave_table_as_lock(Table *table);
251
bool open_new_frm(Session *session, TABLE_SHARE *share, const char *alias,
252
uint32_t db_stat, uint32_t prgflag,
253
uint32_t ha_open_flags, Table *outparam,
275
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
276
uint db_stat, uint prgflag,
277
uint ha_open_flags, Table *outparam,
254
278
TableList *table_desc, MEM_ROOT *mem_root);
255
bool wait_for_tables(Session *session);
279
bool wait_for_tables(THD *thd);
256
280
bool table_is_used(Table *table, bool wait_for_name_lock);
257
Table *drop_locked_tables(Session *session,const char *db, const char *table_name);
258
void abort_locked_tables(Session *session,const char *db, const char *table_name);
259
void execute_init_command(Session *session, sys_var_str *init_command_var,
281
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name);
282
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
283
void execute_init_command(THD *thd, sys_var_str *init_command_var,
260
284
rw_lock_t *var_mutex);
261
285
extern Field *not_found_field;
262
286
extern Field *view_ref_found;
316
338
!my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
318
340
/* sql_handler.cc */
319
bool mysql_ha_open(Session *session, TableList *tables, bool reopen);
320
bool mysql_ha_close(Session *session, TableList *tables);
321
bool mysql_ha_read(Session *, TableList *,enum enum_ha_read_modes,char *,
341
bool mysql_ha_open(THD *thd, TableList *tables, bool reopen);
342
bool mysql_ha_close(THD *thd, TableList *tables);
343
bool mysql_ha_read(THD *, TableList *,enum enum_ha_read_modes,char *,
322
344
List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
323
void mysql_ha_flush(Session *session);
324
void mysql_ha_rm_tables(Session *session, TableList *tables, bool is_locked);
325
void mysql_ha_cleanup(Session *session);
345
void mysql_ha_flush(THD *thd);
346
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked);
347
void mysql_ha_cleanup(THD *thd);
327
349
/* sql_base.cc */
328
350
#define TMP_TABLE_KEY_EXTRA 8
329
void set_item_name(Item *item,char *pos,uint32_t length);
330
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum enum_field_types type,
351
void set_item_name(Item *item,char *pos,uint length);
352
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
331
353
char *length, char *decimal,
332
uint32_t type_modifier,
333
355
enum column_format_type column_format,
334
356
Item *default_value, Item *on_update_value,
335
357
LEX_STRING *comment,
336
358
char *change, List<String> *interval_list,
337
const CHARSET_INFO * const cs,
338
virtual_column_info *vcol_info);
339
Create_field * new_create_field(Session *session, char *field_name, enum_field_types type,
359
const CHARSET_INFO * const cs);
360
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
340
361
char *length, char *decimals,
341
uint32_t type_modifier,
342
363
Item *default_value, Item *on_update_value,
343
364
LEX_STRING *comment, char *change,
344
List<String> *interval_list, CHARSET_INFO *cs,
345
virtual_column_info *vcol_info);
365
List<String> *interval_list, CHARSET_INFO *cs);
346
366
void store_position_for_column(const char *name);
347
bool add_to_list(Session *session, SQL_LIST &list,Item *group,bool asc);
348
bool push_new_name_resolution_context(Session *session,
367
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
368
bool push_new_name_resolution_context(THD *thd,
349
369
TableList *left_op,
350
370
TableList *right_op);
351
371
void add_join_on(TableList *b,Item *expr);
352
372
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
353
373
SELECT_LEX *lex);
354
bool add_proc_to_list(Session *session, Item *item);
355
void unlink_open_table(Session *session, Table *find, bool unlock);
356
void drop_open_table(Session *session, Table *table, const char *db_name,
374
bool add_proc_to_list(THD *thd, Item *item);
375
void unlink_open_table(THD *thd, Table *find, bool unlock);
376
void drop_open_table(THD *thd, Table *table, const char *db_name,
357
377
const char *table_name);
358
378
void update_non_unique_table_error(TableList *update,
359
379
const char *operation,
390
410
RESOLVED_WITH_NO_ALIAS,
391
411
RESOLVED_AGAINST_ALIAS
393
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
413
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
394
414
find_item_error_report_type report_error,
395
415
enum_resolution_type *resolution);
396
416
bool get_key_map_from_key_list(key_map *map, Table *table,
397
417
List<String> *index_list);
398
bool insert_fields(Session *session, Name_resolution_context *context,
418
bool insert_fields(THD *thd, Name_resolution_context *context,
399
419
const char *db_name, const char *table_name,
400
420
List_iterator<Item> *it, bool any_privileges);
401
bool setup_tables(Session *session, Name_resolution_context *context,
421
bool setup_tables(THD *thd, Name_resolution_context *context,
402
422
List<TableList> *from_clause, TableList *tables,
403
423
TableList **leaves, bool select_insert);
404
bool setup_tables_and_check_access(Session *session,
424
bool setup_tables_and_check_access(THD *thd,
405
425
Name_resolution_context *context,
406
426
List<TableList> *from_clause,
407
427
TableList *tables,
408
428
TableList **leaves,
409
429
bool select_insert);
410
int setup_wild(Session *session, TableList *tables, List<Item> &fields,
411
List<Item> *sum_func_list, uint32_t wild_num);
412
bool setup_fields(Session *session, Item** ref_pointer_array,
430
int setup_wild(THD *thd, TableList *tables, List<Item> &fields,
431
List<Item> *sum_func_list, uint wild_num);
432
bool setup_fields(THD *thd, Item** ref_pointer_array,
413
433
List<Item> &item, enum_mark_columns mark_used_columns,
414
434
List<Item> *sum_func_list, bool allow_sum_func);
415
inline bool setup_fields_with_no_wrap(Session *session, Item **ref_pointer_array,
435
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
416
436
List<Item> &item,
417
437
enum_mark_columns mark_used_columns,
418
438
List<Item> *sum_func_list,
419
439
bool allow_sum_func)
422
res= setup_fields(session, ref_pointer_array, item, mark_used_columns, sum_func_list,
442
res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
426
int setup_conds(Session *session, TableList *tables, TableList *leaves,
446
int setup_conds(THD *thd, TableList *tables, TableList *leaves,
428
448
int setup_ftfuncs(SELECT_LEX* select);
429
int init_ftfuncs(Session *session, SELECT_LEX* select, bool no_order);
430
void wait_for_condition(Session *session, pthread_mutex_t *mutex,
449
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
450
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
431
451
pthread_cond_t *cond);
432
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
452
int open_tables(THD *thd, TableList **tables, uint *counter, uint flags);
433
453
/* open_and_lock_tables with optional derived handling */
434
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
454
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived);
435
455
/* simple open_and_lock_tables without derived handling */
436
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
456
inline int simple_open_n_lock_tables(THD *thd, TableList *tables)
438
return open_and_lock_tables_derived(session, tables, false);
458
return open_and_lock_tables_derived(thd, tables, false);
440
460
/* open_and_lock_tables with derived handling */
441
inline int open_and_lock_tables(Session *session, TableList *tables)
461
inline int open_and_lock_tables(THD *thd, TableList *tables)
443
return open_and_lock_tables_derived(session, tables, true);
463
return open_and_lock_tables_derived(thd, tables, true);
445
465
/* simple open_and_lock_tables without derived handling for single table */
446
Table *open_n_lock_single_table(Session *session, TableList *table_l,
466
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
447
467
thr_lock_type lock_type);
448
bool open_normal_and_derived_tables(Session *session, TableList *tables, uint32_t flags);
449
int lock_tables(Session *session, TableList *tables, uint32_t counter, bool *need_reopen);
450
int decide_logging_format(Session *session, TableList *tables);
451
Table *open_temporary_table(Session *session, const char *path, const char *db,
468
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint flags);
469
int lock_tables(THD *thd, TableList *tables, uint counter, bool *need_reopen);
470
int decide_logging_format(THD *thd, TableList *tables);
471
Table *open_temporary_table(THD *thd, const char *path, const char *db,
452
472
const char *table_name, bool link_in_list,
453
473
open_table_mode open_mode);
454
474
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
455
475
void free_io_cache(Table *entry);
456
476
void intern_close_table(Table *entry);
457
bool close_thread_table(Session *session, Table **table_ptr);
458
void close_temporary_tables(Session *session);
459
void close_tables_for_reopen(Session *session, TableList **tables);
477
bool close_thread_table(THD *thd, Table **table_ptr);
478
void close_temporary_tables(THD *thd);
479
void close_tables_for_reopen(THD *thd, TableList **tables);
460
480
TableList *find_table_in_list(TableList *table,
461
481
TableList *TableList::*link,
462
482
const char *db_name,
463
483
const char *table_name);
464
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
484
TableList *unique_table(THD *thd, TableList *table, TableList *table_list,
465
485
bool check_alias);
466
Table *find_temporary_table(Session *session, const char *db, const char *table_name);
467
Table *find_temporary_table(Session *session, TableList *table_list);
468
int drop_temporary_table(Session *session, TableList *table_list);
469
void close_temporary_table(Session *session, Table *table, bool free_share,
486
Table *find_temporary_table(THD *thd, const char *db, const char *table_name);
487
Table *find_temporary_table(THD *thd, TableList *table_list);
488
int drop_temporary_table(THD *thd, TableList *table_list);
489
void close_temporary_table(THD *thd, Table *table, bool free_share,
470
490
bool delete_table);
471
491
void close_temporary(Table *table, bool free_share, bool delete_table);
472
bool rename_temporary_table(Session* session, Table *table, const char *new_db,
492
bool rename_temporary_table(THD* thd, Table *table, const char *new_db,
473
493
const char *table_name);
474
494
void remove_db_from_cache(const char *db);
475
495
void flush_tables();
526
546
bool eval_const_cond(COND *cond);
528
548
/* sql_load.cc */
529
int mysql_load(Session *session, sql_exchange *ex, TableList *table_list,
549
int mysql_load(THD *thd, sql_exchange *ex, TableList *table_list,
530
550
List<Item> &fields_vars, List<Item> &set_fields,
531
551
List<Item> &set_values_list,
532
552
enum enum_duplicates handle_duplicates, bool ignore,
533
553
bool local_file);
534
int write_record(Session *session, Table *table, COPY_INFO *info);
554
int write_record(THD *thd, Table *table, COPY_INFO *info);
537
557
/* sql_test.cc */
538
558
void print_where(COND *cond,const char *info, enum_query_type query_type);
539
559
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,
560
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
561
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
542
562
double current_read_time, const char *info);
543
563
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
544
564
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
545
565
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,
568
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
569
uint *key_length, uint *keypart);
570
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
571
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
552
572
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);
573
void key_zero_nulls(uchar *tuple, KEY *key_info);
574
bool key_cmp_if_same(Table *form,const uchar *key,uint index,uint key_length);
575
void key_unpack(String *to,Table *form,uint index);
576
bool is_key_used(Table *table, uint idx, const MY_BITMAP *fields);
577
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
578
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
560
580
bool init_errmessage(void);
561
581
File open_binlog(IO_CACHE *log, const char *log_file_name,
562
582
const char **errmsg);
565
void refresh_status(Session *session);
585
extern void MYSQLerror(const char*);
586
void refresh_status(THD *thd);
566
587
bool mysql_rm_tmp_tables(void);
567
void handle_connection_in_main_thread(Session *session);
568
void create_thread_to_handle_connection(Session *session);
569
void unlink_session(Session *session);
570
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
588
void handle_connection_in_main_thread(THD *thd);
589
void create_thread_to_handle_connection(THD *thd);
590
void unlink_thd(THD *thd);
591
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
571
592
void flush_thread_cache();
573
594
/* item_func.cc */
574
595
extern bool check_reserved_words(LEX_STRING *name);
575
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
596
extern enum_field_types agg_field_type(Item **items, uint nitems);
578
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
579
char **err_pos, uint32_t *err_len, bool *set_warning);
580
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
599
uint64_t find_set(TYPELIB *lib, const char *x, uint length, const CHARSET_INFO * const cs,
600
char **err_pos, uint *err_len, bool *set_warning);
601
uint find_type(const TYPELIB *lib, const char *find, uint length,
581
602
bool part_match);
582
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
603
uint find_type2(const TYPELIB *lib, const char *find, uint length,
583
604
const CHARSET_INFO *cs);
584
605
void unhex_type2(TYPELIB *lib);
585
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
606
uint check_word(TYPELIB *lib, const char *val, const char *end,
586
607
const char **end_of_word);
587
608
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
588
609
const CHARSET_INFO * const cs);
591
bool is_keyword(const char *name, uint32_t len);
612
bool is_keyword(const char *name, uint len);
593
614
#define MY_DB_OPT_FILE "db.opt"
594
615
bool my_database_names_init(void);
595
616
void my_database_names_free(void);
596
617
bool check_db_dir_existence(const char *db_name);
597
bool load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create);
598
bool load_db_opt_by_name(Session *session, const char *db_name,
618
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
619
bool load_db_opt_by_name(THD *thd, const char *db_name,
599
620
HA_CREATE_INFO *db_create_info);
600
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name);
621
const CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
601
622
bool my_dbopt_init(void);
602
623
void my_dbopt_cleanup(void);
603
624
extern int creating_database; // How many database locks are made
750
775
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY 0x0010
751
776
#define DRIZZLE_LOCK_PERF_SCHEMA 0x0020
753
void mysql_unlock_tables(Session *session, DRIZZLE_LOCK *sql_lock);
754
void mysql_unlock_read_tables(Session *session, DRIZZLE_LOCK *sql_lock);
755
void mysql_unlock_some_tables(Session *session, Table **table,uint32_t count);
756
void mysql_lock_remove(Session *session, DRIZZLE_LOCK *locked,Table *table,
778
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
779
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
780
void mysql_unlock_some_tables(THD *thd, Table **table,uint count);
781
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,Table *table,
757
782
bool always_unlock);
758
void mysql_lock_abort(Session *session, Table *table, bool upgrade_lock);
759
void mysql_lock_downgrade_write(Session *session, Table *table,
783
void mysql_lock_abort(THD *thd, Table *table, bool upgrade_lock);
784
void mysql_lock_downgrade_write(THD *thd, Table *table,
760
785
thr_lock_type new_lock_type);
761
bool mysql_lock_abort_for_thread(Session *session, Table *table);
786
bool mysql_lock_abort_for_thread(THD *thd, Table *table);
762
787
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
763
TableList *mysql_lock_have_duplicate(Session *session, TableList *needle,
788
TableList *mysql_lock_have_duplicate(THD *thd, TableList *needle,
764
789
TableList *haystack);
765
bool lock_global_read_lock(Session *session);
766
void unlock_global_read_lock(Session *session);
767
bool wait_if_global_read_lock(Session *session, bool abort_on_refresh,
790
bool lock_global_read_lock(THD *thd);
791
void unlock_global_read_lock(THD *thd);
792
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
768
793
bool is_not_commit);
769
void start_waiting_global_read_lock(Session *session);
770
bool make_global_read_lock_block_commit(Session *session);
794
void start_waiting_global_read_lock(THD *thd);
795
bool make_global_read_lock_block_commit(THD *thd);
771
796
bool set_protect_against_global_read_lock(void);
772
797
void unset_protect_against_global_read_lock(void);
773
798
void broadcast_refresh(void);
774
int try_transactional_lock(Session *session, TableList *table_list);
775
int check_transactional_lock(Session *session, TableList *table_list);
776
int set_handler_table_locks(Session *session, TableList *table_list,
799
int try_transactional_lock(THD *thd, TableList *table_list);
800
int check_transactional_lock(THD *thd, TableList *table_list);
801
int set_handler_table_locks(THD *thd, TableList *table_list,
777
802
bool transactional);
779
804
/* Lock based on name */
780
int lock_and_wait_for_table_name(Session *session, TableList *table_list);
781
int lock_table_name(Session *session, TableList *table_list, bool check_in_use);
782
void unlock_table_name(Session *session, TableList *table_list);
783
bool wait_for_locked_table_names(Session *session, TableList *table_list);
784
bool lock_table_names(Session *session, TableList *table_list);
785
void unlock_table_names(Session *session, TableList *table_list,
805
int lock_and_wait_for_table_name(THD *thd, TableList *table_list);
806
int lock_table_name(THD *thd, TableList *table_list, bool check_in_use);
807
void unlock_table_name(THD *thd, TableList *table_list);
808
bool wait_for_locked_table_names(THD *thd, TableList *table_list);
809
bool lock_table_names(THD *thd, TableList *table_list);
810
void unlock_table_names(THD *thd, TableList *table_list,
786
811
TableList *last_table);
787
bool lock_table_names_exclusively(Session *session, TableList *table_list);
788
bool is_table_name_exclusively_locked_by_this_thread(Session *session,
812
bool lock_table_names_exclusively(THD *thd, TableList *table_list);
813
bool is_table_name_exclusively_locked_by_this_thread(THD *thd,
789
814
TableList *table_list);
790
bool is_table_name_exclusively_locked_by_this_thread(Session *session, unsigned char *key,
815
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
796
821
void unireg_init(ulong options);
797
822
void unireg_end(void) __attribute__((noreturn));
798
bool mysql_create_frm(Session *session, const char *file_name,
823
bool mysql_create_frm(THD *thd, const char *file_name,
799
824
const char *db, const char *table,
800
825
HA_CREATE_INFO *create_info,
801
826
List<Create_field> &create_field,
802
uint32_t key_count,KEY *key_info,handler *db_type);
803
int rea_create_table(Session *session, const char *path,
827
uint key_count,KEY *key_info,handler *db_type);
828
int rea_create_table(THD *thd, const char *path,
804
829
const char *db, const char *table_name,
805
830
HA_CREATE_INFO *create_info,
806
831
List<Create_field> &create_field,
807
uint32_t key_count,KEY *key_info,
832
uint key_count,KEY *key_info,
809
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
834
int format_number(uint inputflag,uint max_length,char * pos,uint length,
813
838
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
814
uint32_t key_length);
815
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
840
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
817
842
const char *table_name, const char *path);
818
843
void free_table_share(TABLE_SHARE *share);
819
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
844
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
820
845
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
821
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
822
uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
846
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
847
uint db_stat, uint prgflag, uint ha_open_flags,
823
848
Table *outparam, open_table_mode open_mode);
824
int readfrm(const char *name, unsigned char **data, size_t *length);
825
int writefrm(const char* name, const unsigned char* data, size_t len);
849
int readfrm(const char *name, uchar **data, size_t *length);
850
int writefrm(const char* name, const uchar* data, size_t len);
826
851
int closefrm(Table *table, bool free_share);
827
int read_string(File file, unsigned char* *to, size_t length);
852
int read_string(File file, uchar* *to, size_t length);
828
853
void free_blobs(Table *table);
829
854
int set_zone(int nr,int min_zone,int max_zone);
830
uint32_t convert_period_to_month(uint32_t period);
831
uint32_t convert_month_to_period(uint32_t month);
832
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
834
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *not_exist);
835
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
836
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
837
DRIZZLE_TIME *l_time, uint32_t flags);
855
ulong convert_period_to_month(ulong period);
856
ulong convert_month_to_period(ulong month);
857
void get_date_from_daynr(long daynr,uint *year, uint *month,
859
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
860
bool str_to_time_with_warn(const char *str,uint length,DRIZZLE_TIME *l_time);
861
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
862
DRIZZLE_TIME *l_time, uint flags);
838
863
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
839
864
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
841
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
866
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
842
867
const char *str_val,
843
uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
868
uint str_length, timestamp_type time_type,
844
869
const char *field_name);
846
871
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
865
890
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
867
892
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
868
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
893
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
869
894
Item *warn_item, bool *is_null);
871
896
int test_if_number(char *str,int *res,bool allow_wildcards);
872
void change_byte(unsigned char *,uint,char,char);
873
void init_read_record(READ_RECORD *info, Session *session, Table *reg_form,
897
void change_byte(uchar *,uint,char,char);
898
void init_read_record(READ_RECORD *info, THD *thd, Table *reg_form,
874
899
SQL_SELECT *select,
875
900
int use_record_cache, bool print_errors);
876
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table,
877
bool print_error, uint32_t idx);
901
void init_read_record_idx(READ_RECORD *info, THD *thd, Table *table,
902
bool print_error, uint idx);
878
903
void end_read_record(READ_RECORD *info);
879
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
880
uint32_t s_length, SQL_SELECT *select,
904
ha_rows filesort(THD *thd, Table *form,struct st_sort_field *sortorder,
905
uint s_length, SQL_SELECT *select,
881
906
ha_rows max_rows, bool sort_positions,
882
907
ha_rows *examined_rows);
883
908
void filesort_free_buffers(Table *table, bool full);
884
void change_double_for_sort(double nr,unsigned char *to);
909
void change_double_for_sort(double nr,uchar *to);
885
910
double my_double_round(double value, int64_t dec, bool dec_unsigned,
887
912
int get_quick_record(SQL_SELECT *select);
889
914
int calc_weekday(long daynr,bool sunday_first_day_of_week);
890
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
891
void find_date(char *pos,uint32_t *vek,uint32_t flag);
915
uint calc_week(DRIZZLE_TIME *l_time, uint week_behaviour, uint *year);
916
void find_date(char *pos,uint *vek,uint flag);
892
917
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
893
918
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
894
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
895
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
919
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
920
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
896
921
const char *newname);
897
922
ulong next_io_size(ulong pos);
898
void append_unescaped(String *res, const char *pos, uint32_t length);
899
int create_frm(Session *session, const char *name, const char *db, const char *table,
900
uint32_t reclength, unsigned char *fileinfo,
901
HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
923
void append_unescaped(String *res, const char *pos, uint length);
924
int create_frm(THD *thd, const char *name, const char *db, const char *table,
925
uint reclength, uchar *fileinfo,
926
HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
902
927
int rename_file_ext(const char * from,const char * to,const char * ext);
903
928
bool check_db_name(LEX_STRING *db);
904
929
bool check_column_name(const char *name);
905
bool check_table_name(const char *name, uint32_t length);
930
bool check_table_name(const char *name, uint length);
906
931
char *get_field(MEM_ROOT *mem, Field *field);
907
932
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
908
933
char *fn_rext(char *name);
910
935
/* Conversion functions */
911
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
912
const char *table, const char *ext, uint32_t flags);
936
uint build_table_filename(char *buff, size_t bufflen, const char *db,
937
const char *table, const char *ext, uint flags);
914
939
#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#"
915
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH sizeof(MYSQL50_TABLE_NAME_PREFIX)
940
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH 9
917
942
/* Flags for conversion functions. */
918
943
#define FN_FROM_IS_TMP (1 << 0)