~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

  • Committer: Monty Taylor
  • Date: 2008-11-16 06:29:53 UTC
  • mto: (584.1.9 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081116062953-ivdltjmfe009b5fr
Moved stuff into item/

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
 */
 
19
 
 
20
/**
 
21
  @file
 
22
 
 
23
  @details
 
24
  Mostly this file is used in the server. But a little part of it is used in
 
25
  mysqlbinlog too (definition of SELECT_DISTINCT and others).
 
26
 
 
27
  @TODO Name this file better. "priv" could mean private, privileged, privileges.
 
28
*/
 
29
 
 
30
#ifndef DRIZZLED_SERVER_INCLUDES_H
 
31
#define DRIZZLED_SERVER_INCLUDES_H
 
32
 
 
33
/* Some forward declarations just for the server */
 
34
 
 
35
class Comp_creator;
 
36
typedef Comp_creator* (*chooser_compare_func_creator)(bool invert);
 
37
 
 
38
/**
 
39
 * Contains all headers, definitions, and declarations common to
 
40
 * the server and the plugin infrastructure, and not the client
 
41
 */
 
42
#include <drizzled/common_includes.h>
 
43
/* Range optimization API/library */
 
44
#include <drizzled/opt_range.h>
 
45
/* Simple error injection (crash) module */
 
46
#include <drizzled/error_injection.h>
 
47
/* API for connecting, logging in to a drizzled server */
 
48
#include <drizzled/connect.h>
 
49
/* Routines for dropping, repairing, checking schema tables */
 
50
#include <drizzled/sql_table.h>
 
51
 
 
52
/* information schema */
 
53
static const std::string INFORMATION_SCHEMA_NAME("information_schema");
 
54
 
 
55
 
 
56
#define is_schema_db(X) \
 
57
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
 
58
 
 
59
/* sql_base.cc */
 
60
#define TMP_TABLE_KEY_EXTRA 8
 
61
void set_item_name(Item *item,char *pos,uint32_t length);
 
62
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum enum_field_types type,
 
63
                       char *length, char *decimal,
 
64
                       uint32_t type_modifier,
 
65
                       enum column_format_type column_format,
 
66
                       Item *default_value, Item *on_update_value,
 
67
                       LEX_STRING *comment,
 
68
                       char *change, List<String> *interval_list,
 
69
                       const CHARSET_INFO * const cs,
 
70
                       virtual_column_info *vcol_info);
 
71
Create_field * new_create_field(Session *session, char *field_name, enum_field_types type,
 
72
                                char *length, char *decimals,
 
73
                                uint32_t type_modifier, 
 
74
                                Item *default_value, Item *on_update_value,
 
75
                                LEX_STRING *comment, char *change, 
 
76
                                List<String> *interval_list, CHARSET_INFO *cs,
 
77
                                virtual_column_info *vcol_info);
 
78
void store_position_for_column(const char *name);
 
79
bool add_to_list(Session *session, SQL_LIST &list,Item *group,bool asc);
 
80
bool push_new_name_resolution_context(Session *session,
 
81
                                      TableList *left_op,
 
82
                                      TableList *right_op);
 
83
void add_join_on(TableList *b,Item *expr);
 
84
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
 
85
                      SELECT_LEX *lex);
 
86
bool add_proc_to_list(Session *session, Item *item);
 
87
void unlink_open_table(Session *session, Table *find, bool unlock);
 
88
void drop_open_table(Session *session, Table *table, const char *db_name,
 
89
                     const char *table_name);
 
90
void update_non_unique_table_error(TableList *update,
 
91
                                   const char *operation,
 
92
                                   TableList *duplicate);
 
93
 
 
94
SQL_SELECT *make_select(Table *head, table_map const_tables,
 
95
                        table_map read_tables, COND *conds,
 
96
                        bool allow_null_cond,  int *error);
 
97
extern Item **not_found_item;
 
98
 
 
99
/*
 
100
  A set of constants used for checking non aggregated fields and sum
 
101
  functions mixture in the ONLY_FULL_GROUP_BY_MODE.
 
102
*/
 
103
#define NON_AGG_FIELD_USED  1
 
104
#define SUM_FUNC_USED       2
 
105
 
 
106
/*
 
107
  This enumeration type is used only by the function find_item_in_list
 
108
  to return the info on how an item has been resolved against a list
 
109
  of possibly aliased items.
 
110
  The item can be resolved: 
 
111
   - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
 
112
   - against non-aliased field name of the list  (RESOLVED_WITH_NO_ALIAS)
 
113
   - against an aliased field name of the list   (RESOLVED_BEHIND_ALIAS)
 
114
   - ignoring the alias name in cases when SQL requires to ignore aliases
 
115
     (e.g. when the resolved field reference contains a table name or
 
116
     when the resolved item is an expression)   (RESOLVED_IGNORING_ALIAS)    
 
117
*/
 
