~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

Cleanup around SAFEMALLOC

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
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.
9
 
 *
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.
14
 
 *
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
18
 
 */
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/**
21
17
  @file
23
19
  @details
24
20
  Mostly this file is used in the server. But a little part of it is used in
25
21
  mysqlbinlog too (definition of SELECT_DISTINCT and others).
 
22
  The consequence is that 90% of the file is wrapped in \#ifndef DRIZZLE_CLIENT,
 
23
  except the part which must be in the server and in the client.
26
24
 
27
25
  @TODO Name this file better. "priv" could mean private, privileged, privileges.
 
26
 
 
27
  @TODO Get rid of the DRIZZLE_CLIENT and DRIZZLE_SERVER conditionals
28
28
*/
29
29
 
30
30
#ifndef DRIZZLE_SERVER_SERVER_INCLUDES_H
50
50
#include <drizzled/sql_table.h>
51
51
 
52
52
/* sql_db.cc */
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,
 
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,
57
57
                     bool force_switch);
58
 
bool mysql_opt_change_db(Session *session,
 
58
bool mysql_opt_change_db(THD *thd,
59
59
                         const LEX_STRING *new_db_name,
60
60
                         LEX_STRING *saved_db_name,
61
61
                         bool force_switch,
62
62
                         bool *cur_db_changed);
63
63
 
64
64
/* sql_repl.cc */
65
 
void write_bin_log(Session *session, bool clear_error,
 
65
void write_bin_log(THD *thd, bool clear_error,
66
66
                   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);
 
67
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
 
68
void mysql_client_binlog_statement(THD *thd);
69
69
 
70
70
/* 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,
 
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
73
                      char *new_table_name, char *new_table_alias,
74
74
                      bool skip_error);
75
75
 
76
76
/* sql_parse.cc */
77
 
void mysql_parse(Session *session, const char *inBuf, uint32_t length,
 
77
void mysql_parse(THD *thd, const char *inBuf, uint length,
78
78
                 const char ** semicolon);
79
79
 
80
 
bool mysql_test_parse_for_slave(Session *session,char *inBuf,uint32_t length);
 
80
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
81
81
 
82
82
 
83
83
bool is_update_query(enum enum_sql_command command);
84
84
 
85
 
bool alloc_query(Session *session, const char *packet, uint32_t packet_length);
 
85
bool alloc_query(THD *thd, const char *packet, uint packet_length);
86
86
 
87
 
void mysql_reset_session_for_next_command(Session *session);
 
87
void mysql_reset_thd_for_next_command(THD *thd);
88
88
 
89
89
void create_select_for_variable(const char *var_name);
90
90
 
94
94
 
95
95
void init_update_queries(void);
96
96
 
97
 
bool do_command(Session *session);
98
 
 
99
 
bool dispatch_command(enum enum_server_command command, Session *session,
100
 
                      char* packet, uint32_t packet_length);
101
 
 
102
 
void log_slow_statement(Session *session);
103
 
 
104
 
bool append_file_to_dir(Session *session, const char **filename_ptr, 
 
97
bool do_command(THD *thd);
 
98
 
 
99
bool dispatch_command(enum enum_server_command command, THD *thd,
 
100
                      char* packet, uint packet_length);
 
101
 
 
102
void log_slow_statement(THD *thd);
 
103
 
 
104
bool append_file_to_dir(THD *thd, const char **filename_ptr, 
105
105
                        const char *table_name);
106
106
 
107
 
bool reload_cache(Session *session, ulong options, TableList *tables, bool *write_to_binlog);
 
107
bool reload_cache(THD *thd, ulong options, TableList *tables, bool *write_to_binlog);
108
108
 
109
109
bool check_simple_select();
110
110
 
 
111
/* @TODO <UNUSED> */
111
112
void mysql_init_select(LEX *lex);
112
113
bool mysql_new_select(LEX *lex, bool move_down);
 
114
void init_max_user_conn(void);
 
115
void free_max_user_conn(void);
 
116
pthread_handler_t handle_bootstrap(void *arg);
 
117
int mysql_execute_command(THD *thd);
 
118
bool check_dup(const char *db, const char *name, TableList *tables);
 
119
bool check_table_access(THD *thd, ulong want_access, TableList *tables,
 
120
                        bool no_errors,
 
121
                        bool any_combination_of_privileges_will_do,
 
122
                        uint number);
 
123
/*
 
124
  General routine to change field->ptr of a NULL-terminated array of Field
 
125
  objects. Useful when needed to call val_int, val_str or similar and the
 
126
  field data is not in table->record[0] but in some other structure.
 
127
  set_key_field_ptr changes all fields of an index using a key_info object.
 
128
  All methods presume that there is at least one field to change.
 
129
*/
 
130
void set_field_ptr(Field **ptr, const uchar *new_buf, const uchar *old_buf);
 
131
void set_key_field_ptr(KEY *key_info, const uchar *new_buf,
 
132
                       const uchar *old_buf);
 
133
/* </UNUSED> */
113
134
 
114
135
/* sql_base.cc */
115
136
void table_cache_free(void);
117
138
bool table_def_init(void);
118
139
void table_def_free(void);
119
140
void assign_new_table_id(TABLE_SHARE *share);
120
 
uint32_t cached_open_tables(void);
121
 
uint32_t cached_table_definitions(void);
 
141
uint cached_open_tables(void);
 
142
uint cached_table_definitions(void);
122
143
 
123
144
/* drizzled.cc */
124
145
void kill_mysql(void);
125
 
void close_connection(Session *session, uint32_t errcode, bool lock);
 
146
void close_connection(THD *thd, uint errcode, bool lock);
126
147
 
127
148
/* sql_select.cc */
128
 
Table *create_virtual_tmp_table(Session *session, List<Create_field> &field_list);
 
149
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
129
150
 
130
151
/* handler.cc */
131
 
bool mysql_xa_recover(Session *session);
 
152
bool mysql_xa_recover(THD *thd);
132
153
 
133
 
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
154
SORT_FIELD * make_unireg_sortorder(order_st *order, uint *length,
134
155
                                  SORT_FIELD *sortorder);
135
 
int setup_order(Session *session, Item **ref_pointer_array, TableList *tables,
 
156
int setup_order(THD *thd, Item **ref_pointer_array, TableList *tables,
136
157
                List<Item> &fields, List <Item> &all_fields, order_st *order);
137
 
int setup_group(Session *session, Item **ref_pointer_array, TableList *tables,
 
158
int setup_group(THD *thd, Item **ref_pointer_array, TableList *tables,
138
159
                List<Item> &fields, List<Item> &all_fields, order_st *order,
139
160
                bool *hidden_group_fields);
140
 
bool fix_inner_refs(Session *session, List<Item> &all_fields, SELECT_LEX *select,
 
161
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
141
162
                   Item **ref_pointer_array);
142
163
 
143
 
bool handle_select(Session *session, LEX *lex, select_result *result,
 
164
bool handle_select(THD *thd, LEX *lex, select_result *result,
144
165
                   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,
 
166
bool mysql_select(THD *thd, Item ***rref_pointer_array,
 
167
                  TableList *tables, uint wild_num,  List<Item> &list,
 
168
                  COND *conds, uint og_num, order_st *order, order_st *group,
148
169
                  Item *having, order_st *proc_param, uint64_t select_type, 
149
170
                  select_result *result, SELECT_LEX_UNIT *unit, 
150
171
                  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,
 
172
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
 
173
bool mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit,
153
174
                         select_result *result);
154
 
int mysql_explain_select(Session *session, SELECT_LEX *sl, char const *type,
 
175
int mysql_explain_select(THD *thd, SELECT_LEX *sl, char const *type,
155
176
                         select_result *result);
156
 
bool mysql_union(Session *session, LEX *lex, select_result *result,
 
177
bool mysql_union(THD *thd, LEX *lex, select_result *result,
157
178
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
158
 
bool mysql_handle_derived(LEX *lex, bool (*processor)(Session *session,
 
179
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
159
180
                                                      LEX *lex,
160
181
                                                      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,
 
182
bool mysql_derived_prepare(THD *thd, LEX *lex, TableList *t);
 
183
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *t);
 
184
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
164
185
                        Item ***copy_func, Field **from_field,
165
186
                        Field **def_field,
166
187
                        bool group, bool modify_item,
167
188
                        bool table_cant_handle_bit_fields,
168
189
                        bool make_copy_field,
169
 
                        uint32_t convert_blob_length);
170
 
void sp_prepare_create_field(Session *session, Create_field *sql_field);
 
190
                        uint convert_blob_length);
 
191
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
171
192
int prepare_create_field(Create_field *sql_field, 
172
 
                         uint32_t *blob_columns, 
 
193
                         uint *blob_columns, 
173
194
                         int *timestamps, int *timestamps_with_niladic,
174
195
                         int64_t table_flags);
175
 
bool mysql_create_table(Session *session,const char *db, const char *table_name,
 
196
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
176
197
                        HA_CREATE_INFO *create_info,
177
198
                        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,
 
199
                        bool tmp_table, uint select_field_count);
 
200
bool mysql_create_table_no_lock(THD *thd, const char *db,
180
201
                                const char *table_name,
181
202
                                HA_CREATE_INFO *create_info,
182
203
                                Alter_info *alter_info,
183
 
                                bool tmp_table, uint32_t select_field_count,
184
 
                                bool lock_open_lock);
 
204
                                bool tmp_table, uint select_field_count);
185
205
 
186
 
bool mysql_alter_table(Session *session, char *new_db, char *new_name,
 
206
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
187
207
                       HA_CREATE_INFO *create_info,
188
208
                       TableList *table_list,
189
209
                       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,
 
210
                       uint order_num, order_st *order, bool ignore);
 
211
bool mysql_recreate_table(THD *thd, TableList *table_list);
 
212
bool mysql_create_like_table(THD *thd, TableList *table,
193
213
                             TableList *src_table,
194
214
                             HA_CREATE_INFO *create_info);
195
215
bool mysql_rename_table(handlerton *base, const char *old_db,
196
216
                        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,
 
217
                        const char * new_name, uint flags);
 
218
bool mysql_prepare_update(THD *thd, TableList *table_list,
 
219
                          Item **conds, uint order_num, order_st *order);
 
220
int mysql_update(THD *thd,TableList *tables,List<Item> &fields,
201
221
                 List<Item> &values,COND *conds,
202
 
                 uint32_t order_num, order_st *order, ha_rows limit,
 
222
                 uint order_num, order_st *order, ha_rows limit,
203
223
                 enum enum_duplicates handle_duplicates, bool ignore);
204
 
bool mysql_multi_update(Session *session, TableList *table_list,
 
224
bool mysql_multi_update(THD *thd, TableList *table_list,
205
225
                        List<Item> *fields, List<Item> *values,
206
226
                        COND *conds, uint64_t options,
207
227
                        enum enum_duplicates handle_duplicates, bool ignore,
208
228
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
209
 
bool mysql_prepare_insert(Session *session, TableList *table_list, Table *table,
 
229
bool mysql_prepare_insert(THD *thd, TableList *table_list, Table *table,
210
230
                          List<Item> &fields, List_item *values,
211
231
                          List<Item> &update_fields,
212
232
                          List<Item> &update_values, enum_duplicates duplic,
213
233
                          COND **where, bool select_insert,
214
234
                          bool check_fields, bool abort_on_warning);
215
 
bool mysql_insert(Session *session,TableList *table,List<Item> &fields,
 
235
bool mysql_insert(THD *thd,TableList *table,List<Item> &fields,
216
236
                  List<List_item> &values, List<Item> &update_fields,
217
237
                  List<Item> &update_values, enum_duplicates flag,
218
238
                  bool ignore);
219
 
int check_that_all_fields_are_given_values(Session *session, Table *entry,
 
239
int check_that_all_fields_are_given_values(THD *thd, Table *entry,
220
240
                                           TableList *table_list);
221
241
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,
 
242
int mysql_prepare_delete(THD *thd, TableList *table_list, Item **conds);
 
243
bool mysql_delete(THD *thd, TableList *table_list, COND *conds,
224
244
                  SQL_LIST *order, ha_rows rows, uint64_t options,
225
245
                  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,
 
246
bool mysql_truncate(THD *thd, TableList *table_list, bool dont_send_ok);
 
247
uint create_table_def_key(THD *thd, char *key, TableList *table_list,
228
248
                          bool tmp_table);
229
 
TABLE_SHARE *get_table_share(Session *session, TableList *table_list, char *key,
230
 
                             uint32_t key_length, uint32_t db_flags, int *error);
 
249
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
 
250
                             uint key_length, uint db_flags, int *error);
231
251
void release_table_share(TABLE_SHARE *share, enum release_type type);
232
252
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,
 
253
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type update,
 
254
                   uint lock_flags);
 
255
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint flags);
 
256
bool name_lock_locked_table(THD *thd, TableList *tables);
 
257
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in);
 
258
Table *table_cache_insert_placeholder(THD *thd, const char *key,
 
259
                                      uint key_length);
 
260
bool lock_table_name_if_not_cached(THD *thd, const char *db,
241
261
                                   const char *table_name, Table **table);
242
 
Table *find_locked_table(Session *session, const char *db,const char *table_name);
 
262
Table *find_locked_table(THD *thd, const char *db,const char *table_name);
243
263
void detach_merge_children(Table *table, bool clear_refs);
244
264
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
245
265
                          TableList *new_child_list, TableList **new_last);
246
266
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,
 
267
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
 
268
void close_data_files_and_morph_locks(THD *thd, const char *db,
249
269
                                      const char *table_name);
250
270
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,
 
271
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
 
272
                  uint db_stat, uint prgflag,
 
273
                  uint ha_open_flags, Table *outparam,
254
274
                  TableList *table_desc, MEM_ROOT *mem_root);
255
 
bool wait_for_tables(Session *session);
 
275
bool wait_for_tables(THD *thd);
256
276
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,
 
277
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name);
 
278
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
 
279
void execute_init_command(THD *thd, sys_var_str *init_command_var,
260
280
                          rw_lock_t *var_mutex);
261
281
extern Field *not_found_field;
262
282
extern Field *view_ref_found;
265
285
                                  IGNORE_ERRORS, REPORT_EXCEPT_NON_UNIQUE,
266
286
                                  IGNORE_EXCEPT_NON_UNIQUE};
267
287
Field *
268
 
find_field_in_tables(Session *session, Item_ident *item,
 
288
find_field_in_tables(THD *thd, Item_ident *item,
269
289
                     TableList *first_table, TableList *last_table,
270
290
                     Item **ref, find_item_error_report_type report_error,
271
291
                     bool check_privileges, bool register_tree_change);
272
292
Field *
273
 
find_field_in_table_ref(Session *session, TableList *table_list,
274
 
                        const char *name, uint32_t length,
 
293
find_field_in_table_ref(THD *thd, TableList *table_list,
 
294
                        const char *name, uint length,
275
295
                        const char *item_name, const char *db_name,
276
296
                        const char *table_name, Item **ref,
277
297
                        bool check_privileges, bool allow_rowid,
278
 
                        uint32_t *cached_field_index_ptr,
 
298
                        uint *cached_field_index_ptr,
279
299
                        bool register_tree_change, TableList **actual_table);
280
300
Field *
281
 
find_field_in_table(Session *session, Table *table, const char *name, uint32_t length,
282
 
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
 
301
find_field_in_table(THD *thd, Table *table, const char *name, uint length,
 
302
                    bool allow_rowid, uint *cached_field_index_ptr);
283
303
Field *
284
304
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);
287
305
 
288
306
/* sql_do.cc */
289
 
bool mysql_do(Session *session, List<Item> &values);
 
307
bool mysql_do(THD *thd, List<Item> &values);
290
308
 
291
309
/* sql_analyse.h */
292
310
bool append_escaped(String *to_str, String *from_str);
301
319
extern LEX_STRING SLOW_LOG_NAME;
302
320
 
303
321
extern const LEX_STRING partition_keywords[];
304
 
ST_SCHEMA_TABLE *find_schema_table(Session *session, const char* table_name);
 
322
ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name);
305
323
ST_SCHEMA_TABLE *get_schema_table(enum enum_schema_tables schema_table_idx);
306
 
int prepare_schema_table(Session *session, LEX *lex, Table_ident *table_ident,
 
324
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
307
325
                         enum enum_schema_tables schema_table_idx);
308
 
int make_schema_select(Session *session,  SELECT_LEX *sel,
 
326
int make_schema_select(THD *thd,  SELECT_LEX *sel,
309
327
                       enum enum_schema_tables schema_table_idx);
310
 
int mysql_schema_table(Session *session, LEX *lex, TableList *table_list);
 
328
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list);
311
329
bool get_schema_tables_result(JOIN *join,
312
330
                              enum enum_schema_table_state executed_place);
313
331
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
316
334
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
317
335
 
318
336
/* 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 *,
 
337
bool mysql_ha_open(THD *thd, TableList *tables, bool reopen);
 
338
bool mysql_ha_close(THD *thd, TableList *tables);
 
339
bool mysql_ha_read(THD *, TableList *,enum enum_ha_read_modes,char *,
322
340
                   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);
 
341
void mysql_ha_flush(THD *thd);
 
342
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked);
 
343
void mysql_ha_cleanup(THD *thd);
326
344
 
327
345
/* sql_base.cc */
328
346
#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,
 
347
void set_item_name(Item *item,char *pos,uint length);
 
348
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
331
349
                       char *length, char *decimal,
332
 
                       uint32_t type_modifier,
 
350
                       uint type_modifier,
333
351
                       enum column_format_type column_format,
334
352
                       Item *default_value, Item *on_update_value,
335
353
                       LEX_STRING *comment,
336
354
                       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,
 
355
                       const CHARSET_INFO * const cs);
 
356
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
340
357
                                char *length, char *decimals,
341
 
                                uint32_t type_modifier, 
 
358
                                uint type_modifier, 
342
359
                                Item *default_value, Item *on_update_value,
343
360
                                LEX_STRING *comment, char *change, 
344
 
                                List<String> *interval_list, CHARSET_INFO *cs,
345
 
                                virtual_column_info *vcol_info);
 
361
                                List<String> *interval_list, CHARSET_INFO *cs);
346
362
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,
 
363
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
 
364
bool push_new_name_resolution_context(THD *thd,
349
365
                                      TableList *left_op,
350
366
                                      TableList *right_op);
351
367
void add_join_on(TableList *b,Item *expr);
352
368
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
353
369
                      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,
 
370
bool add_proc_to_list(THD *thd, Item *item);
 
371
void unlink_open_table(THD *thd, Table *find, bool unlock);
 
372
void drop_open_table(THD *thd, Table *table, const char *db_name,
357
373
                     const char *table_name);
358
374
void update_non_unique_table_error(TableList *update,
359
375
                                   const char *operation,
390
406
  RESOLVED_WITH_NO_ALIAS,
391
407
  RESOLVED_AGAINST_ALIAS
392
408
};
393
 
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
 
409
Item ** find_item_in_list(Item *item, List<Item> &items, uint *counter,
394
410
                          find_item_error_report_type report_error,
395
411
                          enum_resolution_type *resolution);
396
412
bool get_key_map_from_key_list(key_map *map, Table *table,
397
413
                               List<String> *index_list);
398
 
bool insert_fields(Session *session, Name_resolution_context *context,
 
414
bool insert_fields(THD *thd, Name_resolution_context *context,
399
415
                   const char *db_name, const char *table_name,
400
416
                   List_iterator<Item> *it, bool any_privileges);
401
 
bool setup_tables(Session *session, Name_resolution_context *context,
 
417
bool setup_tables(THD *thd, Name_resolution_context *context,
402
418
                  List<TableList> *from_clause, TableList *tables,
403
419
                  TableList **leaves, bool select_insert);
404
 
bool setup_tables_and_check_access(Session *session, 
 
420
bool setup_tables_and_check_access(THD *thd, 
405
421
                                   Name_resolution_context *context,
406
422
                                   List<TableList> *from_clause, 
407
423
                                   TableList *tables, 
408
424
                                   TableList **leaves, 
409
425
                                   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,
 
426
int setup_wild(THD *thd, TableList *tables, List<Item> &fields,
 
427
               List<Item> *sum_func_list, uint wild_num);
 
428
bool setup_fields(THD *thd, Item** ref_pointer_array,
413
429
                  List<Item> &item, enum_mark_columns mark_used_columns,
414
430
                  List<Item> *sum_func_list, bool allow_sum_func);
415
 
inline bool setup_fields_with_no_wrap(Session *session, Item **ref_pointer_array,
 
431
inline bool setup_fields_with_no_wrap(THD *thd, Item **ref_pointer_array,
416
432
                                      List<Item> &item,
417
433
                                      enum_mark_columns mark_used_columns,
418
434
                                      List<Item> *sum_func_list,
419
435
                                      bool allow_sum_func)
420
436
{
421
437
  bool res;
422
 
  res= setup_fields(session, ref_pointer_array, item, mark_used_columns, sum_func_list,
 
438
  res= setup_fields(thd, ref_pointer_array, item, mark_used_columns, sum_func_list,
423
439
                    allow_sum_func);
424
440
  return res;
425
441
}
426
 
int setup_conds(Session *session, TableList *tables, TableList *leaves,
 
442
int setup_conds(THD *thd, TableList *tables, TableList *leaves,
427
443
                COND **conds);
428
444
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,
 
445
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
 
446
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
431
447
                        pthread_cond_t *cond);
432
 
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
 
448
int open_tables(THD *thd, TableList **tables, uint *counter, uint flags);
433
449
/* open_and_lock_tables with optional derived handling */
434
 
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
 
450
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived);
435
451
/* simple open_and_lock_tables without derived handling */
436
 
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
 
452
inline int simple_open_n_lock_tables(THD *thd, TableList *tables)
437
453
{
438
 
  return open_and_lock_tables_derived(session, tables, false);
 
454
  return open_and_lock_tables_derived(thd, tables, false);
439
455
}
440
456
/* open_and_lock_tables with derived handling */
441
 
inline int open_and_lock_tables(Session *session, TableList *tables)
 
457
inline int open_and_lock_tables(THD *thd, TableList *tables)
442
458
{
443
 
  return open_and_lock_tables_derived(session, tables, true);
 
459
  return open_and_lock_tables_derived(thd, tables, true);
444
460
}
445
461
/* simple open_and_lock_tables without derived handling for single table */
446
 
Table *open_n_lock_single_table(Session *session, TableList *table_l,
 
462
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
447
463
                                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,
 
464
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint flags);
 
465
int lock_tables(THD *thd, TableList *tables, uint counter, bool *need_reopen);
 
466
int decide_logging_format(THD *thd, TableList *tables);
 
467
Table *open_temporary_table(THD *thd, const char *path, const char *db,
452
468
                            const char *table_name, bool link_in_list,
453
469
                            open_table_mode open_mode);
454
470
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
455
471
void free_io_cache(Table *entry);
456
472
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);
 
473
bool close_thread_table(THD *thd, Table **table_ptr);
 
474
void close_temporary_tables(THD *thd);
 
475
void close_tables_for_reopen(THD *thd, TableList **tables);
460
476
TableList *find_table_in_list(TableList *table,
461
477
                               TableList *TableList::*link,
462
478
                               const char *db_name,
463
479
                               const char *table_name);
464
 
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
 
480
TableList *unique_table(THD *thd, TableList *table, TableList *table_list,
465
481
                         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,
 
482
Table *find_temporary_table(THD *thd, const char *db, const char *table_name);
 
483
Table *find_temporary_table(THD *thd, TableList *table_list);
 
484
int drop_temporary_table(THD *thd, TableList *table_list);
 
485
void close_temporary_table(THD *thd, Table *table, bool free_share,
470
486
                           bool delete_table);
471
487
void close_temporary(Table *table, bool free_share, bool delete_table);
472
 
bool rename_temporary_table(Session* session, Table *table, const char *new_db,
 
488
bool rename_temporary_table(THD* thd, Table *table, const char *new_db,
473
489
                            const char *table_name);
474
490
void remove_db_from_cache(const char *db);
475
491
void flush_tables();
478
494
 
479
495
/* bits for last argument to remove_table_from_cache() */
480
496
#define RTFC_NO_FLAG                0x0000
481
 
#define RTFC_OWNED_BY_Session_FLAG      0x0001
 
497
#define RTFC_OWNED_BY_THD_FLAG      0x0001
482
498
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
483
499
#define RTFC_CHECK_KILLED_FLAG      0x0004
484
 
bool remove_table_from_cache(Session *session, const char *db, const char *table,
485
 
                             uint32_t flags);
 
500
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
 
501
                             uint flags);
486
502
 
487
503
#define NORMAL_PART_NAME 0
488
504
#define TEMP_PART_NAME 1
495
511
#define WFRM_PACK_FRM 4
496
512
#define WFRM_KEEP_SHARE 8
497
513
 
498
 
bool close_cached_tables(Session *session, TableList *tables, bool have_lock,
 
514
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
499
515
                         bool wait_for_refresh, bool wait_for_placeholders);
500
 
bool close_cached_connection_tables(Session *session, bool wait_for_refresh,
 
516
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
501
517
                                    LEX_STRING *connect_string,
502
518
                                    bool have_lock= false);
503
519
void copy_field_from_tmp_record(Field *field,int offset);
504
 
bool fill_record(Session * session, List<Item> &fields, List<Item> &values, bool ignore_errors);
505
 
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors);
506
 
OPEN_TableList *list_open_tables(Session *session, const char *db, const char *wild);
 
520
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
 
521
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
 
522
OPEN_TableList *list_open_tables(THD *thd, const char *db, const char *wild);
507
523
 
508
524
inline TableList *find_table_in_global_list(TableList *table,
509
525
                                             const char *db_name,
526
542
bool eval_const_cond(COND *cond);
527
543
 
528
544
/* sql_load.cc */
529
 
int mysql_load(Session *session, sql_exchange *ex, TableList *table_list,
 
545
int mysql_load(THD *thd, sql_exchange *ex, TableList *table_list,
530
546
                List<Item> &fields_vars, List<Item> &set_fields,
531
547
                List<Item> &set_values_list,
532
548
                enum enum_duplicates handle_duplicates, bool ignore,
533
549
                bool local_file);
534
 
int write_record(Session *session, Table *table, COPY_INFO *info);
 
550
int write_record(THD *thd, Table *table, COPY_INFO *info);
535
551
 
536
552
 
537
553
/* sql_test.cc */
538
554
void print_where(COND *cond,const char *info, enum_query_type query_type);
539
555
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,
 
556
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
 
557
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
542
558
                double current_read_time, const char *info);
543
559
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
544
560
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
545
561
void mysql_print_status();
546
562
 
547
563
/* key.cc */
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,
 
564
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
 
565
                 uint *key_length, uint *keypart);
 
566
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
 
567
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
552
568
                 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);
 
569
void key_zero_nulls(uchar *tuple, KEY *key_info);
 
570
bool key_cmp_if_same(Table *form,const uchar *key,uint index,uint key_length);
 
571
void key_unpack(String *to,Table *form,uint index);
 
572
bool is_key_used(Table *table, uint idx, const MY_BITMAP *fields);
 
573
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
 
574
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
559
575
 
560
576
bool init_errmessage(void);
561
577
File open_binlog(IO_CACHE *log, const char *log_file_name,
563
579
 
564
580
/* mysqld.cc */
565
581
extern void MYSQLerror(const char*);
566
 
void refresh_status(Session *session);
 
582
void refresh_status(THD *thd);
567
583
bool mysql_rm_tmp_tables(void);
568
 
void handle_connection_in_main_thread(Session *session);
569
 
void create_thread_to_handle_connection(Session *session);
570
 
void unlink_session(Session *session);
571
 
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
 
584
void handle_connection_in_main_thread(THD *thd);
 
585
void create_thread_to_handle_connection(THD *thd);
 
586
void unlink_thd(THD *thd);
 
587
bool one_thread_per_connection_end(THD *thd, bool put_in_cache);
572
588
void flush_thread_cache();
573
589
 
574
590
/* item_func.cc */
575
591
extern bool check_reserved_words(LEX_STRING *name);
576
 
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
 
592
extern enum_field_types agg_field_type(Item **items, uint nitems);
577
593
 
578
594
/* strfunc.cc */
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,
 
595
uint64_t find_set(TYPELIB *lib, const char *x, uint length, const CHARSET_INFO * const cs,
 
596
                   char **err_pos, uint *err_len, bool *set_warning);
 
597
uint find_type(const TYPELIB *lib, const char *find, uint length,
582
598
               bool part_match);
583
 
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
 
599
uint find_type2(const TYPELIB *lib, const char *find, uint length,
584
600
                const CHARSET_INFO *cs);
585
601
void unhex_type2(TYPELIB *lib);
586
 
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
602
uint check_word(TYPELIB *lib, const char *val, const char *end,
587
603
                const char **end_of_word);
588
604
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
589
605
                         const CHARSET_INFO * const cs);
590
606
 
591
607
 
592
 
bool is_keyword(const char *name, uint32_t len);
 
608
bool is_keyword(const char *name, uint len);
593
609
 
594
610
#define MY_DB_OPT_FILE "db.opt"
595
611
bool my_database_names_init(void);
596
612
void my_database_names_free(void);
597
613
bool check_db_dir_existence(const char *db_name);
598
 
bool load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create);
599
 
bool load_db_opt_by_name(Session *session, const char *db_name,
 
614
bool load_db_opt(THD *thd, const char *path, HA_CREATE_INFO *create);
 
615
bool load_db_opt_by_name(THD *thd, const char *db_name,
600
616
                         HA_CREATE_INFO *db_create_info);
601
 
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name);
 
617
const CHARSET_INFO *get_default_db_collation(THD *thd, const char *db_name);
602
618
bool my_dbopt_init(void);
603
619
void my_dbopt_cleanup(void);
604
620
extern int creating_database; // How many database locks are made
632
648
extern const double log_10[309];
633
649
extern uint64_t log_10_int[20];
634
650
extern uint64_t keybuff_size;
635
 
extern uint64_t session_startup_options;
 
651
extern uint64_t thd_startup_options;
636
652
extern ulong thread_id;
637
653
extern ulong binlog_cache_use, binlog_cache_disk_use;
638
654
extern ulong aborted_threads,aborted_connects;
642
658
extern ulong max_connections,max_connect_errors, connect_timeout;
643
659
extern bool slave_allow_batching;
644
660
extern ulong slave_net_timeout, slave_trans_retries;
645
 
extern uint32_t max_user_connections;
 
661
extern uint max_user_connections;
646
662
extern ulong what_to_log,flush_time;
647
663
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
648
664
extern ulong max_binlog_size, max_relay_log_size;
655
671
extern ulong tc_log_page_waits;
656
672
extern bool relay_log_purge;
657
673
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;
 
674
extern uint test_flags,select_errors,ha_open_options;
 
675
extern uint protocol_version, mysqld_port, dropping_tables;
 
676
extern uint delay_key_write_options;
661
677
extern bool opt_endinfo, using_udf_functions;
662
678
extern bool locked_in_memory;
663
679
extern bool opt_using_transactions;
669
685
extern bool opt_log_queries_not_using_indexes;
670
686
extern bool opt_character_set_client_handshake;
671
687
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;
 
688
extern uint volatile thread_count, thread_running, global_read_lock;
 
689
extern uint connection_count;
674
690
extern bool opt_sql_bin_update;
675
691
extern bool opt_safe_user_create;
676
692
extern bool opt_no_mix_types;
680
696
extern bool use_temp_pool;
681
697
extern ulong slave_exec_mode_options;
682
698
extern bool opt_readonly;
 
699
extern bool opt_secure_auth;
683
700
extern char* opt_secure_file_priv;
 
701
extern bool opt_log_slow_admin_statements;
 
702
extern bool opt_log_slow_slave_statements;
684
703
extern bool opt_noacl;
685
704
extern bool opt_old_style_user_limits;
686
 
extern uint32_t opt_crash_binlog_innodb;
 
705
extern uint opt_crash_binlog_innodb;
687
706
extern char *default_tz_name;
688
707
extern char *opt_logname, *opt_slow_logname;
689
708
extern const char *log_output_str;
706
725
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
707
726
extern pthread_cond_t COND_global_read_lock;
708
727
extern pthread_attr_t connection_attrib;
709
 
extern I_List<Session> threads;
 
728
extern I_List<THD> threads;
710
729
extern I_List<NAMED_LIST> key_caches;
711
730
extern MY_BITMAP temp_pool;
712
731
extern String my_empty_string;
727
746
extern scheduler_functions thread_scheduler;
728
747
extern TYPELIB thread_handling_typelib;
729
748
extern uint8_t uc_update_queries[SQLCOM_END+1];
730
 
extern uint32_t sql_command_flags[];
 
749
extern uint sql_command_flags[];
731
750
extern TYPELIB log_output_typelib;
732
751
 
733
752
/* optional things, have_* variables */
742
761
 
743
762
extern pthread_t signal_thread;
744
763
 
745
 
DRIZZLE_LOCK *mysql_lock_tables(Session *session, Table **table, uint32_t count,
746
 
                              uint32_t flags, bool *need_reopen);
 
764
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, Table **table, uint count,
 
765
                              uint flags, bool *need_reopen);
747
766
/* mysql_lock_tables() and open_table() flags bits */
748
767
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
749
768
#define DRIZZLE_LOCK_IGNORE_FLUSH                 0x0002
752
771
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
753
772
#define DRIZZLE_LOCK_PERF_SCHEMA                  0x0020
754
773
 
755
 
void mysql_unlock_tables(Session *session, DRIZZLE_LOCK *sql_lock);
756
 
void mysql_unlock_read_tables(Session *session, DRIZZLE_LOCK *sql_lock);
757
 
void mysql_unlock_some_tables(Session *session, Table **table,uint32_t count);
758
 
void mysql_lock_remove(Session *session, DRIZZLE_LOCK *locked,Table *table,
 
774
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
 
775
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
 
776
void mysql_unlock_some_tables(THD *thd, Table **table,uint count);
 
777
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,Table *table,
759
778
                       bool always_unlock);
760
 
void mysql_lock_abort(Session *session, Table *table, bool upgrade_lock);
761
 
void mysql_lock_downgrade_write(Session *session, Table *table,
 
779
void mysql_lock_abort(THD *thd, Table *table, bool upgrade_lock);
 
780
void mysql_lock_downgrade_write(THD *thd, Table *table,
762
781
                                thr_lock_type new_lock_type);
763
 
bool mysql_lock_abort_for_thread(Session *session, Table *table);
 
782
bool mysql_lock_abort_for_thread(THD *thd, Table *table);
764
783
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
765
 
TableList *mysql_lock_have_duplicate(Session *session, TableList *needle,
 
784
TableList *mysql_lock_have_duplicate(THD *thd, TableList *needle,
766
785
                                      TableList *haystack);
767
 
bool lock_global_read_lock(Session *session);
768
 
void unlock_global_read_lock(Session *session);
769
 
bool wait_if_global_read_lock(Session *session, bool abort_on_refresh,
 
786
bool lock_global_read_lock(THD *thd);
 
787
void unlock_global_read_lock(THD *thd);
 
788
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
770
789
                              bool is_not_commit);
771
 
void start_waiting_global_read_lock(Session *session);
772
 
bool make_global_read_lock_block_commit(Session *session);
 
790
void start_waiting_global_read_lock(THD *thd);
 
791
bool make_global_read_lock_block_commit(THD *thd);
773
792
bool set_protect_against_global_read_lock(void);
774
793
void unset_protect_against_global_read_lock(void);
775
794
void broadcast_refresh(void);
776
 
int try_transactional_lock(Session *session, TableList *table_list);
777
 
int check_transactional_lock(Session *session, TableList *table_list);
778
 
int set_handler_table_locks(Session *session, TableList *table_list,
 
795
int try_transactional_lock(THD *thd, TableList *table_list);
 
796
int check_transactional_lock(THD *thd, TableList *table_list);
 
797
int set_handler_table_locks(THD *thd, TableList *table_list,
779
798
                            bool transactional);
780
799
 
781
800
/* Lock based on name */
782
 
int lock_and_wait_for_table_name(Session *session, TableList *table_list);
783
 
int lock_table_name(Session *session, TableList *table_list, bool check_in_use);
784
 
void unlock_table_name(Session *session, TableList *table_list);
785
 
bool wait_for_locked_table_names(Session *session, TableList *table_list);
786
 
bool lock_table_names(Session *session, TableList *table_list);
787
 
void unlock_table_names(Session *session, TableList *table_list,
 
801
int lock_and_wait_for_table_name(THD *thd, TableList *table_list);
 
802
int lock_table_name(THD *thd, TableList *table_list, bool check_in_use);
 
803
void unlock_table_name(THD *thd, TableList *table_list);
 
804
bool wait_for_locked_table_names(THD *thd, TableList *table_list);
 
805
bool lock_table_names(THD *thd, TableList *table_list);
 
806
void unlock_table_names(THD *thd, TableList *table_list,
788
807
                        TableList *last_table);
789
 
bool lock_table_names_exclusively(Session *session, TableList *table_list);
790
 
bool is_table_name_exclusively_locked_by_this_thread(Session *session, 
 
808
bool lock_table_names_exclusively(THD *thd, TableList *table_list);
 
809
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
791
810
                                                     TableList *table_list);
792
 
bool is_table_name_exclusively_locked_by_this_thread(Session *session, unsigned char *key,
 
811
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
793
812
                                                     int key_length);
794
813
 
795
814
 
797
816
 
798
817
void unireg_init(ulong options);
799
818
void unireg_end(void) __attribute__((noreturn));
800
 
bool mysql_create_frm(Session *session, const char *file_name,
 
819
bool mysql_create_frm(THD *thd, const char *file_name,
801
820
                      const char *db, const char *table,
802
821
                      HA_CREATE_INFO *create_info,
803
822
                      List<Create_field> &create_field,
804
 
                      uint32_t key_count,KEY *key_info,handler *db_type);
805
 
int rea_create_table(Session *session, const char *path,
 
823
                      uint key_count,KEY *key_info,handler *db_type);
 
824
int rea_create_table(THD *thd, const char *path,
806
825
                     const char *db, const char *table_name,
807
826
                     HA_CREATE_INFO *create_info,
808
827
                     List<Create_field> &create_field,
809
 
                     uint32_t key_count,KEY *key_info,
 
828
                     uint key_count,KEY *key_info,
810
829
                     handler *file);
811
 
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
 
830
int format_number(uint inputflag,uint max_length,char * pos,uint length,
812
831
                  char * *errpos);
813
832
 
814
833
/* table.cc */
815
834
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
816
 
                               uint32_t key_length);
817
 
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
818
 
                          uint32_t key_length,
 
835
                               uint key_length);
 
836
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
 
837
                          uint key_length,
819
838
                          const char *table_name, const char *path);
820
839
void free_table_share(TABLE_SHARE *share);
821
 
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
 
840
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
822
841
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
823
 
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
824
 
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
 
842
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
 
843
                          uint db_stat, uint prgflag, uint ha_open_flags,
825
844
                          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);
 
845
int readfrm(const char *name, uchar **data, size_t *length);
 
846
int writefrm(const char* name, const uchar* data, size_t len);
828
847
int closefrm(Table *table, bool free_share);
829
 
int read_string(File file, unsigned char* *to, size_t length);
 
848
int read_string(File file, uchar* *to, size_t length);
830
849
void free_blobs(Table *table);
831
850
int set_zone(int nr,int min_zone,int max_zone);
832
 
uint32_t convert_period_to_month(uint32_t period);
833
 
uint32_t convert_month_to_period(uint32_t month);
834
 
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
835
 
                         uint32_t *day);
836
 
my_time_t TIME_to_timestamp(Session *session, 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);
 
851
ulong convert_period_to_month(ulong period);
 
852
ulong convert_month_to_period(ulong month);
 
853
void get_date_from_daynr(long daynr,uint *year, uint *month,
 
854
                         uint *day);
 
855
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
 
856
bool str_to_time_with_warn(const char *str,uint length,DRIZZLE_TIME *l_time);
 
857
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
 
858
                                         DRIZZLE_TIME *l_time, uint flags);
840
859
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
841
860
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
842
861
 
843
 
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
862
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
844
863
                                  const char *str_val,
845
 
                                  uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
 
864
                                  uint str_length, timestamp_type time_type,
846
865
                                  const char *field_name);
847
866
 
848
867
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
851
870
 
852
871
extern LEX_STRING interval_type_to_name[];
853
872
 
854
 
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
873
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
855
874
                                               const char *format_str,
856
 
                                               uint32_t format_length);
857
 
extern DATE_TIME_FORMAT *date_time_format_copy(Session *session,
 
875
                                               uint format_length);
 
876
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
858
877
                                               DATE_TIME_FORMAT *format);
859
878
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
860
 
                                                             enum enum_drizzle_timestamp_type type);
 
879
                                     timestamp_type type);
