~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

  • Committer: Brian Aker
  • Date: 2008-08-12 03:12:57 UTC
  • Revision ID: brian@tangent.org-20080812031257-ln3uk87y1r22byeg
First pass of new sql_db.cc work

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).
26
 
  The consequence is that 90% of the file is wrapped in \#ifndef DRIZZLE_CLIENT,
 
22
  The consequence is that 90% of the file is wrapped in \#ifndef MYSQL_CLIENT,
27
23
  except the part which must be in the server and in the client.
28
24
 
29
25
  @TODO Name this file better. "priv" could mean private, privileged, privileges.
 
26
 
 
27
  @TODO Get rid of the MYSQL_CLIENT and MYSQL_SERVER conditionals
30
28
*/
31
29
 
32
30
#ifndef DRIZZLE_SERVER_SERVER_INCLUDES_H
66
64
/* sql_repl.cc */
67
65
void write_bin_log(THD *thd, bool clear_error,
68
66
                   char const *query, ulong query_length);
69
 
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, uint16_t flags);
 
67
void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, ushort flags);
70
68
void mysql_client_binlog_statement(THD *thd);
71
69
 
72
70
/* sql_rename.cc */
73
 
bool mysql_rename_tables(THD *thd, TableList *table_list, bool silent);
74
 
bool do_rename(THD *thd, TableList *ren_table, char *new_db,
 
71
bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent);
 
72
bool do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db,
75
73
                      char *new_table_name, char *new_table_alias,
76
74
                      bool skip_error);
77
75
 
78
76
/* sql_parse.cc */
79
 
void mysql_parse(THD *thd, const char *inBuf, uint32_t length,
 
77
void mysql_parse(THD *thd, const char *inBuf, uint length,
80
78
                 const char ** semicolon);
81
79
 
82
 
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint32_t length);
 
80
bool mysql_test_parse_for_slave(THD *thd,char *inBuf,uint length);
83
81
 
84
82
 
85
83
bool is_update_query(enum enum_sql_command command);
86
84
 
87
 
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length);
 
85
bool alloc_query(THD *thd, const char *packet, uint packet_length);
88
86
 
89
87
void mysql_reset_thd_for_next_command(THD *thd);
90
88
 
99
97
bool do_command(THD *thd);
100
98
 
101
99
bool dispatch_command(enum enum_server_command command, THD *thd,
102
 
                      char* packet, uint32_t packet_length);
 
100
                      char* packet, uint packet_length);
103
101
 
104
102
void log_slow_statement(THD *thd);
105
103
 
106
104
bool append_file_to_dir(THD *thd, const char **filename_ptr, 
107
105
                        const char *table_name);
108
106
 
109
 
bool reload_cache(THD *thd, ulong options, TableList *tables, bool *write_to_binlog);
 
107
bool reload_cache(THD *thd, ulong options, TABLE_LIST *tables, bool *write_to_binlog);
110
108
 
111
109
bool check_simple_select();
112
110
 
117
115
void free_max_user_conn(void);
118
116
pthread_handler_t handle_bootstrap(void *arg);
119
117
int mysql_execute_command(THD *thd);
120
 
bool check_dup(const char *db, const char *name, TableList *tables);
121
 
bool check_table_access(THD *thd, ulong want_access, TableList *tables,
 
118
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
 
119
bool check_table_access(THD *thd, ulong want_access, TABLE_LIST *tables,
122
120
                        bool no_errors,
123
121
                        bool any_combination_of_privileges_will_do,
124
 
                        uint32_t number);
 
122
                        uint number);
125
123
/*
126
124
  General routine to change field->ptr of a NULL-terminated array of Field
127
125
  objects. Useful when needed to call val_int, val_str or similar and the
129
127
  set_key_field_ptr changes all fields of an index using a key_info object.
130
128
  All methods presume that there is at least one field to change.
131
129
*/
132
 
void set_field_ptr(Field **ptr, const unsigned char *new_buf, const unsigned char *old_buf);
133
 
void set_key_field_ptr(KEY *key_info, const unsigned char *new_buf,
134
 
                       const unsigned char *old_buf);
 
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);
135
133
/* </UNUSED> */
136
134
 
 
135
/* sql_update.cc */
 
136
bool compare_record(TABLE *table);
 
137
 
137
138
/* sql_base.cc */
138
139
void table_cache_free(void);
139
140
bool table_cache_init(void);
140
141
bool table_def_init(void);
141
142
void table_def_free(void);
142
143
void assign_new_table_id(TABLE_SHARE *share);
143
 
uint32_t cached_open_tables(void);
144
 
uint32_t cached_table_definitions(void);
 
144
uint cached_open_tables(void);
 
145
uint cached_table_definitions(void);
145
146
 
146
147
/* drizzled.cc */
147
148
void kill_mysql(void);
148
 
void close_connection(THD *thd, uint32_t errcode, bool lock);
 
149
void close_connection(THD *thd, uint errcode, bool lock);
149
150
 
150
151
/* sql_select.cc */
151
 
Table *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
 
152
TABLE *create_virtual_tmp_table(THD *thd, List<Create_field> &field_list);
152
153
 
153
154
/* handler.cc */
154
155
bool mysql_xa_recover(THD *thd);
155
156
 
156
 
SORT_FIELD * make_unireg_sortorder(order_st *order, uint32_t *length,
 
157
SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length,
157
158
                                  SORT_FIELD *sortorder);
158
 
int setup_order(THD *thd, Item **ref_pointer_array, TableList *tables,
159
 
                List<Item> &fields, List <Item> &all_fields, order_st *order);
160
 
int setup_group(THD *thd, Item **ref_pointer_array, TableList *tables,
161
 
                List<Item> &fields, List<Item> &all_fields, order_st *order,
 
159
int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
 
160
                List<Item> &fields, List <Item> &all_fields, ORDER *order);
 
161
int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
 
162
                List<Item> &fields, List<Item> &all_fields, ORDER *order,
162
163
                bool *hidden_group_fields);
163
164
bool fix_inner_refs(THD *thd, List<Item> &all_fields, SELECT_LEX *select,
164
165
                   Item **ref_pointer_array);
166
167
bool handle_select(THD *thd, LEX *lex, select_result *result,
167
168
                   ulong setup_tables_done_option);
168
169
bool mysql_select(THD *thd, Item ***rref_pointer_array,
169
 
                  TableList *tables, uint32_t wild_num,  List<Item> &list,
170
 
                  COND *conds, uint32_t og_num, order_st *order, order_st *group,
171
 
                  Item *having, order_st *proc_param, uint64_t select_type, 
 
170
                  TABLE_LIST *tables, uint wild_num,  List<Item> &list,
 
171
                  COND *conds, uint og_num, ORDER *order, ORDER *group,
 
172
                  Item *having, ORDER *proc_param, uint64_t select_type, 
172
173
                  select_result *result, SELECT_LEX_UNIT *unit, 
173
174
                  SELECT_LEX *select_lex);