118
enum enum_resolution_type {
 
119
  NOT_RESOLVED=0,
 
120
  RESOLVED_IGNORING_ALIAS,
 
121
  RESOLVED_BEHIND_ALIAS,
 
122
  RESOLVED_WITH_NO_ALIAS,
 
123
  RESOLVED_AGAINST_ALIAS
 
124
};
 
125
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
 
126
                          find_item_error_report_type report_error,
 
127
                          enum_resolution_type *resolution);
 
128
bool get_key_map_from_key_list(key_map *map, Table *table,
 
129
                               List<String> *index_list);
 
130
bool insert_fields(Session *session, Name_resolution_context *context,
 
131
                   const char *db_name, const char *table_name,
 
132
                   List_iterator<Item> *it, bool any_privileges);
 
133
bool setup_tables(Session *session, Name_resolution_context *context,
 
134
                  List<TableList> *from_clause, TableList *tables,
 
135
                  TableList **leaves, bool select_insert);
 
136
bool setup_tables_and_check_access(Session *session, 
 
137
                                   Name_resolution_context *context,
 
138
                                   List<TableList> *from_clause, 
 
139
                                   TableList *tables, 
 
140
                                   TableList **leaves, 
 
141
                                   bool select_insert);
 
142
int setup_wild(Session *session, TableList *tables, List<Item> &fields,
 
143
               List<Item> *sum_func_list, uint32_t wild_num);
 
144
bool setup_fields(Session *session, Item** ref_pointer_array,
 
145
                  List<Item> &item, enum_mark_columns mark_used_columns,
 
146
                  List<Item> *sum_func_list, bool allow_sum_func);
 
147
inline bool setup_fields_with_no_wrap(Session *session, Item **ref_pointer_array,
 
148
                                      List<Item> &item,
 
149
                                      enum_mark_columns mark_used_columns,
 
150
                                      List<Item> *sum_func_list,
 
151
                                      bool allow_sum_func)
 
152
{
 
153
  bool res;
 
154
  res= setup_fields(session, ref_pointer_array, item, mark_used_columns, sum_func_list,
 
155
                    allow_sum_func);
 
156
  return res;
 
157
}
 
158
int setup_conds(Session *session, TableList *tables, TableList *leaves,
 
159
                COND **conds);
 
160
int setup_ftfuncs(SELECT_LEX* select);
 
161
int init_ftfuncs(Session *session, SELECT_LEX* select, bool no_order);
 
162
void wait_for_condition(Session *session, pthread_mutex_t *mutex,
 
163
                        pthread_cond_t *cond);
 
164
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
 
165
/* open_and_lock_tables with optional derived handling */
 
166
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
 
167
/* simple open_and_lock_tables without derived handling */
 
168
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
 
169
{
 
170
  return open_and_lock_tables_derived(session, tables, false);
 
171
}
 
172
/* open_and_lock_tables with derived handling */
 
173
inline int open_and_lock_tables(Session *session, TableList *tables)
 
174
{
 
175
  return open_and_lock_tables_derived(session, tables, true);
 
176
}
 
177
/* simple open_and_lock_tables without derived handling for single table */
 
178
Table *open_n_lock_single_table(Session *session, TableList *table_l,
 
179
                                thr_lock_type lock_type);
 
180
bool open_normal_and_derived_tables(Session *session, TableList *tables, uint32_t flags);
 
181
int lock_tables(Session *session, TableList *tables, uint32_t counter, bool *need_reopen);
 
182
int decide_logging_format(Session *session);
 
183
Table *open_temporary_table(Session *session, const char *path, const char *db,
 
184
                            const char *table_name, bool link_in_list,
 
185
                            open_table_mode open_mode);
 
186
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
 
187
void free_io_cache(Table *entry);
 
188
void intern_close_table(Table *entry);
 
189
bool close_thread_table(Session *session, Table **table_ptr);
 
190
void close_temporary_tables(Session *session);
 
191
void close_tables_for_reopen(Session *session, TableList **tables);
 
192
TableList *find_table_in_list(TableList *table,
 
193
                               TableList *TableList::*link,
 
194
                               const char *db_name,
 
195
                               const char *table_name);
 
196
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
 
197
                         bool check_alias);
 
198
Table *find_temporary_table(Session *session, const char *db, const char *table_name);
 
199
Table *find_temporary_table(Session *session, TableList *table_list);
 
200
int drop_temporary_table(Session *session, TableList *table_list);
 
201
void close_temporary_table(Session *session, Table *table, bool free_share,
 
202
                           bool delete_table);
 
203
void close_temporary(Table *table, bool free_share, bool delete_table);
 
204
bool rename_temporary_table(Session* session, Table *table, const char *new_db,
 
205
                            const char *table_name);
 
206
void remove_db_from_cache(const char *db);
 
207
void flush_tables();
 
208
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
 
209
char *make_default_log_name(char *buff,const char* log_ext);
 
210
 
 
211
/* bits for last argument to remove_table_from_cache() */
 
212
#define RTFC_NO_FLAG                0x0000
 
213
#define RTFC_OWNED_BY_Session_FLAG      0x0001
 
214
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
 
215
#define RTFC_CHECK_KILLED_FLAG      0x0004
 
216
bool remove_table_from_cache(Session *session, const char *db, const char *table,
 
217
                             uint32_t flags);
 
218
 
 
219
#define NORMAL_PART_NAME 0
 
220
#define TEMP_PART_NAME 1
 
221
#define RENAMED_PART_NAME 2
 
222
 
 
223
void mem_alloc_error(size_t size);
 
224
 
 
225
#define WFRM_WRITE_SHADOW 1
 
226
#define WFRM_INSTALL_SHADOW 2
 
227
#define WFRM_PACK_FRM 4
 
228
#define WFRM_KEEP_SHARE 8
 
229
 
 
230
bool close_cached_tables(Session *session, TableList *tables, bool have_lock,
 
231
                         bool wait_for_refresh, bool wait_for_placeholders);
 
232
bool close_cached_connection_tables(Session *session, bool wait_for_refresh,
 
233
                                    LEX_STRING *connect_string,
 
234
                                    bool have_lock= false);
 
235
void copy_field_from_tmp_record(Field *field,int offset);
 
236
bool fill_record(Session * session, List<Item> &fields, List<Item> &values, bool ignore_errors);
 
237
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors);
 
238
OPEN_TableList *list_open_tables(Session *session, const char *db, const char *wild);
 
239
 
 
240
inline TableList *find_table_in_global_list(TableList *table,
 
241
                                             const char *db_name,
 
242
                                             const char *table_name)
 
243
{
 
244
  return find_table_in_list(table, &TableList::next_global,
 
245
                            db_name, table_name);
 
246
}
 
247
 
 
248
inline TableList *find_table_in_local_list(TableList *table,
 
249
                                            const char *db_name,
 
250
                                            const char *table_name)
 
251
{
 
252
  return find_table_in_list(table, &TableList::next_local,
 
253
                            db_name, table_name);
 
254
}
 
255
 
 
256
 
 
257
/* sql_calc.cc */
 
258
bool eval_const_cond(COND *cond);
 
259
 
 
260
/* sql_load.cc */
 
261
int mysql_load(Session *session, sql_exchange *ex, TableList *table_list,
 
262
                List<Item> &fields_vars, List<Item> &set_fields,
 
263
                List<Item> &set_values_list,
 
264
                enum enum_duplicates handle_duplicates, bool ignore,
 
265
                bool local_file);
 
266
int write_record(Session *session, Table *table, COPY_INFO *info);
 
267
 
 
268
 
 
269
/* sql_test.cc */
 
270
void print_where(COND *cond,const char *info, enum_query_type query_type);
 
271
void print_cached_tables(void);
 
272
void TEST_filesort(SORT_FIELD *sortorder,uint32_t s_length);
 
273
void print_plan(JOIN* join,uint32_t idx, double record_count, double read_time,
 
274
                double current_read_time, const char *info);
 
275
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
 
276
void dump_TableList_graph(SELECT_LEX *select_lex, TableList* tl);
 
277
void mysql_print_status();
 
278
 
 
279
/* key.cc */
 
280
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
 
281
                 uint32_t *key_length, uint32_t *keypart);
 
282
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
 
283
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
 
284
                 uint16_t key_length);
 
285
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
 
286
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
 
287
void key_unpack(String *to,Table *form,uint32_t index);
 
288
bool is_key_used(Table *table, uint32_t idx, const MY_BITMAP *fields);
 
289
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
 
290
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
 
291
 
 
292
bool init_errmessage(void);
 
293
File open_binlog(IO_CACHE *log, const char *log_file_name,
 
294
                 const char **errmsg);
 
295
 
 
296
/* mysqld.cc */
 
297
void refresh_status(Session *session);
 
298
bool drizzle_rm_tmp_tables(void);
 
299
void handle_connection_in_main_thread(Session *session);
 
300
void create_thread_to_handle_connection(Session *session);
 
301
void unlink_session(Session *session);
 
302
bool one_thread_per_connection_end(Session *session, bool put_in_cache);
 
303
void flush_thread_cache();
 
304
 
 
305
/* item_func.cc */
 
306
extern bool check_reserved_words(LEX_STRING *name);
 
307
extern enum_field_types agg_field_type(Item **items, uint32_t nitems);
 
308
 
 
309
/* strfunc.cc */
 
310
uint64_t find_set(TYPELIB *lib, const char *x, uint32_t length, const CHARSET_INFO * const cs,
 
311
                   char **err_pos, uint32_t *err_len, bool *set_warning);
 
312
uint32_t find_type(const TYPELIB *lib, const char *find, uint32_t length,
 
313
               bool part_match);
 
314
uint32_t find_type2(const TYPELIB *lib, const char *find, uint32_t length,
 
315
                const CHARSET_INFO *cs);
 
316
void unhex_type2(TYPELIB *lib);
 
317
uint32_t check_word(TYPELIB *lib, const char *val, const char *end,
 
318
                const char **end_of_word);
 
319
int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle,
 
320
                         const CHARSET_INFO * const cs);
 
321
 
 
322
 
 
323
bool is_keyword(const char *name, uint32_t len);
 
324
 
 
325
#define MY_DB_OPT_FILE "db.opt"
 
326
bool my_database_names_init(void);
 
327
void my_database_names_free(void);
 
328
bool check_db_dir_existence(const char *db_name);
 
329
bool load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create);
 
330
bool load_db_opt_by_name(Session *session, const char *db_name,
 
331
                         HA_CREATE_INFO *db_create_info);
 
332
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name);
 
333
bool my_dbopt_init(void);
 
334
void my_dbopt_cleanup(void);
 
335
extern int creating_database; // How many database locks are made
 
336
extern int creating_table;    // How many mysql_create_table() are running
 
337
 
 
338
/*
 
339
  External variables
 
340
*/
 
341
 
 
342
extern time_t server_start_time, flush_status_time;
 
343
extern char *opt_drizzle_tmpdir;
 
344
            
 
345
#define drizzle_tmpdir (my_tmpdir(&drizzle_tmpdir_list))
 
346
extern MY_TMPDIR drizzle_tmpdir_list;
 
347
extern const LEX_STRING command_name[];
 
348
extern const char *first_keyword, *my_localhost, *delayed_user, *binary_keyword;
 
349
extern const char *myisam_recover_options_str;
 
350
extern const char *in_left_expr_name, *in_additional_cond, *in_having_cond;
 
351
extern const char * const TRG_EXT;
 
352
extern const char * const TRN_EXT;
 
353
extern Eq_creator eq_creator;
 
354
extern Ne_creator ne_creator;
 
355
extern Gt_creator gt_creator;
 
356
extern Lt_creator lt_creator;
 
357
extern Ge_creator ge_creator;
 
358
extern Le_creator le_creator;
 
359
extern char language[FN_REFLEN];
 
360
extern char glob_hostname[FN_REFLEN], drizzle_home[FN_REFLEN];
 
361
extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
 
362
extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
 
363
extern const double log_10[309];
 
364
extern uint64_t log_10_int[20];
 
365
extern uint64_t keybuff_size;
 
366
extern uint64_t session_startup_options;
 
367
extern ulong thread_id;
 
368
extern ulong binlog_cache_use, binlog_cache_disk_use;
 
369
extern ulong aborted_threads,aborted_connects;
 
370
extern ulong slave_open_temp_tables;
 
371
extern ulong slow_launch_threads, slow_launch_time;
 
372
extern ulong table_cache_size, table_def_size;
 
373
extern ulong max_connections,max_connect_errors, connect_timeout;
 
374
extern bool slave_allow_batching;
 
375
extern ulong slave_net_timeout, slave_trans_retries;
 
376
extern uint32_t max_user_connections;
 
377
extern ulong what_to_log,flush_time;
 
378
extern ulong binlog_cache_size, max_binlog_cache_size, open_files_limit;
 
379
extern ulong max_binlog_size, max_relay_log_size;
 
380
extern ulong opt_binlog_rows_event_max_size;
 
381
extern ulong rpl_recovery_rank, thread_cache_size, thread_pool_size;
 
382
extern ulong back_log;
 
383
extern ulong current_pid;
 
384
extern ulong expire_logs_days, sync_binlog_period, sync_binlog_counter;
 
385
extern ulong opt_tc_log_size, tc_log_max_pages_used, tc_log_page_size;
 
386
extern ulong tc_log_page_waits;
 
387
extern bool relay_log_purge;
 
388
extern bool opt_innodb_safe_binlog, opt_innodb;
 
389
extern uint32_t test_flags,select_errors,ha_open_options;
 
390
extern uint32_t protocol_version, drizzled_port, dropping_tables;
 
391
extern uint32_t delay_key_write_options;
 
392
extern bool opt_endinfo, using_udf_functions;
 
393
extern bool locked_in_memory;
 
394
extern bool opt_using_transactions;
 
395
extern bool using_update_log, server_id_supplied;
 
396
extern bool opt_update_log, opt_bin_log, opt_error_log;
 
397
extern bool opt_log; 
 
398
extern bool opt_slow_log;
 
399
extern ulong log_output_options;
 
400
extern bool opt_log_queries_not_using_indexes;
 
401
extern bool opt_character_set_client_handshake;
 
402
extern bool volatile abort_loop, shutdown_in_progress;
 
403
extern uint32_t volatile thread_count, thread_running, global_read_lock;
 
404
extern uint32_t connection_count;
 
405
extern bool opt_sql_bin_update;
 
406
extern bool opt_safe_user_create;
 
407
extern bool opt_no_mix_types;
 
408
extern bool opt_safe_show_db, opt_myisam_use_mmap;
 
409
extern bool opt_local_infile;
 
410
extern bool opt_slave_compressed_protocol;
 
411
extern bool use_temp_pool;
 
412
extern ulong slave_exec_mode_options;
 
413
extern bool opt_readonly;
 
414
extern char* opt_secure_file_priv;
 
415
extern bool opt_noacl;
 
416
extern bool opt_old_style_user_limits;
 
417
extern uint32_t opt_crash_binlog_innodb;
 
418
extern char *default_tz_name;
 
419
extern char *opt_logname, *opt_slow_logname;
 
420
extern const char *log_output_str;
 
421
 
 
422
extern DRIZZLE_BIN_LOG mysql_bin_log;
 
423
extern LOGGER logger;
 
424
extern TableList general_log, slow_log;
 
425
extern FILE *stderror_file;
 
426
extern pthread_key_t THR_MALLOC;
 
427
extern pthread_mutex_t LOCK_drizzle_create_db,LOCK_open, LOCK_lock_db,
 
428
       LOCK_thread_count,LOCK_user_locks, LOCK_status,
 
429
       LOCK_error_log, LOCK_uuid_generator,
 
430
       LOCK_crypt, LOCK_timezone,
 
431
       LOCK_slave_list, LOCK_active_mi, LOCK_global_read_lock,
 
432
       LOCK_global_system_variables, LOCK_user_conn,
 
433
       LOCK_bytes_sent, LOCK_bytes_received, LOCK_connection_count;
 
434
extern pthread_mutex_t LOCK_server_started;
 
435
extern rw_lock_t LOCK_sys_init_connect, LOCK_sys_init_slave;
 
436
extern rw_lock_t LOCK_system_variables_hash;
 
437
extern pthread_cond_t COND_refresh, COND_thread_count, COND_manager;
 
438
extern pthread_cond_t COND_global_read_lock;
 
439
extern pthread_attr_t connection_attrib;
 
440
extern I_List<Session> threads;
 
441
extern I_List<NAMED_LIST> key_caches;
 
442
extern MY_BITMAP temp_pool;
 
443
extern String my_empty_string;
 
444
extern const String my_null_string;
 
445
extern SHOW_VAR status_vars[];
 
446
extern struct system_variables max_system_variables;
 
447
extern struct system_status_var global_status_var;
 
448
extern struct rand_struct sql_rand;
 
449
 
 
450
extern const char *opt_date_time_formats[];
 
451
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
 
452
 
 
453
extern HASH open_cache, lock_db_cache;
 
454
extern Table *unused_tables;
 
455
extern const char* any_db;
 
456
extern struct my_option my_long_options[];
 
457
extern const LEX_STRING view_type;
 
458
extern TYPELIB thread_handling_typelib;
 
459
extern uint8_t uc_update_queries[SQLCOM_END+1];
 
460
extern uint32_t sql_command_flags[];
 
461
extern TYPELIB log_output_typelib;
 
462
 
 
463
/* optional things, have_* variables */
 
464
extern SHOW_COMP_OPTION have_community_features;
 
465
 
 
466
extern handlerton *myisam_hton;
 
467
extern handlerton *heap_hton;
 
468
 
 
469
extern SHOW_COMP_OPTION have_symlink;
 
470
extern SHOW_COMP_OPTION have_compress;
 
471
 
 
472
 
 
473
extern pthread_t signal_thread;
 
474
 
 
475
DRIZZLE_LOCK *mysql_lock_tables(Session *session, Table **table, uint32_t count,
 
476
                              uint32_t flags, bool *need_reopen);
 
477
/* mysql_lock_tables() and open_table() flags bits */
 
478
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_LOCK      0x0001
 
479
#define DRIZZLE_LOCK_IGNORE_FLUSH                 0x0002
 
480
#define DRIZZLE_LOCK_NOTIFY_IF_NEED_REOPEN        0x0004
 
481
#define DRIZZLE_OPEN_TEMPORARY_ONLY               0x0008
 
482
#define DRIZZLE_LOCK_IGNORE_GLOBAL_READ_ONLY      0x0010
 
483
#define DRIZZLE_LOCK_PERF_SCHEMA                  0x0020
 
484
 
 
485
void mysql_unlock_tables(Session *session, DRIZZLE_LOCK *sql_lock);
 
486
void mysql_unlock_read_tables(Session *session, DRIZZLE_LOCK *sql_lock);
 
487
void mysql_unlock_some_tables(Session *session, Table **table,uint32_t count);
 
488
void mysql_lock_remove(Session *session, DRIZZLE_LOCK *locked,Table *table,
 
489
                       bool always_unlock);
 
490
void mysql_lock_abort(Session *session, Table *table, bool upgrade_lock);
 
491
void mysql_lock_downgrade_write(Session *session, Table *table,
 
492
                                thr_lock_type new_lock_type);
 
493
bool mysql_lock_abort_for_thread(Session *session, Table *table);
 
494
DRIZZLE_LOCK *mysql_lock_merge(DRIZZLE_LOCK *a,DRIZZLE_LOCK *b);
 
495
TableList *mysql_lock_have_duplicate(Session *session, TableList *needle,
 
496
                                      TableList *haystack);
 
497
bool lock_global_read_lock(Session *session);
 
498
void unlock_global_read_lock(Session *session);
 
499
bool wait_if_global_read_lock(Session *session, bool abort_on_refresh,
 
500
                              bool is_not_commit);
 
501
void start_waiting_global_read_lock(Session *session);
 
502
bool make_global_read_lock_block_commit(Session *session);
 
503
bool set_protect_against_global_read_lock(void);
 
504
void unset_protect_against_global_read_lock(void);
 
505
void broadcast_refresh(void);
 
506
int try_transactional_lock(Session *session, TableList *table_list);
 
507
int check_transactional_lock(Session *session, TableList *table_list);
 
508
int set_handler_table_locks(Session *session, TableList *table_list,
 
509
                            bool transactional);
 
510
 
 
511
/* Lock based on name */
 
512
int lock_and_wait_for_table_name(Session *session, TableList *table_list);
 
513
int lock_table_name(Session *session, TableList *table_list, bool check_in_use);
 
514
void unlock_table_name(Session *session, TableList *table_list);
 
515
bool wait_for_locked_table_names(Session *session, TableList *table_list);
 
516
bool lock_table_names(Session *session, TableList *table_list);
 
517
void unlock_table_names(Session *session, TableList *table_list,
 
518
                        TableList *last_table);
 
519
bool lock_table_names_exclusively(Session *session, TableList *table_list);
 
520
bool is_table_name_exclusively_locked_by_this_thread(Session *session, 
 
521
                                                     TableList *table_list);
 
522
bool is_table_name_exclusively_locked_by_this_thread(Session *session, unsigned char *key,
 
523
                                                     int key_length);
 
524
 
 
525
 
 
526
/* old unireg functions */
 
527
 
 
528
void unireg_init(ulong options);
 
529
void unireg_end(void) __attribute__((noreturn));
 
530
bool mysql_create_frm(Session *session, const char *file_name,
 
531
                      const char *db, const char *table,
 
532
                      HA_CREATE_INFO *create_info,
 
533
                      List<Create_field> &create_field,
 
534
                      uint32_t key_count,KEY *key_info,handler *db_type);
 
535
int rea_create_table(Session *session, const char *path,
 
536
                     const char *db, const char *table_name,
 
537
                     HA_CREATE_INFO *create_info,
 
538
                     List<Create_field> &create_field,
 
539
                     uint32_t key_count,KEY *key_info,
 
540
                     handler *file);
 
541
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
 
542
                  char * *errpos);
 
543
 
 
544
/* table.cc */
 
545
TABLE_SHARE *alloc_table_share(TableList *table_list, char *key,
 
546
                               uint32_t key_length);
 
547
void init_tmp_table_share(Session *session, TABLE_SHARE *share, const char *key,
 
548
                          uint32_t key_length,
 
549
                          const char *table_name, const char *path);
 
550
void free_table_share(TABLE_SHARE *share);
 
551
int open_table_def(Session *session, TABLE_SHARE *share, uint32_t db_flags);
 
552
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
 
553
int open_table_from_share(Session *session, TABLE_SHARE *share, const char *alias,
 
554
                          uint32_t db_stat, uint32_t prgflag, uint32_t ha_open_flags,
 
555
                          Table *outparam, open_table_mode open_mode);
 
556
int readfrm(const char *name, unsigned char **data, size_t *length);
 
557
int writefrm(const char* name, const unsigned char* data, size_t len);
 
558
int closefrm(Table *table, bool free_share);
 
559
int read_string(File file, unsigned char* *to, size_t length);
 
560
void free_blobs(Table *table);
 
561
int set_zone(int nr,int min_zone,int max_zone);
 
562
uint32_t convert_period_to_month(uint32_t period);
 
563
uint32_t convert_month_to_period(uint32_t month);
 
564
void get_date_from_daynr(long daynr,uint32_t *year, uint32_t *month,
 
565
                         uint32_t *day);
 
566
my_time_t TIME_to_timestamp(Session *session, const DRIZZLE_TIME *t, bool *not_exist);
 
567
bool str_to_time_with_warn(const char *str,uint32_t length,DRIZZLE_TIME *l_time);
 
568
enum enum_drizzle_timestamp_type str_to_datetime_with_warn(const char *str, uint32_t length,
 
569
                                         DRIZZLE_TIME *l_time, uint32_t flags);
 
570
void localtime_to_TIME(DRIZZLE_TIME *to, struct tm *from);
 
571
void calc_time_from_sec(DRIZZLE_TIME *to, long seconds, long microseconds);
 
572
 
 
573
void make_truncated_value_warning(Session *session, DRIZZLE_ERROR::enum_warning_level level,
 
574
                                  const char *str_val,
 
575
                                  uint32_t str_length, enum enum_drizzle_timestamp_type time_type,
 
576
                                  const char *field_name);
 
577
 
 
578
bool date_add_interval(DRIZZLE_TIME *ltime, interval_type int_type, INTERVAL interval);
 
579
bool calc_time_diff(DRIZZLE_TIME *l_time1, DRIZZLE_TIME *l_time2, int l_sign,
 
580
                    int64_t *seconds_out, long *microseconds_out);
 
581
 
 
582
extern LEX_STRING interval_type_to_name[];
 
583
 
 
584
extern DATE_TIME_FORMAT *date_time_format_make(enum enum_drizzle_timestamp_type format_type,
 
585
                                               const char *format_str,
 
586
                                               uint32_t format_length);
 
587
extern DATE_TIME_FORMAT *date_time_format_copy(Session *session,
 
588
                                               DATE_TIME_FORMAT *format);
 
589
const char *get_date_time_format_str(KNOWN_DATE_TIME_FORMAT *format,
 
590
                                                             enum enum_drizzle_timestamp_type type);
 
591
extern bool make_date_time(DATE_TIME_FORMAT *format, DRIZZLE_TIME *l_time,
 
592
                                             enum enum_drizzle_timestamp_type type, String *str);
 
593
void make_datetime(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
594
                   String *str);
 
595
void make_date(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
596
               String *str);
 
597
void make_time(const DATE_TIME_FORMAT *format, const DRIZZLE_TIME *l_time,
 
598
               String *str);
 
599
int my_time_compare(DRIZZLE_TIME *a, DRIZZLE_TIME *b);
 
600
uint64_t get_datetime_value(Session *session, Item ***item_arg, Item **cache_arg,
 
601
                             Item *warn_item, bool *is_null);
 
602
 
 
603
int test_if_number(char *str,int *res,bool allow_wildcards);
 
604
void change_byte(unsigned char *,uint,char,char);
 
605
void init_read_record(READ_RECORD *info, Session *session, Table *reg_form,
 
606
                      SQL_SELECT *select,
 
607
                      int use_record_cache, bool print_errors);
 
608
void init_read_record_idx(READ_RECORD *info, Session *session, Table *table, 
 
609
                          bool print_error, uint32_t idx);
 
610
void end_read_record(READ_RECORD *info);
 
611
ha_rows filesort(Session *session, Table *form,struct st_sort_field *sortorder,
 
612
                 uint32_t s_length, SQL_SELECT *select,
 
613
                 ha_rows max_rows, bool sort_positions,
 
614
                 ha_rows *examined_rows);
 
615
void filesort_free_buffers(Table *table, bool full);
 
616
void change_double_for_sort(double nr,unsigned char *to);
 
617
double my_double_round(double value, int64_t dec, bool dec_unsigned,
 
618
                       bool truncate);
 
619
int get_quick_record(SQL_SELECT *select);
 
620
 
 
621
int calc_weekday(long daynr,bool sunday_first_day_of_week);
 
622
uint32_t calc_week(DRIZZLE_TIME *l_time, uint32_t week_behaviour, uint32_t *year);
 
623
void find_date(char *pos,uint32_t *vek,uint32_t flag);
 
624
TYPELIB *convert_strings_to_array_type(char * *typelibs, char * *end);
 
625
TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings);
 
626
ulong get_form_pos(File file, unsigned char *head, TYPELIB *save_names);
 
627
ulong make_new_entry(File file,unsigned char *fileinfo,TYPELIB *formnames,
 
628
                     const char *newname);
 
629
ulong next_io_size(ulong pos);
 
630
void append_unescaped(String *res, const char *pos, uint32_t length);
 
631
int create_frm(Session *session, const char *name, const char *db, const char *table,
 
632
               uint32_t reclength, unsigned char *fileinfo,
 
633
               HA_CREATE_INFO *create_info, uint32_t keys, KEY *key_info);
 
634
int rename_file_ext(const char * from,const char * to,const char * ext);
 
635
bool check_db_name(LEX_STRING *db);
 
636
bool check_column_name(const char *name);
 
637
bool check_table_name(const char *name, uint32_t length);
 
638
char *get_field(MEM_ROOT *mem, Field *field);
 
639
bool get_field(MEM_ROOT *mem, Field *field, class String *res);
 
640
char *fn_rext(char *name);
 
641
 
 
642
/* Conversion functions */
 
643
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
 
644
                          const char *table, const char *ext, uint32_t flags);
 
645
 
 
646
#define MYSQL50_TABLE_NAME_PREFIX         "#mysql50#"
 
647
#define MYSQL50_TABLE_NAME_PREFIX_LENGTH  sizeof(MYSQL50_TABLE_NAME_PREFIX)
 