861
880
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
862
 
                                             enum enum_drizzle_timestamp_type type, String *str);
 
881
                           timestamp_type type, String *str);
863
882
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
864
883
                   String *str);
865
884
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
867
886
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
868
887
               String *str);
869
888
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
870
 
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
 
889
uint64_t get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
871
890
                             Item *warn_item, bool *is_null);
872
891
 
873
892
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, Session *session, Table *reg_form,
 
893
void change_byte(uchar *,uint,char,char);
 
894
void init_read_record(READ_RECORD *info, THD *thd, Table *reg_form,
876
895
                      SQL_SELECT *select,
877
896
                      int use_record_cache, bool print_errors);
878
 
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table, 
879
 
                          bool print_error, uint32_t idx);
 
897
void init_read_record_idx(READ_RECORD *info, THD *thd, Table *table, 
 
898
                          bool print_error, uint idx);
880
899
void end_read_record(READ_RECORD *info);
881
 
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
882
 
                 uint32_t s_length, SQL_SELECT *select,
 
900
ha_rows filesort(THD *thd, Table *form,struct st_sort_field *sortorder,
 
901
                 uint s_length, SQL_SELECT *select,
883
902
                 ha_rows max_rows, bool sort_positions,
884
903
                 ha_rows *examined_rows);