174
175
void free_underlaid_joins(THD *thd, SELECT_LEX *select);
180
181
                 SELECT_LEX_UNIT *unit, ulong setup_tables_done_option);
181
182
bool mysql_handle_derived(LEX *lex, bool (*processor)(THD *thd,
182
183
                                                      LEX *lex,
183
 
                                                      TableList *table));
184
 
bool mysql_derived_prepare(THD *thd, LEX *lex, TableList *t);
185
 
bool mysql_derived_filling(THD *thd, LEX *lex, TableList *t);
186
 
Field *create_tmp_field(THD *thd, Table *table,Item *item, Item::Type type,
 
184
                                                      TABLE_LIST *table));
 
185
bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *t);
 
186
bool mysql_derived_filling(THD *thd, LEX *lex, TABLE_LIST *t);
 
187
Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
187
188
                        Item ***copy_func, Field **from_field,
188
189
                        Field **def_field,
189
190
                        bool group, bool modify_item,
190
191
                        bool table_cant_handle_bit_fields,
191
192
                        bool make_copy_field,
192
 
                        uint32_t convert_blob_length);
 
193
                        uint convert_blob_length);
193
194
void sp_prepare_create_field(THD *thd, Create_field *sql_field);
194
195
int prepare_create_field(Create_field *sql_field, 
195
 
                         uint32_t *blob_columns, 
 
196
                         uint *blob_columns, 
196
197
                         int *timestamps, int *timestamps_with_niladic,
197
198
                         int64_t table_flags);
198
199
bool mysql_create_table(THD *thd,const char *db, const char *table_name,
199
200
                        HA_CREATE_INFO *create_info,
200
201
                        Alter_info *alter_info,
201
 
                        bool tmp_table, uint32_t select_field_count);
 
202
                        bool tmp_table, uint select_field_count);
202
203
bool mysql_create_table_no_lock(THD *thd, const char *db,
203
204
                                const char *table_name,
204
205
                                HA_CREATE_INFO *create_info,
205
206
                                Alter_info *alter_info,
206
 
                                bool tmp_table, uint32_t select_field_count);
 
207
                                bool tmp_table, uint select_field_count);
207
208
 
208
209
bool mysql_alter_table(THD *thd, char *new_db, char *new_name,
209
210
                       HA_CREATE_INFO *create_info,
210
 
                       TableList *table_list,
 
211
                       TABLE_LIST *table_list,
211
212
                       Alter_info *alter_info,
212
 
                       uint32_t order_num, order_st *order, bool ignore);
213
 
bool mysql_recreate_table(THD *thd, TableList *table_list);
214
 
bool mysql_create_like_table(THD *thd, TableList *table,
215
 
                             TableList *src_table,
 
213
                       uint order_num, ORDER *order, bool ignore);
 
214
bool mysql_recreate_table(THD *thd, TABLE_LIST *table_list);
 
215
bool mysql_create_like_table(THD *thd, TABLE_LIST *table,
 
216
                             TABLE_LIST *src_table,
216
217
                             HA_CREATE_INFO *create_info);
217
218
bool mysql_rename_table(handlerton *base, const char *old_db,
218
219
                        const char * old_name, const char *new_db,
219
 
                        const char * new_name, uint32_t flags);
220
 
bool mysql_prepare_update(THD *thd, TableList *table_list,
221
 
                          Item **conds, uint32_t order_num, order_st *order);
222
 
int mysql_update(THD *thd,TableList *tables,List<Item> &fields,
 
220
                        const char * new_name, uint flags);
 
221
bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list,
 
222
                          Item **conds, uint order_num, ORDER *order);
 
223
int mysql_update(THD *thd,TABLE_LIST *tables,List<Item> &fields,
223
224
                 List<Item> &values,COND *conds,
224
 
                 uint32_t order_num, order_st *order, ha_rows limit,
 
225
                 uint order_num, ORDER *order, ha_rows limit,
225
226
                 enum enum_duplicates handle_duplicates, bool ignore);
226
 
bool mysql_multi_update(THD *thd, TableList *table_list,
 
227
bool mysql_multi_update(THD *thd, TABLE_LIST *table_list,
227
228
                        List<Item> *fields, List<Item> *values,
228
229
                        COND *conds, uint64_t options,
229
230
                        enum enum_duplicates handle_duplicates, bool ignore,
230
231
                        SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex);
231
 
bool mysql_prepare_insert(THD *thd, TableList *table_list, Table *table,
 
232
bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list, TABLE *table,
232
233
                          List<Item> &fields, List_item *values,
233
234
                          List<Item> &update_fields,
234
235
                          List<Item> &update_values, enum_duplicates duplic,
235
236
                          COND **where, bool select_insert,
236
237
                          bool check_fields, bool abort_on_warning);
237
 
bool mysql_insert(THD *thd,TableList *table,List<Item> &fields,
 
238
bool mysql_insert(THD *thd,TABLE_LIST *table,List<Item> &fields,
238
239
                  List<List_item> &values, List<Item> &update_fields,
239
240
                  List<Item> &update_values, enum_duplicates flag,
240
241
                  bool ignore);
241
 
int check_that_all_fields_are_given_values(THD *thd, Table *entry,
242
 
                                           TableList *table_list);
243
 
void prepare_triggers_for_insert_stmt(Table *table);
244
 
int mysql_prepare_delete(THD *thd, TableList *table_list, Item **conds);
245
 
bool mysql_delete(THD *thd, TableList *table_list, COND *conds,
 
242
int check_that_all_fields_are_given_values(THD *thd, TABLE *entry,
 
243
                                           TABLE_LIST *table_list);
 
244
void prepare_triggers_for_insert_stmt(TABLE *table);
 
245
int mysql_prepare_delete(THD *thd, TABLE_LIST *table_list, Item **conds);
 
246
bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
246
247
                  SQL_LIST *order, ha_rows rows, uint64_t options,
247
248
                  bool reset_auto_increment);
248
 
bool mysql_truncate(THD *thd, TableList *table_list, bool dont_send_ok);
249
 
uint32_t create_table_def_key(THD *thd, char *key, TableList *table_list,
 
249
bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok);
 
250
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
250
251
                          bool tmp_table);
251
 
TABLE_SHARE *get_table_share(THD *thd, TableList *table_list, char *key,
252
 
                             uint32_t key_length, uint32_t db_flags, int *error);
 
252
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
 
253
                             uint key_length, uint db_flags, int *error);
253
254
void release_table_share(TABLE_SHARE *share, enum release_type type);
254
255
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
255
 
Table *open_ltable(THD *thd, TableList *table_list, thr_lock_type update,
256
 
                   uint32_t lock_flags);
257
 
Table *open_table(THD *thd, TableList *table_list, bool *refresh, uint32_t flags);
258
 
bool name_lock_locked_table(THD *thd, TableList *tables);
259
 
bool reopen_name_locked_table(THD* thd, TableList* table_list, bool link_in);
260
 
Table *table_cache_insert_placeholder(THD *thd, const char *key,
261
 
                                      uint32_t key_length);
 
256
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
 
257
                   uint lock_flags);
 
258
TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
 
259
                  bool *refresh, uint flags);
 
260
bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
 
261
bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
 
262
TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
 
263
                                      uint key_length);
262
264
bool lock_table_name_if_not_cached(THD *thd, const char *db,
263
 
                                   const char *table_name, Table **table);
264
 
Table *find_locked_table(THD *thd, const char *db,const char *table_name);
265
 
void detach_merge_children(Table *table, bool clear_refs);
266
 
bool fix_merge_after_open(TableList *old_child_list, TableList **old_last,
267
 
                          TableList *new_child_list, TableList **new_last);
268
 
bool reopen_table(Table *table);
 
265
                                   const char *table_name, TABLE **table);
 
266
TABLE *find_locked_table(THD *thd, const char *db,const char *table_name);
 
267
void detach_merge_children(TABLE *table, bool clear_refs);
 
268
bool fix_merge_after_open(TABLE_LIST *old_child_list, TABLE_LIST **old_last,
 
269
                          TABLE_LIST *new_child_list, TABLE_LIST **new_last);
 
270
bool reopen_table(TABLE *table);
269
271
bool reopen_tables(THD *thd,bool get_locks,bool in_refresh);
270
272
void close_data_files_and_morph_locks(THD *thd, const char *db,
271
273
                                      const char *table_name);
272
 
void close_handle_and_leave_table_as_lock(Table *table);
 
274
void close_handle_and_leave_table_as_lock(TABLE *table);
273
275
bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
274
 
                  uint32_t db_stat, uint32_t prgflag,
275
 
                  uint32_t ha_open_flags, Table *outparam,
276
 
                  TableList *table_desc, MEM_ROOT *mem_root);
 
276
                  uint db_stat, uint prgflag,
 
277
                  uint ha_open_flags, TABLE *outparam,
 
278
                  TABLE_LIST *table_desc, MEM_ROOT *mem_root);
277
279
bool wait_for_tables(THD *thd);
278
 
bool table_is_used(Table *table, bool wait_for_name_lock);
279
 
Table *drop_locked_tables(THD *thd,const char *db, const char *table_name);
 
280
bool table_is_used(TABLE *table, bool wait_for_name_lock);
 
281
TABLE *drop_locked_tables(THD *thd,const char *db, const char *table_name);
280
282
void abort_locked_tables(THD *thd,const char *db, const char *table_name);
281
283
void execute_init_command(THD *thd, sys_var_str *init_command_var,
282
284
                          rw_lock_t *var_mutex);
288
290
                                  IGNORE_EXCEPT_NON_UNIQUE};
289
291
Field *
290
292
find_field_in_tables(THD *thd, Item_ident *item,
291
 
                     TableList *first_table, TableList *last_table,
 
293
                     TABLE_LIST *first_table, TABLE_LIST *last_table,
292
294
                     Item **ref, find_item_error_report_type report_error,
293
295
                     bool check_privileges, bool register_tree_change);
294
296
Field *
295
 
find_field_in_table_ref(THD *thd, TableList *table_list,
296
 
                        const char *name, uint32_t length,
 
297
find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
 
298
                        const char *name, uint length,
297
299
                        const char *item_name, const char *db_name,
298
300
                        const char *table_name, Item **ref,
299
301
                        bool check_privileges, bool allow_rowid,
300
 
                        uint32_t *cached_field_index_ptr,
301
 
                        bool register_tree_change, TableList **actual_table);
302
 
Field *
303
 
find_field_in_table(THD *thd, Table *table, const char *name, uint32_t length,
304
 
                    bool allow_rowid, uint32_t *cached_field_index_ptr);
305
 
Field *
306
 
find_field_in_table_sef(Table *table, const char *name);
 
302
                        uint *cached_field_index_ptr,
 
303
                        bool register_tree_change, TABLE_LIST **actual_table);
 
304
Field *
 
305
find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
 
306
                    bool allow_rowid, uint *cached_field_index_ptr);
 
307
Field *
 
308
find_field_in_table_sef(TABLE *table, const char *name);
307
309
 
308
310
/* sql_do.cc */
309
311
bool mysql_do(THD *thd, List<Item> &values);
316
318
/* information schema */
317
319
extern LEX_STRING INFORMATION_SCHEMA_NAME;
318
320
/* log tables */
319
 
extern LEX_STRING DRIZZLE_SCHEMA_NAME;
 
321
extern LEX_STRING MYSQL_SCHEMA_NAME;
320
322
extern LEX_STRING GENERAL_LOG_NAME;
321
323
extern LEX_STRING SLOW_LOG_NAME;
322
324
 
327
329
                         enum enum_schema_tables schema_table_idx);
328
330
int make_schema_select(THD *thd,  SELECT_LEX *sel,
329
331
                       enum enum_schema_tables schema_table_idx);
330
 
int mysql_schema_table(THD *thd, LEX *lex, TableList *table_list);
 
332
int mysql_schema_table(THD *thd, LEX *lex, TABLE_LIST *table_list);
331
333
bool get_schema_tables_result(JOIN *join,
332
334
                              enum enum_schema_table_state executed_place);
333
335
enum enum_schema_tables get_schema_table_idx(ST_SCHEMA_TABLE *schema_table);
336
338
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
337
339
 
338
340
/* sql_handler.cc */
339
 
bool mysql_ha_open(THD *thd, TableList *tables, bool reopen);
340
 
bool mysql_ha_close(THD *thd, TableList *tables);
341
 
bool mysql_ha_read(THD *, TableList *,enum enum_ha_read_modes,char *,
 
341
bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen);
 
342
bool mysql_ha_close(THD *thd, TABLE_LIST *tables);
 
343
bool mysql_ha_read(THD *, TABLE_LIST *,enum enum_ha_read_modes,char *,
342
344
                   List<Item> *,enum ha_rkey_function,Item *,ha_rows,ha_rows);
343
345
void mysql_ha_flush(THD *thd);
344
 
void mysql_ha_rm_tables(THD *thd, TableList *tables, bool is_locked);
 
346
void mysql_ha_rm_tables(THD *thd, TABLE_LIST *tables, bool is_locked);
345
347
void mysql_ha_cleanup(THD *thd);
346
348
 
347
349
/* sql_base.cc */
348
350
#define TMP_TABLE_KEY_EXTRA 8
349
 
void set_item_name(Item *item,char *pos,uint32_t length);
 
351
void set_item_name(Item *item,char *pos,uint length);
350
352
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum enum_field_types type,
351
353
                       char *length, char *decimal,
352
 
                       uint32_t type_modifier,
 
354
                       uint type_modifier,
353
355
                       enum column_format_type column_format,
354
356
                       Item *default_value, Item *on_update_value,
355
357
                       LEX_STRING *comment,
357
359
                       const CHARSET_INFO * const cs);
358
360
Create_field * new_create_field(THD *thd, char *field_name, enum_field_types type,
359
361
                                char *length, char *decimals,
360
 
                                uint32_t type_modifier, 
 
362
                                uint type_modifier, 
361
363
                                Item *default_value, Item *on_update_value,
362
364
                                LEX_STRING *comment, char *change, 
363
365
                                List<String> *interval_list, CHARSET_INFO *cs);
364
366
void store_position_for_column(const char *name);
365
367
bool add_to_list(THD *thd, SQL_LIST &list,Item *group,bool asc);
366
368
bool push_new_name_resolution_context(THD *thd,
367
 
                                      TableList *left_op,
368
 
                                      TableList *right_op);
369
 
void add_join_on(TableList *b,Item *expr);
370
 
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
 
369
                                      TABLE_LIST *left_op,
 
370
                                      TABLE_LIST *right_op);
 
371
void add_join_on(TABLE_LIST *b,Item *expr);
 
372
void add_join_natural(TABLE_LIST *a,TABLE_LIST *b,List<String> *using_fields,
371
373
                      SELECT_LEX *lex);
372
374
bool add_proc_to_list(THD *thd, Item *item);
373
 
void unlink_open_table(THD *thd, Table *find, bool unlock);
374
 
void drop_open_table(THD *thd, Table *table, const char *db_name,
 
375
void unlink_open_table(THD *thd, TABLE *find, bool unlock);
 
376
void drop_open_table(THD *thd, TABLE *table, const char *db_name,
375
377
                     const char *table_name);
376
 
void update_non_unique_table_error(TableList *update,
 
378
void update_non_unique_table_error(TABLE_LIST *update,
377
379
                                   const char *operation,
378
 
                                   TableList *duplicate);
 
380
                                   TABLE_LIST *duplicate);
379
381
 
380
 
SQL_SELECT *make_select(Table *head, table_map const_tables,
 
382
SQL_SELECT *make_select(TABLE *head, table_map const_tables,
381
383
                        table_map read_tables, COND *conds,
382
384
                        bool allow_null_cond,  int *error);
383
385
extern Item **not_found_item;
408
410
  RESOLVED_WITH_NO_ALIAS,
409
411
  RESOLVED_AGAINST_ALIAS
410
412
};
411
 
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,
412
414
                          find_item_error_report_type report_error,
413
415
                          enum_resolution_type *resolution);
414
 
bool get_key_map_from_key_list(key_map *map, Table *table,
 
416
bool get_key_map_from_key_list(key_map *map, TABLE *table,
415
417
                               List<String> *index_list);
416
418
bool insert_fields(THD *thd, Name_resolution_context *context,
417
419
                   const char *db_name, const char *table_name,
418
420
                   List_iterator<Item> *it, bool any_privileges);
419
421
bool setup_tables(THD *thd, Name_resolution_context *context,
420
 
                  List<TableList> *from_clause, TableList *tables,
421
 
                  TableList **leaves, bool select_insert);
 
422
                  List<TABLE_LIST> *from_clause, TABLE_LIST *tables,
 
423
                  TABLE_LIST **leaves, bool select_insert);
422
424
bool setup_tables_and_check_access(THD *thd, 
423
425
                                   Name_resolution_context *context,
424
 
                                   List<TableList> *from_clause, 
425
 
                                   TableList *tables, 
426
 
                                   TableList **leaves, 
 
426
                                   List<TABLE_LIST> *from_clause, 
 
427
                                   TABLE_LIST *tables, 
 
428
                                   TABLE_LIST **leaves, 
427
429
                                   bool select_insert);
428
 
int setup_wild(THD *thd, TableList *tables, List<Item> &fields,
429
 
               List<Item> *sum_func_list, uint32_t wild_num);
 
430
int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
 
431
               List<Item> *sum_func_list, uint wild_num);
430
432
bool setup_fields(THD *thd, Item** ref_pointer_array,
431
433
                  List<Item> &item, enum_mark_columns mark_used_columns,
432
434
                  List<Item> *sum_func_list, bool allow_sum_func);
441
443
                    allow_sum_func);
442
444
  return res;
443
445
}
444
 
int setup_conds(THD *thd, TableList *tables, TableList *leaves,
 
446
int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
445
447
                COND **conds);
446
448
int setup_ftfuncs(SELECT_LEX* select);
447
449
int init_ftfuncs(THD *thd, SELECT_LEX* select, bool no_order);
448
450
void wait_for_condition(THD *thd, pthread_mutex_t *mutex,
449
451
                        pthread_cond_t *cond);
450
 
int open_tables(THD *thd, TableList **tables, uint32_t *counter, uint32_t flags);
 
452
int open_tables(THD *thd, TABLE_LIST **tables, uint *counter, uint flags);
451
453
/* open_and_lock_tables with optional derived handling */
452
 
int open_and_lock_tables_derived(THD *thd, TableList *tables, bool derived);
 
454
int open_and_lock_tables_derived(THD *thd, TABLE_LIST *tables, bool derived);
453
455
/* simple open_and_lock_tables without derived handling */
454
 
inline int simple_open_n_lock_tables(THD *thd, TableList *tables)
 
456
inline int simple_open_n_lock_tables(THD *thd, TABLE_LIST *tables)
455
457
{
456
458
  return open_and_lock_tables_derived(thd, tables, false);
457
459
}
458
460
/* open_and_lock_tables with derived handling */
459
 
inline int open_and_lock_tables(THD *thd, TableList *tables)
 
461
inline int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
460
462
{
461
463
  return open_and_lock_tables_derived(thd, tables, true);
462
464
}
463
465
/* simple open_and_lock_tables without derived handling for single table */
464
 
Table *open_n_lock_single_table(THD *thd, TableList *table_l,
 
466
TABLE *open_n_lock_single_table(THD *thd, TABLE_LIST *table_l,
465
467
                                thr_lock_type lock_type);
466
 
bool open_normal_and_derived_tables(THD *thd, TableList *tables, uint32_t flags);
467
 
int lock_tables(THD *thd, TableList *tables, uint32_t counter, bool *need_reopen);
468
 
int decide_logging_format(THD *thd, TableList *tables);
469
 
Table *open_temporary_table(THD *thd, const char *path, const char *db,
 
468
bool open_normal_and_derived_tables(THD *thd, TABLE_LIST *tables, uint flags);
 
469
int lock_tables(THD *thd, TABLE_LIST *tables, uint counter, bool *need_reopen);
 
470
int decide_logging_format(THD *thd, TABLE_LIST *tables);
 
471
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
470
472
                            const char *table_name, bool link_in_list,
471
473
                            open_table_mode open_mode);
472
474
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
473
 
void free_io_cache(Table *entry);
474
 
void intern_close_table(Table *entry);
475
 
bool close_thread_table(THD *thd, Table **table_ptr);
 
475
void free_io_cache(TABLE *entry);
 
476
void intern_close_table(TABLE *entry);
 
477
bool close_thread_table(THD *thd, TABLE **table_ptr);
476
478
void close_temporary_tables(THD *thd);
477
 
void close_tables_for_reopen(THD *thd, TableList **tables);
478
 
TableList *find_table_in_list(TableList *table,
479
 
                               TableList *TableList::*link,
 
479
void close_tables_for_reopen(THD *thd, TABLE_LIST **tables);
 
480
TABLE_LIST *find_table_in_list(TABLE_LIST *table,
 
481
                               TABLE_LIST *TABLE_LIST::*link,
480
482
                               const char *db_name,
481
483
                               const char *table_name);
482
 
TableList *unique_table(THD *thd, TableList *table, TableList *table_list,
 
484
TABLE_LIST *unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
483
485
                         bool check_alias);
484
 
Table *find_temporary_table(THD *thd, const char *db, const char *table_name);
485
 
Table *find_temporary_table(THD *thd, TableList *table_list);
486
 
int drop_temporary_table(THD *thd, TableList *table_list);
487
 
void close_temporary_table(THD *thd, 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, TABLE_LIST *table_list);
 
488
int drop_temporary_table(THD *thd, TABLE_LIST *table_list);
 
489
void close_temporary_table(THD *thd, TABLE *table, bool free_share,
488
490
                           bool delete_table);
489
 
void close_temporary(Table *table, bool free_share, bool delete_table);
490
 
bool rename_temporary_table(THD* thd, Table *table, const char *new_db,
 
491
void close_temporary(TABLE *table, bool free_share, bool delete_table);
 
492
bool rename_temporary_table(THD* thd, TABLE *table, const char *new_db,
491
493
                            const char *table_name);
492
494
void remove_db_from_cache(const char *db);
493
495
void flush_tables();
500
502
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
501
503
#define RTFC_CHECK_KILLED_FLAG      0x0004
502
504
bool remove_table_from_cache(THD *thd, const char *db, const char *table,
503
 
                             uint32_t flags);
 
505
                             uint flags);
504
506
 
505
507
#define NORMAL_PART_NAME 0
506
508
#define TEMP_PART_NAME 1
513
515
#define WFRM_PACK_FRM 4
514
516
#define WFRM_KEEP_SHARE 8
515
517
 
516
 
bool close_cached_tables(THD *thd, TableList *tables, bool have_lock,
 
518
/* Functions to work with system tables. */
 
519
bool open_system_tables_for_read(THD *thd, TABLE_LIST *table_list,
 
520
                                 Open_tables_state *backup);
 
521
void close_system_tables(THD *thd, Open_tables_state *backup);
 
522
TABLE *open_system_table_for_update(THD *thd, TABLE_LIST *one_table);
 
523
 
 
524
bool close_cached_tables(THD *thd, TABLE_LIST *tables, bool have_lock,
517
525
                         bool wait_for_refresh, bool wait_for_placeholders);
518
526
bool close_cached_connection_tables(THD *thd, bool wait_for_refresh,
519
527
                                    LEX_STRING *connect_string,
521
529
void copy_field_from_tmp_record(Field *field,int offset);
522
530
bool fill_record(THD * thd, List<Item> &fields, List<Item> &values, bool ignore_errors);
523
531
bool fill_record(THD *thd, Field **field, List<Item> &values, bool ignore_errors);
524
 
OPEN_TableList *list_open_tables(THD *thd, const char *db, const char *wild);
 
532
OPEN_TABLE_LIST *list_open_tables(THD *thd, const char *db, const char *wild);
525
533
 
526
 
inline TableList *find_table_in_global_list(TableList *table,
 
534
inline TABLE_LIST *find_table_in_global_list(TABLE_LIST *table,
527
535
                                             const char *db_name,
528
536
                                             const char *table_name)
529
537
{
530
 
  return find_table_in_list(table, &TableList::next_global,
 
538
  return find_table_in_list(table, &TABLE_LIST::next_global,
531
539
                            db_name, table_name);
532
540
}
533
541
 
534
 
inline TableList *find_table_in_local_list(TableList *table,
 
542
inline TABLE_LIST *find_table_in_local_list(TABLE_LIST *table,
535
543
                                            const char *db_name,
536
544
                                            const char *table_name)
537
545
{
538
 
  return find_table_in_list(table, &TableList::next_local,
 
546
  return find_table_in_list(table, &TABLE_LIST::next_local,
539
547
                            db_name, table_name);
540
548
}
541
549
 
544
552
bool eval_const_cond(COND *cond);
545
553
 
546
554
/* sql_load.cc */
547
 
int mysql_load(THD *thd, sql_exchange *ex, TableList *table_list,
 
555
int mysql_load(THD *thd, sql_exchange *ex, TABLE_LIST *table_list,
548
556
                List<Item> &fields_vars, List<Item> &set_fields,
549
557
                List<Item> &set_values_list,
550
558
                enum enum_duplicates handle_duplicates, bool ignore,
551
559
                bool local_file);
552
 
int write_record(THD *thd, Table *table, COPY_INFO *info);
 
560
int write_record(THD *thd, TABLE *table, COPY_INFO *info);
553
561
 
554
562
 
555
563
/* sql_test.cc */
556
564
void print_where(COND *cond,const char *info, enum_query_type query_type);
557
565
void print_cached_tables(void);
558
 
void TEST_filesort(SORT_FIELD *sortorder,uint32_t s_length);
559
 
void print_plan(JOIN* join,uint32_t idx, double record_count, double read_time,
 
566
void TEST_filesort(SORT_FIELD *sortorder,uint s_length);
 
567
void print_plan(JOIN* join,uint idx, double record_count, double read_time,
560
568
                double current_read_time, const char *info);
561
569
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
562
 
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
 
570
void dump_TABLE_LIST_graph(SELECT_LEX *select_lex, TABLE_LIST* tl);
563
571
void mysql_print_status();
564
572
 
565
573
/* key.cc */
566
 
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
567
 
                 uint32_t *key_length, uint32_t *keypart);
568
 
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
569
 
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
 
574
int find_ref_key(KEY *key, uint key_count, uchar *record, Field *field,
 
575
                 uint *key_length, uint *keypart);
 
576
void key_copy(uchar *to_key, uchar *from_record, KEY *key_info, uint key_length);
 
577
void key_restore(uchar *to_record, uchar *from_key, KEY *key_info,
570
578
                 uint16_t key_length);
571
 
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
572
 
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
573
 
void key_unpack(String *to,Table *form,uint32_t index);
574
 
bool is_key_used(Table *table, uint32_t idx, const MY_BITMAP *fields);
575
 
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
576
 
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
 
579
void key_zero_nulls(uchar *tuple, KEY *key_info);
 
580
bool key_cmp_if_same(TABLE *form,const uchar *key,uint index,uint key_length);
 
581
void key_unpack(String *to,TABLE *form,uint index);
 
582
bool is_key_used(TABLE *table, uint idx, const MY_BITMAP *fields);
 
583
int key_cmp(KEY_PART_INFO *key_part, const uchar *key, uint key_length);
 
584
extern "C" int key_rec_cmp(void *key_info, uchar *a, uchar *b);
577
585
 
578
586
bool init_errmessage(void);
579
587
File open_binlog(IO_CACHE *log, const char *log_file_name,
591
599
 
592
600
/* item_func.cc */
593
601
extern bool check_reserved_words(LEX_STRING *name);
594
 
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
 
602
extern enum_field_types agg_field_type(Item **items, uint nitems);
595
603
 
596
604
/* strfunc.cc */
597
 
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
598
 
                   char **err_pos, uint32_t *err_len, bool *set_warning);
599
 
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
 
605
uint64_t find_set(TYPELIB *lib, const char *x, uint length, const CHARSET_INFO * const cs,
 
606
                   char **err_pos, uint *err_len, bool *set_warning);
 
607
uint find_type(const TYPELIB *lib, const char *find, uint length,
600
608
               bool part_match);
601
 
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
 
609
uint find_type2(const TYPELIB *lib, const char *find, uint length,
602
610
                const CHARSET_INFO *cs);
603
611
void unhex_type2(TYPELIB *lib);
604
 
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
612
uint check_word(TYPELIB *lib, const char *val, const char *end,
605
613
                const char **end_of_word);
606
614
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
607
615
                         const CHARSET_INFO * const cs);
608
616
 
609
617
 
610
 
bool is_keyword(const char *name, uint32_t len);
 
618
bool is_keyword(const char *name, uint len);
611
619
 
612
620
#define MY_DB_OPT_FILE "db.opt"
613
621
bool my_database_names_init(void);
627
635
*/
628
636
 
629
637
extern time_t server_start_time, flush_status_time;
630
 
extern char *opt_mysql_tmpdir;
 
638
extern char *opt_mysql_tmpdir, mysql_charsets_dir[];
631
639
            
632
640
#define mysql_tmpdir (my_tmpdir(&mysql_tmpdir_list))
633
641
extern MY_TMPDIR mysql_tmpdir_list;
660
668
extern ulong max_connections,max_connect_errors, connect_timeout;
661
669
extern bool slave_allow_batching;
662
670
extern ulong slave_net_timeout, slave_trans_retries;
663
 
extern uint32_t max_user_connections;
 
671
extern uint max_user_connections;
664
672
extern ulong what_to_log,flush_time;
 
673
extern ulong query_buff_size;
665
674
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
666
675
extern ulong max_binlog_size, max_relay_log_size;
667
676
extern ulong opt_binlog_rows_event_max_size;
673
682
extern ulong tc_log_page_waits;
674
683
extern bool relay_log_purge;
675
684
extern bool opt_innodb_safe_binlog, opt_innodb;
676
 
extern uint32_t test_flags,select_errors,ha_open_options;
677
 
extern uint32_t protocol_version, mysqld_port, dropping_tables;
678
 
extern uint32_t delay_key_write_options;
 
685
extern uint test_flags,select_errors,ha_open_options;
 
686
extern uint protocol_version, mysqld_port, dropping_tables;
 
687
extern uint delay_key_write_options;
679
688
extern bool opt_endinfo, using_udf_functions;
680
689
extern bool locked_in_memory;
681
690
extern bool opt_using_transactions;
687
696
extern bool opt_log_queries_not_using_indexes;
688
697
extern bool opt_character_set_client_handshake;
689
698
extern bool volatile abort_loop, shutdown_in_progress;
690
 
extern uint32_t volatile thread_count, thread_running, global_read_lock;
691
 
extern uint32_t connection_count;
 
699
extern uint volatile thread_count, thread_running, global_read_lock;
 
700
extern uint connection_count;
692
701
extern bool opt_sql_bin_update;
693
702
extern bool opt_safe_user_create;
694
703
extern bool opt_no_mix_types;
698
707
extern bool use_temp_pool;
699
708
extern ulong slave_exec_mode_options;
700
709
extern bool opt_readonly;
 
710
extern bool opt_sync_frm;
701
711
extern bool opt_secure_auth;
702
712
extern char* opt_secure_file_priv;
703
713
extern bool opt_log_slow_admin_statements;
704
714
extern bool opt_log_slow_slave_statements;
705
715
extern bool opt_noacl;
706
716
extern bool opt_old_style_user_limits;
707
 
extern uint32_t opt_crash_binlog_innodb;
 
717
extern uint opt_crash_binlog_innodb;
708
718
extern char *default_tz_name;
709
719
extern char *opt_logname, *opt_slow_logname;
710
720
extern const char *log_output_str;
711
721
 
712
 
extern DRIZZLE_BIN_LOG mysql_bin_log;
 
722
extern MYSQL_BIN_LOG mysql_bin_log;
713
723
extern LOGGER logger;
714
 
extern TableList general_log, slow_log;
 
724
extern TABLE_LIST general_log, slow_log;
715
725
extern FILE *stderror_file;
716
726
extern pthread_key(MEM_ROOT**,THR_MALLOC);
717
727
extern pthread_mutex_t LOCK_mysql_create_db,LOCK_open, LOCK_lock_db,
718
 
       LOCK_thread_count,LOCK_user_locks, LOCK_status,
 
728
       LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status,
719
729
       LOCK_error_log, LOCK_uuid_generator,
720
730
       LOCK_crypt, LOCK_timezone,
721
731
       LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
740
750
extern const char *opt_date_time_formats[];
741
751
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
742
752
 
 
753
extern String null_string;
743
754
extern HASH open_cache, lock_db_cache;
744
 
extern Table *unused_tables;
 
755
extern TABLE *unused_tables;
745
756
extern const char* any_db;
746
757
extern struct my_option my_long_options[];
747
758
extern const LEX_STRING view_type;
748
759
extern scheduler_functions thread_scheduler;
749
760
extern TYPELIB thread_handling_typelib;
750
761
extern uint8_t uc_update_queries[SQLCOM_END+1];
751
 
extern uint32_t sql_command_flags[];
 
762
extern uint sql_command_flags[];
752
763
extern TYPELIB log_output_typelib;
753
764
 
754
765
/* optional things, have_* variables */
763
774
 
764
775
extern pthread_t signal_thread;
765
776
 
766
 
DRIZZLE_LOCK *mysql_lock_tables(THD *thd, Table **table, uint32_t count,
767
 
                              uint32_t flags, bool *need_reopen);
 
777
MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count,
 
778
                              uint flags, bool *need_reopen);
768
779
/* mysql_lock_tables() and open_table() flags bits */
769
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
770
 
#define DRIZZLE_LOCK_IGNORE_FLUSH                 0x0002
771
 
#define DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
772
 
#define DRIZZLE_OPEN_TEMPORARY_ONLY               0x0008
773
 
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
774
 
#define DRIZZLE_LOCK_PERF_SCHEMA                  0x0020
 
780
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
 
781
#define MYSQL_LOCK_IGNORE_FLUSH                 0x0002
 
782
#define MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
 
783
#define MYSQL_OPEN_TEMPORARY_ONLY               0x0008
 
784
#define MYSQL_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
 
785
#define MYSQL_LOCK_PERF_SCHEMA                  0x0020
775
786
 
776
 
void mysql_unlock_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
777
 
void mysql_unlock_read_tables(THD *thd, DRIZZLE_LOCK *sql_lock);
778
 
void mysql_unlock_some_tables(THD *thd, Table **table,uint32_t count);
779
 
void mysql_lock_remove(THD *thd, DRIZZLE_LOCK *locked,Table *table,
 
787
void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock);
 
788
void mysql_unlock_read_tables(THD *thd, MYSQL_LOCK *sql_lock);
 
789
void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count);
 
790
void mysql_lock_remove(THD *thd, MYSQL_LOCK *locked,TABLE *table,
780
791
                       bool always_unlock);
781
 
void mysql_lock_abort(THD *thd, Table *table, bool upgrade_lock);
782
 
void mysql_lock_downgrade_write(THD *thd, Table *table,
 
792
void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock);
 
793
void mysql_lock_downgrade_write(THD *thd, TABLE *table,
783
794
                                thr_lock_type new_lock_type);
784
 
bool mysql_lock_abort_for_thread(THD *thd, Table *table);
785
 
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
786
 
TableList *mysql_lock_have_duplicate(THD *thd, TableList *needle,
787
 
                                      TableList *haystack);
 
795
bool mysql_lock_abort_for_thread(THD *thd, TABLE *table);
 
796
MYSQL_LOCK *mysql_lock_merge(MYSQL_LOCK *a,MYSQL_LOCK *b);
 
797
TABLE_LIST *mysql_lock_have_duplicate(THD *thd, TABLE_LIST *needle,
 
798
                                      TABLE_LIST *haystack);
788
799
bool lock_global_read_lock(THD *thd);
789
800
void unlock_global_read_lock(THD *thd);
790
801
bool wait_if_global_read_lock(THD *thd, bool abort_on_refresh,
794
805
bool set_protect_against_global_read_lock(void);
795
806
void unset_protect_against_global_read_lock(void);
796
807
void broadcast_refresh(void);
797
 
int try_transactional_lock(THD *thd, TableList *table_list);
798
 
int check_transactional_lock(THD *thd, TableList *table_list);
799
 
int set_handler_table_locks(THD *thd, TableList *table_list,
 
808
int try_transactional_lock(THD *thd, TABLE_LIST *table_list);
 
809
int check_transactional_lock(THD *thd, TABLE_LIST *table_list);
 
810
int set_handler_table_locks(THD *thd, TABLE_LIST *table_list,
800
811
                            bool transactional);
801
812
 
802
813
/* Lock based on name */
803
 
int lock_and_wait_for_table_name(THD *thd, TableList *table_list);
804
 
int lock_table_name(THD *thd, TableList *table_list, bool check_in_use);
805
 
void unlock_table_name(THD *thd, TableList *table_list);
806
 
bool wait_for_locked_table_names(THD *thd, TableList *table_list);
807
 
bool lock_table_names(THD *thd, TableList *table_list);
808
 
void unlock_table_names(THD *thd, TableList *table_list,
809
 
                        TableList *last_table);
810
 
bool lock_table_names_exclusively(THD *thd, TableList *table_list);
 
814
int lock_and_wait_for_table_name(THD *thd, TABLE_LIST *table_list);
 
815
int lock_table_name(THD *thd, TABLE_LIST *table_list, bool check_in_use);
 
816
void unlock_table_name(THD *thd, TABLE_LIST *table_list);
 
817
bool wait_for_locked_table_names(THD *thd, TABLE_LIST *table_list);
 
818
bool lock_table_names(THD *thd, TABLE_LIST *table_list);
 
819
void unlock_table_names(THD *thd, TABLE_LIST *table_list,
 
820
                        TABLE_LIST *last_table);
 
821
bool lock_table_names_exclusively(THD *thd, TABLE_LIST *table_list);
811
822
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, 
812
 
                                                     TableList *table_list);
813
 
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, unsigned char *key,
 
823
                                                     TABLE_LIST *table_list);
 
824
bool is_table_name_exclusively_locked_by_this_thread(THD *thd, uchar *key,
814
825
                                                     int key_length);
815
826
 
816
827
 
822
833
                      const char *db, const char *table,
823
834
                      HA_CREATE_INFO *create_info,
824
835
                      List<Create_field> &create_field,
825
 
                      uint32_t key_count,KEY *key_info,handler *db_type);
 
836
                      uint key_count,KEY *key_info,handler *db_type);
826
837
int rea_create_table(THD *thd, const char *path,
827
838
                     const char *db, const char *table_name,
828
839
                     HA_CREATE_INFO *create_info,
829
840
                     List<Create_field> &create_field,
830
 
                     uint32_t key_count,KEY *key_info,
 
841
                     uint key_count,KEY *key_info,
831
842
                     handler *file);
832
 
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
 
843
int format_number(uint inputflag,uint max_length,char * pos,uint length,
833
844
                  char * *errpos);
834
845
 
835
846
/* table.cc */
836
 
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
837
 
                               uint32_t key_length);
 
847
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
 
848
                               uint key_length);
838
849
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
839
 
                          uint32_t key_length,
 
850
                          uint key_length,
840
851
                          const char *table_name, const char *path);
841
852
void free_table_share(TABLE_SHARE *share);
842
 
int open_table_def(THD *thd, TABLE_SHARE *share, uint32_t db_flags);
 
853
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
843
854
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
844
855
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
845
 
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
846
 
                          Table *outparam, open_table_mode open_mode);
847
 
int readfrm(const char *name, unsigned char **data, size_t *length);
848
 
int writefrm(const char* name, const unsigned char* data, size_t len);
849
 
int closefrm(Table *table, bool free_share);
850
 
int read_string(File file, unsigned char* *to, size_t length);
851
 
void free_blobs(Table *table);
 
856
                          uint db_stat, uint prgflag, uint ha_open_flags,
 
857
                          TABLE *outparam, open_table_mode open_mode);
 
858
int readfrm(const char *name, uchar **data, size_t *length);
 
859
int writefrm(const char* name, const uchar* data, size_t len);
 
860
int closefrm(TABLE *table, bool free_share);
 
861
int read_string(File file, uchar* *to, size_t length);
 
862
void free_blobs(TABLE *table);
852
863
int set_zone(int nr,int min_zone,int max_zone);
853
864
ulong convert_period_to_month(ulong period);
854
865
ulong convert_month_to_period(ulong month);
855
 
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
856
 
                         uint32_t *day);
 
866
void get_date_from_daynr(long daynr,uint *year, uint *month,
 
867
                         uint *day);
857
868
my_time_t TIME_to_timestamp(THD *thd, const DRIZZLE_TIME *t, bool *not_exist);
858
 
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
859
 
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
860
 
                                         DRIZZLE_TIME *l_time, uint32_t flags);
 
869
bool str_to_time_with_warn(const char *str,uint length,DRIZZLE_TIME *l_time);
 
870
timestamp_type str_to_datetime_with_warn(const char *str, uint length,
 
871
                                         DRIZZLE_TIME *l_time, uint flags);
861
872
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
862
873
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
863
874
 
864
875
void make_truncated_value_warning(THD *thd, DRIZZLE_ERROR::enum_warning_level level,
865
876
                                  const char *str_val,
866
 
                                  uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
 
877
                                  uint str_length, timestamp_type time_type,
867
878
                                  const char *field_name);
868
879
 
869
880
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
872
883
 
873
884
extern LEX_STRING interval_type_to_name[];
874
885
 
875
 
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
886
extern DATE_TIME_FORMAT *date_time_format_make(timestamp_type format_type,
876
887
                                               const char *format_str,
877
 
                                               uint32_t format_length);
 
888
                                               uint format_length);
878
889
extern DATE_TIME_FORMAT *date_time_format_copy(THD *thd,
879
890
                                               DATE_TIME_FORMAT *format);
880
891
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
881
 
                                                             enum enum_drizzle_timestamp_type type);
 
892
                                     timestamp_type type);
882
893
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
883
 
                                             enum enum_drizzle_timestamp_type type, String *str);
 
894
                           timestamp_type type, String *str);
884
895
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
885
896
                   String *str);
886
897
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
892
903
                             Item *warn_item, bool *is_null);
893
904
 
894
905
int test_if_number(char *str,int *res,bool allow_wildcards);
895
 
void change_byte(unsigned char *,uint,char,char);
896
 
void init_read_record(READ_RECORD *info, THD *thd, Table *reg_form,
 
906
void change_byte(uchar *,uint,char,char);
 
907
void init_read_record(READ_RECORD *info, THD *thd, TABLE *reg_form,
897
908
                      SQL_SELECT *select,
898
909
                      int use_record_cache, bool print_errors);
899
 
void init_read_record_idx(READ_RECORD *info, THD *thd, Table *table, 
900
 
                          bool print_error, uint32_t idx);
 
910
void init_read_record_idx(READ_RECORD *info, THD *thd, TABLE *table, 
 
911
                          bool print_error, uint idx);
901
912
void end_read_record(READ_RECORD *info);
902
 
ha_rows filesort(THD *thd, Table *form,struct st_sort_field *sortorder,
903
 
                 uint32_t s_length, SQL_SELECT *select,
 
913
ha_rows filesort(THD *thd, TABLE *form,struct st_sort_field *sortorder,
 
914
                 uint s_length, SQL_SELECT *select,
904
915
                 ha_rows max_rows, bool sort_positions,
905
916
                 ha_rows *examined_rows);
906
 
void filesort_free_buffers(Table *table, bool full);
907
 
void change_double_for_sort(double nr,unsigned char *to);
 
917
void filesort_free_buffers(TABLE *table, bool full);
 
918
void change_double_for_sort(double nr,uchar *to);
908
919
double my_double_round(double value, int64_t dec, bool dec_unsigned,
909
920
                       bool truncate);
910
921
int get_quick_record(SQL_SELECT *select);
911
922
 
912
923
int calc_weekday(long daynr,bool sunday_first_day_of_week);
913
 
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
914
 
void find_date(char *pos,uint32_t *vek,uint32_t flag);
 
924
uint calc_week(DRIZZLE_TIME *l_time, uint week_behaviour, uint *year);
 
925
void find_date(char *pos,uint *vek,uint flag);
915
926
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
916
927
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
917
 
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
918
 
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
 
928
ulong get_form_pos(File file, uchar *head, TYPELIB *save_names);
 
929
ulong make_new_entry(File file,uchar *fileinfo,TYPELIB *formnames,
919
930
                     const char *newname);
920
931
ulong next_io_size(ulong pos);
921
 
void append_unescaped(String *res, const char *pos, uint32_t length);
 
932
void append_unescaped(String *res, const char *pos, uint length);
922
933
int create_frm(THD *thd, const char *name, const char *db, const char *table,
923
 
               uint32_t reclength, unsigned char *fileinfo,
924
 
               HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
 
934
               uint reclength, uchar *fileinfo,
 
935
               HA_CREATE_INFO *create_info, uint keys, KEY *key_info);
 
936
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
925
937
int rename_file_ext(const char * from,const char * to,const char * ext);
926
938
bool check_db_name(LEX_STRING *db);
927
939
bool check_column_name(const char *name);
928
 
bool check_table_name(const char *name, uint32_t length);
 
940
bool check_table_name(const char *name, uint length);
929
941
char *get_field(MEM_ROOT *mem, Field *field);
930
942
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
931
943
char *fn_rext(char *name);
932
944
 
933
945
/* Conversion functions */
934
 
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
935
 
                          const char *table, const char *ext, uint32_t flags);
 
946
uint build_table_filename(char *buff, size_t bufflen, const char *db,
 
947
                          const char *table, const char *ext, uint flags);
936
948
 
937
949
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
938
950
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  9
977
989
  return thd->lex->current_select->add_group_to_list(thd, item, asc);
978
990
}
979
991
 
980
 
inline void mark_as_null_row(Table *table)
 
992
inline void mark_as_null_row(TABLE *table)
981
993
{
982
994
  table->null_row=1;
983
995
  table->status|=STATUS_NULL_ROW;
984
996
  memset(table->null_flags, 255, table->s->null_bytes);
985
997
}
986
998
 
987
 
inline void table_case_convert(char * name, uint32_t length)
 
999
inline void table_case_convert(char * name, uint length)
988
1000
{
989
1001
  if (lower_case_table_names)
990
1002
    files_charset_info->cset->casedn(files_charset_info,
1018
1030
/**
1019
1031
  clean/setup table fields and map.
1020
1032
 
1021
 
  @param table        Table structure pointer (which should be setup)
1022
 
  @param table_list   TableList structure pointer (owner of Table)
 
1033
  @param table        TABLE structure pointer (which should be setup)
 
1034
  @param table_list   TABLE_LIST structure pointer (owner of TABLE)
1023
1035
  @param tablenr     table number
1024
1036
*/
1025
 
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
 
1037
inline void setup_table_map(TABLE *table, TABLE_LIST *table_list, uint tablenr)
1026
1038
{
1027
1039
  table->used_fields= 0;
1028
1040
  table->const_table= 0;
1029
1041
  table->null_row= 0;
1030
1042
  table->status= STATUS_NO_RECORD;
1031
1043
  table->maybe_null= table_list->outer_join;
1032
 
  TableList *embedding= table_list->embedding;
 
1044
  TABLE_LIST *embedding= table_list->embedding;
1033
1045
  while (!table->maybe_null && embedding)
1034
1046
  {
1035
1047
    table->maybe_null= embedding->outer_join;
1061
1073
/**
1062
1074
  return true if the table was created explicitly.
1063
1075
*/
1064
 
inline bool is_user_table(Table * table)
 
1076
inline bool is_user_table(TABLE * table)
1065
1077
{
1066
1078
  const char *name= table->s->table_name.str;
1067
1079
  return strncmp(name, tmp_file_prefix, tmp_file_prefix_length);
1087
1099
 
1088
1100
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
1089
1101
void kill_delayed_threads(void);
1090
 
bool check_stack_overrun(THD *thd, long margin, unsigned char *dummy);
 
1102
bool check_stack_overrun(THD *thd, long margin, uchar *dummy);
1091
1103
 
1092
1104
/** 
1093
1105
 * Used by handlers to store things in schema tables