648
 
 
649
/* Flags for conversion functions. */
 
650
#define FN_FROM_IS_TMP  (1 << 0)
 
651
#define FN_TO_IS_TMP    (1 << 1)
 
652
#define FN_IS_TMP       (FN_FROM_IS_TMP | FN_TO_IS_TMP)
 
653
#define NO_FRM_RENAME   (1 << 2)
 
654
 
 
655
/* item_func.cc */
 
656
Item *get_system_var(Session *session, enum_var_type var_type, LEX_STRING name,
 
657
                     LEX_STRING component);
 
658
int get_var_with_binlog(Session *session, enum_sql_command sql_command,
 
659
                        LEX_STRING &name, user_var_entry **out_entry);
 
660
/* log.cc */
 
661
bool flush_error_log(void);
 
662
 
 
663
/* sql_list.cc */
 
664
void free_list(I_List <i_string_pair> *list);
 
665
void free_list(I_List <i_string> *list);
 
666
 
 
667
/* Some inline functions for more speed */
 
668
 
 
669
inline bool add_item_to_list(Session *session, Item *item)
 
670
{
 
671
  return session->lex->current_select->add_item_to_list(session, item);
 
672
}
 
673
 
 
674
inline bool add_value_to_list(Session *session, Item *value)
 
675
{
 
676
  return session->lex->value_list.push_back(value);
 
677
}
 
678
 
 
679
inline bool add_order_to_list(Session *session, Item *item, bool asc)
 
680
{
 
681
  return session->lex->current_select->add_order_to_list(session, item, asc);
 
682
}
 
683
 
 
684
inline bool add_group_to_list(Session *session, Item *item, bool asc)
 
685
{
 
686
  return session->lex->current_select->add_group_to_list(session, item, asc);
 
687
}
 
688
 
 
689
inline void mark_as_null_row(Table *table)
 
690
{
 
691
  table->null_row=1;
 
692
  table->status|=STATUS_NULL_ROW;
 
693
  memset(table->null_flags, 255, table->s->null_bytes);
 
694
}
 
695
 
 
696
inline ulong sql_rnd()
 
697
{
 
698
  ulong tmp= (ulong) (rand() * 0xffffffff); /* make all bits random */
 
699
 
 
700
  return tmp;
 
701
}
 
702
 
 
703
Comp_creator *comp_eq_creator(bool invert);
 
704
Comp_creator *comp_ge_creator(bool invert);
 
705
Comp_creator *comp_gt_creator(bool invert);
 
706
Comp_creator *comp_le_creator(bool invert);
 
707
Comp_creator *comp_lt_creator(bool invert);
 
708
Comp_creator *comp_ne_creator(bool invert);
 
709
 
 
710
Item * all_any_subquery_creator(Item *left_expr,
 
711
                                chooser_compare_func_creator cmp,
 
712
                                bool all,
 
713
                                SELECT_LEX *select_lex);
 
714
 
 
715
/**
 
716
  clean/setup table fields and map.
 
717
 
 
718
  @param table        Table structure pointer (which should be setup)
 
719
  @param table_list   TableList structure pointer (owner of Table)
 
720
  @param tablenr     table number
 
721
*/
 
722
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
 
723
{
 
724
  table->used_fields= 0;
 
725
  table->const_table= 0;
 
726
  table->null_row= 0;
 
727
  table->status= STATUS_NO_RECORD;
 
728
  table->maybe_null= table_list->outer_join;
 
729
  TableList *embedding= table_list->embedding;
 
730
  while (!table->maybe_null && embedding)
 
731
  {
 
732
    table->maybe_null= embedding->outer_join;
 
733
    embedding= embedding->embedding;
 
734
  }
 
735
  table->tablenr= tablenr;
 
736
  table->map= (table_map) 1 << tablenr;
 
737
  table->force_index= table_list->force_index;
 
738
  table->covering_keys= table->s->keys_for_keyread;
 
739
  table->merge_keys.clear_all();
 
740
}
 
741
 
 
742
#include <drizzled/item/create.h>         /* Factory API for creating Item_* instances */
 
743
 
 
744
/**
 
745
  convert a hex digit into number.
 
746
*/
 
747
 
 
748
inline int hexchar_to_int(char c)
 
749
{
 
750
  if (c <= '9' && c >= '0')
 
751
    return c-'0';
 
752
  c|=32;
 
753
  if (c <= 'f' && c >= 'a')
 
754
    return c-'a'+10;
 
755
  return -1;
 
756
}
 
757
 
 
758
/*
 
759
  Some functions that are different in the embedded library and the normal
 
760
  server
 
761
*/
 
762
 
 
763
extern "C" void unireg_abort(int exit_code) __attribute__((noreturn));
 
764
bool check_stack_overrun(Session *session, long margin, unsigned char *dummy);
 
765
 
 
766
#endif /* DRIZZLE_SERVER_SERVER_INCLUDES_H */