885
904
void filesort_free_buffers(Table *table, bool full);
886
 
void change_double_for_sort(double nr,unsigned char *to);
 
905
void change_double_for_sort(double nr,uchar *to);
887
906
double my_double_round(double value, int64_t dec, bool dec_unsigned,
888
907
                       bool truncate);
889
908
int get_quick_record(SQL_SELECT *select);
890
909
 
891
910
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);
 
911
uint calc_week(DRIZZLE_TIME *l_time, uint week_behaviour, uint *year);
 
912
void find_date(char *pos,uint *vek,uint flag);
894
913
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
895
914
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,
 
915
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
 
916
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
898
917
                     const char *newname);
899
918
ulong next_io_size(ulong pos);
900
 
void append_unescaped(String *res, const char *pos, uint32_t length);
901
 
int create_frm(Session *session, 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);
 
919
void append_unescaped(String *res, const char *pos, uint length);
 
920
int create_frm(THD *thd, const char *name, const char *db, const char *table,
 
921
               uint reclength, uchar *fileinfo,
 
922
               HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
904
923
int rename_file_ext(const char * from,const char * to,const char * ext);
905
924
bool check_db_name(LEX_STRING *db);
906
925
bool check_column_name(const char *name);
907
 
bool check_table_name(const char *name, uint32_t length);
 
926
bool check_table_name(const char *name, uint length);
908
927
char *get_field(MEM_ROOT *mem, Field *field);
909
928
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
910
929
char *fn_rext(char *name);
911
930
 
912
931
/* 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);
 
932
uint build_table_filename(char *buff, size_t bufflen, const char *db,
 
933
                          const char *table, const char *ext, uint flags);
915
934
 
916
935
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
917
936
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
923
942
#define NO_FRM_RENAME   (1 << 2)
924
943
 
925
944
/* item_func.cc */
926
 
Item *get_system_var(Session *session, enum_var_type var_type, LEX_STRING name,
 
945
Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
927
946
                     LEX_STRING component);
928
 
int get_var_with_binlog(Session *session, enum_sql_command sql_command,
 
947
int get_var_with_binlog(THD *thd, enum_sql_command sql_command,
929
948
                        LEX_STRING &name, user_var_entry **out_entry);
930
949
/* log.cc */
931
950
bool flush_error_log(void);
936
955
 
937
956
/* Some inline functions for more speed */
938
957
 
939
 
inline bool add_item_to_list(Session *session, Item *item)
940
 
{
941
 
  return session->lex->current_select->add_item_to_list(session, item);
942
 
}
943
 
 
944
 
inline bool add_value_to_list(Session *session, Item *value)
945
 
{
946
 
  return session->lex->value_list.push_back(value);
947
 
}
948
 
 
949
 
inline bool add_order_to_list(Session *session, Item *item, bool asc)
950
 
{
951
 
  return session->lex->current_select->add_order_to_list(session, item, asc);
952
 
}
953
 
 
954
 
inline bool add_group_to_list(Session *session, Item *item, bool asc)
955
 
{
956
 
  return session->lex->current_select->add_group_to_list(session, item, asc);
 
958
inline bool add_item_to_list(THD *thd, Item *item)
 
959
{
 
960
  return thd->lex->current_select->add_item_to_list(thd, item);
 
961
}
 
962
 
 
963
inline bool add_value_to_list(THD *thd, Item *value)
 
964
{
 
965
  return thd->lex->value_list.push_back(value);
 
966
}
 
967
 
 
968
inline bool add_order_to_list(THD *thd, Item *item, bool asc)
 
969
{
 
970
  return thd->lex->current_select->add_order_to_list(thd, item, asc);
 
971
}
 
972
 
 
973
inline bool add_group_to_list(THD *thd, Item *item, bool asc)
 
974
{
 
975
  return thd->lex->current_select->add_group_to_list(thd, item, asc);
957
976
}
958
977
 
959
978
inline void mark_as_null_row(Table *table)
963
982
  memset(table->null_flags, 255, table->s->null_bytes);
964
983
}
965
984
 
966
 
inline void table_case_convert(char * name, uint32_t length)
 
985
inline void table_case_convert(char * name, uint length)
967
986
{
968
987
  if (lower_case_table_names)
969
988
    files_charset_info->cset->casedn(files_charset_info,
1001
1020
  @param table_list   TableList structure pointer (owner of Table)
1002
1021
  @param tablenr     table number
1003
1022
*/
1004
 
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
 
1023
inline void setup_table_map(Table *table, TableList *table_list, uint tablenr)
1005
1024
{
1006
1025
  table->used_fields= 0;
1007
1026
  table->const_table= 0;
1037
1056
  return -1;
1038
1057
}
1039
1058
 
 
1059
/**
 
1060
  return true if the table was created explicitly.
 
1061
*/
 
1062
inline bool is_user_table(Table * table)
 
1063
{
 
1064
  const char *name= table->s->table_name.str;
 
1065
  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
 
1066
}
 
1067
 
 
1068
 
 
1069
#ifndef HAVE_LOG2
 
1070
/*
 
1071
  This will be slightly slower and perhaps a tiny bit less accurate than
 
1072
  doing it the IEEE754 way but log2() should be available on C99 systems.
 
1073
*/
 
1074
static inline double log2(double x)
 
1075
{
 
1076
  return (log(x) / M_LN2);
 
1077
}
 
1078
#endif
 
1079
 
 
1080
 
1040
1081
/*
1041
1082
  Some functions that are different in the embedded library and the normal
1042
1083
  server
1044
1085
 
1045
1086
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
1046
1087
void kill_delayed_threads(void);
1047
 
bool check_stack_overrun(Session *session, long margin, unsigned char *dummy);
 
1088
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
 
1089
 
 
1090
/** 
 
1091
 * Used by handlers to store things in schema tables 
 
1092
 *
 
1093
 * @TODO These should be placed in an information_schema.h header
 
1094
 * file once the new information schema design is finalized.
 
1095
 */
 
1096
#define IS_FILES_FILE_ID              0
 
1097
#define IS_FILES_FILE_NAME            1
 
1098
#define IS_FILES_FILE_TYPE            2
 
1099
#define IS_FILES_TABLESPACE_NAME      3
 
1100
#define IS_FILES_TABLE_CATALOG        4
 
1101
#define IS_FILES_TABLE_SCHEMA         5
 
1102
#define IS_FILES_TABLE_NAME           6
 
1103
#define IS_FILES_LOGFILE_GROUP_NAME   7
 
1104
#define IS_FILES_LOGFILE_GROUP_NUMBER 8
 
1105
#define IS_FILES_ENGINE               9
 
1106
#define IS_FILES_FULLTEXT_KEYS       10
 
1107
#define IS_FILES_DELETED_ROWS        11
 
1108
#define IS_FILES_UPDATE_COUNT        12
 
1109
#define IS_FILES_FREE_EXTENTS        13
 
1110
#define IS_FILES_TOTAL_EXTENTS       14
 
1111
#define IS_FILES_EXTENT_SIZE         15
 
1112
#define IS_FILES_INITIAL_SIZE        16
 
1113
#define IS_FILES_MAXIMUM_SIZE        17
 
1114
#define IS_FILES_AUTOEXTEND_SIZE     18
 
1115
#define IS_FILES_CREATION_TIME       19
 
1116
#define IS_FILES_LAST_UPDATE_TIME    20
 
1117
#define IS_FILES_LAST_ACCESS_TIME    21
 
1118
#define IS_FILES_RECOVER_TIME        22
 
1119
#define IS_FILES_TRANSACTION_COUNTER 23
 
1120
#define IS_FILES_VERSION             24
 
1121
#define IS_FILES_ROW_FORMAT          25
 
1122
#define IS_FILES_TABLE_ROWS          26
 
1123
#define IS_FILES_AVG_ROW_LENGTH      27
 
1124
#define IS_FILES_DATA_LENGTH         28
 
1125
#define IS_FILES_MAX_DATA_LENGTH     29
 
1126
#define IS_FILES_INDEX_LENGTH        30
 
1127
#define IS_FILES_DATA_FREE           31
 
1128
#define IS_FILES_CREATE_TIME         32
 
1129
#define IS_FILES_UPDATE_TIME         33
 
1130
#define IS_FILES_CHECK_TIME          34
 
1131
#define IS_FILES_CHECKSUM            35
 
1132
#define IS_FILES_STATUS              36
 
1133
#define IS_FILES_EXTRA               37
1048
1134
 
1049
1135
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */