~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/server_includes.h

  • Committer: Monty Taylor
  • Date: 2008-11-18 22:12:56 UTC
  • mto: (589.1.3 devel)
  • mto: This revision was merged to the branch mainline in revision 589.
  • Revision ID: monty@inaugust.com-20081118221256-ap2kmj073pdw7uap
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include <drizzled/connect.h>
44
44
/* Routines for dropping, repairing, checking schema tables */
45
45
#include <drizzled/sql_table.h>
 
46
#include <drizzled/log.h>
 
47
 
 
48
#include <string>
 
49
 
 
50
typedef class st_select_lex SELECT_LEX;
 
51
typedef struct st_mysql_lock DRIZZLE_LOCK;
 
52
typedef struct st_ha_create_information HA_CREATE_INFO;
46
53
 
47
54
/* information schema */
48
55
static const std::string INFORMATION_SCHEMA_NAME("information_schema");
51
58
#define is_schema_db(X) \
52
59
  !my_strcasecmp(system_charset_info, INFORMATION_SCHEMA_NAME.str, (X))
53
60
 
54
 
/* sql_base.cc */
55
 
#define TMP_TABLE_KEY_EXTRA 8
56
 
void set_item_name(Item *item,char *pos,uint32_t length);
57
 
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum enum_field_types type,
58
 
                       char *length, char *decimal,
59
 
                       uint32_t type_modifier,
60
 
                       enum column_format_type column_format,
61
 
                       Item *default_value, Item *on_update_value,
62
 
                       LEX_STRING *comment,
63
 
                       char *change, List<String> *interval_list,
64
 
                       const CHARSET_INFO * const cs,
65
 
                       virtual_column_info *vcol_info);
66
 
Create_field * new_create_field(Session *session, char *field_name, enum_field_types type,
67
 
                                char *length, char *decimals,
68
 
                                uint32_t type_modifier, 
69
 
                                Item *default_value, Item *on_update_value,
70
 
                                LEX_STRING *comment, char *change, 
71
 
                                List<String> *interval_list, CHARSET_INFO *cs,
72
 
                                virtual_column_info *vcol_info);
73
 
void store_position_for_column(const char *name);
74
 
bool add_to_list(Session *session, SQL_LIST &list,Item *group,bool asc);
75
 
bool push_new_name_resolution_context(Session *session,
76
 
                                      TableList *left_op,
77
 
                                      TableList *right_op);
78
 
void add_join_on(TableList *b,Item *expr);
79
 
void add_join_natural(TableList *a,TableList *b,List<String> *using_fields,
80
 
                      SELECT_LEX *lex);
81
 
bool add_proc_to_list(Session *session, Item *item);
82
 
void unlink_open_table(Session *session, Table *find, bool unlock);
83
 
void drop_open_table(Session *session, Table *table, const char *db_name,
84
 
                     const char *table_name);
85
 
void update_non_unique_table_error(TableList *update,
86
 
                                   const char *operation,
87
 
                                   TableList *duplicate);
88
 
 
89
 
SQL_SELECT *make_select(Table *head, table_map const_tables,
90
 
                        table_map read_tables, COND *conds,
91
 
                        bool allow_null_cond,  int *error);
92
 
extern Item **not_found_item;
93
 
 
94
 
/*
95
 
  A set of constants used for checking non aggregated fields and sum
96
 
  functions mixture in the ONLY_FULL_GROUP_BY_MODE.
97
 
*/
98
 
#define NON_AGG_FIELD_USED  1
99
 
#define SUM_FUNC_USED       2
100
 
 
101
 
/*
102
 
  This enumeration type is used only by the function find_item_in_list
103
 
  to return the info on how an item has been resolved against a list
104
 
  of possibly aliased items.
105
 
  The item can be resolved: 
106
 
   - against an alias name of the list's element (RESOLVED_AGAINST_ALIAS)
107
 
   - against non-aliased field name of the list  (RESOLVED_WITH_NO_ALIAS)
108
 
   - against an aliased field name of the list   (RESOLVED_BEHIND_ALIAS)
109
 
   - ignoring the alias name in cases when SQL requires to ignore aliases
110
 
     (e.g. when the resolved field reference contains a table name or
111
 
     when the resolved item is an expression)   (RESOLVED_IGNORING_ALIAS)    
112
 
*/
113
 
enum enum_resolution_type {
114
 
  NOT_RESOLVED=0,
115
 
  RESOLVED_IGNORING_ALIAS,
116
 
  RESOLVED_BEHIND_ALIAS,
117
 
  RESOLVED_WITH_NO_ALIAS,
118
 
  RESOLVED_AGAINST_ALIAS
119
 
};
120
 
Item ** find_item_in_list(Item *item, List<Item> &items, uint32_t *counter,
121
 
                          find_item_error_report_type report_error,
122
 
                          enum_resolution_type *resolution);
123
 
bool get_key_map_from_key_list(key_map *map, Table *table,
124
 
                               List<String> *index_list);
125
 
bool insert_fields(Session *session, Name_resolution_context *context,
126
 
                   const char *db_name, const char *table_name,
127
 
                   List_iterator<Item> *it, bool any_privileges);
128
 
bool setup_tables(Session *session, Name_resolution_context *context,
129
 
                  List<TableList> *from_clause, TableList *tables,
130
 
                  TableList **leaves, bool select_insert);
131
 
bool setup_tables_and_check_access(Session *session, 
132
 
                                   Name_resolution_context *context,
133
 
                                   List<TableList> *from_clause, 
134
 
                                   TableList *tables, 
135
 
                                   TableList **leaves, 
136
 
                                   bool select_insert);
137
 
int setup_wild(Session *session, TableList *tables, List<Item> &fields,
138
 
               List<Item> *sum_func_list, uint32_t wild_num);
139
 
bool setup_fields(Session *session, Item** ref_pointer_array,
140
 
                  List<Item> &item, enum_mark_columns mark_used_columns,
141
 
                  List<Item> *sum_func_list, bool allow_sum_func);
142
 
inline bool setup_fields_with_no_wrap(Session *session, Item **ref_pointer_array,
143
 
                                      List<Item> &item,
144
 
                                      enum_mark_columns mark_used_columns,
145
 
                                      List<Item> *sum_func_list,
146
 
                                      bool allow_sum_func)
147
 
{
148
 
  bool res;
149
 
  res= setup_fields(session, ref_pointer_array, item, mark_used_columns, sum_func_list,
150
 
                    allow_sum_func);
151
 
  return res;
152
 
}
153
 
int setup_conds(Session *session, TableList *tables, TableList *leaves,
154
 
                COND **conds);
155
 
int setup_ftfuncs(SELECT_LEX* select);
156
 
int init_ftfuncs(Session *session, SELECT_LEX* select, bool no_order);
157
 
void wait_for_condition(Session *session, pthread_mutex_t *mutex,
158
 
                        pthread_cond_t *cond);
159
 
int open_tables(Session *session, TableList **tables, uint32_t *counter, uint32_t flags);
160
 
/* open_and_lock_tables with optional derived handling */
161
 
int open_and_lock_tables_derived(Session *session, TableList *tables, bool derived);
162
 
/* simple open_and_lock_tables without derived handling */
163
 
inline int simple_open_n_lock_tables(Session *session, TableList *tables)
164
 
{
165
 
  return open_and_lock_tables_derived(session, tables, false);
166
 
}
167
 
/* open_and_lock_tables with derived handling */
168
 
inline int open_and_lock_tables(Session *session, TableList *tables)
169
 
{
170
 
  return open_and_lock_tables_derived(session, tables, true);
171
 
}
172
 
/* simple open_and_lock_tables without derived handling for single table */
173
 
Table *open_n_lock_single_table(Session *session, TableList *table_l,
174
 
                                thr_lock_type lock_type);
175
 
bool open_normal_and_derived_tables(Session *session, TableList *tables, uint32_t flags);
176
 
int lock_tables(Session *session, TableList *tables, uint32_t counter, bool *need_reopen);
177
 
int decide_logging_format(Session *session);
178
 
Table *open_temporary_table(Session *session, const char *path, const char *db,
179
 
                            const char *table_name, bool link_in_list,
180
 
                            open_table_mode open_mode);
181
 
bool rm_temporary_table(handlerton *base, char *path, bool frm_only);
182
 
void free_io_cache(Table *entry);
183
 
void intern_close_table(Table *entry);
184
 
bool close_thread_table(Session *session, Table **table_ptr);
185
 
void close_temporary_tables(Session *session);
186
 
void close_tables_for_reopen(Session *session, TableList **tables);
187
 
TableList *find_table_in_list(TableList *table,
188
 
                               TableList *TableList::*link,
189
 
                               const char *db_name,
190
 
                               const char *table_name);
191
 
TableList *unique_table(Session *session, TableList *table, TableList *table_list,
192
 
                         bool check_alias);
193
 
Table *find_temporary_table(Session *session, const char *db, const char *table_name);
194
 
Table *find_temporary_table(Session *session, TableList *table_list);
195
 
int drop_temporary_table(Session *session, TableList *table_list);
196
 
void close_temporary_table(Session *session, Table *table, bool free_share,
197
 
                           bool delete_table);
198
 
void close_temporary(Table *table, bool free_share, bool delete_table);
199
 
bool rename_temporary_table(Session* session, Table *table, const char *new_db,
200
 
                            const char *table_name);
201
 
void remove_db_from_cache(const char *db);
202
 
void flush_tables();
203
 
bool is_equal(const LEX_STRING *a, const LEX_STRING *b);
204
 
char *make_default_log_name(char *buff,const char* log_ext);
205
 
 
206
 
/* bits for last argument to remove_table_from_cache() */
207
 
#define RTFC_NO_FLAG                0x0000
208
 
#define RTFC_OWNED_BY_Session_FLAG      0x0001
209
 
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
210
 
#define RTFC_CHECK_KILLED_FLAG      0x0004
211
 
bool remove_table_from_cache(Session *session, const char *db, const char *table,
212
 
                             uint32_t flags);
213
 
 
214
 
#define NORMAL_PART_NAME 0
215
 
#define TEMP_PART_NAME 1
216
 
#define RENAMED_PART_NAME 2
217
 
 
218
 
void mem_alloc_error(size_t size);
219
 
 
220
 
#define WFRM_WRITE_SHADOW 1
221
 
#define WFRM_INSTALL_SHADOW 2
222
 
#define WFRM_PACK_FRM 4
223
 
#define WFRM_KEEP_SHARE 8
224
 
 
225
 
bool close_cached_tables(Session *session, TableList *tables, bool have_lock,
226
 
                         bool wait_for_refresh, bool wait_for_placeholders);
227
 
bool close_cached_connection_tables(Session *session, bool wait_for_refresh,
228
 
                                    LEX_STRING *connect_string,
229
 
                                    bool have_lock= false);
230
 
void copy_field_from_tmp_record(Field *field,int offset);
231
 
bool fill_record(Session * session, List<Item> &fields, List<Item> &values, bool ignore_errors);
232
 
bool fill_record(Session *session, Field **field, List<Item> &values, bool ignore_errors);
233
 
OPEN_TableList *list_open_tables(Session *session, const char *db, const char *wild);
234
 
 
235
 
inline TableList *find_table_in_global_list(TableList *table,
236
 
                                             const char *db_name,
237
 
                                             const char *table_name)
238
 
{
239
 
  return find_table_in_list(table, &TableList::next_global,
240
 
                            db_name, table_name);
241
 
}
242
 
 
243
 
inline TableList *find_table_in_local_list(TableList *table,
244
 
                                            const char *db_name,
245
 
                                            const char *table_name)
246
 
{
247
 
  return find_table_in_list(table, &TableList::next_local,
248
 
                            db_name, table_name);
249
 
}
250
 
 
251
61
 
252
62
/* sql_calc.cc */
253
63
bool eval_const_cond(COND *cond);
254
64
 
255
 
/* sql_load.cc */
256
 
int mysql_load(Session *session, sql_exchange *ex, TableList *table_list,
257
 
                List<Item> &fields_vars, List<Item> &set_fields,
258
 
                List<Item> &set_values_list,
259
 
                enum enum_duplicates handle_duplicates, bool ignore,
260
 
                bool local_file);
261
 
int write_record(Session *session, Table *table, COPY_INFO *info);
262
 
 
263
65
 
264
66
/* sql_test.cc */
265
67
void print_where(COND *cond,const char *info, enum_query_type query_type);
266
68
void print_cached_tables(void);
267
 
void TEST_filesort(SORT_FIELD *sortorder,uint32_t s_length);
268
69
void print_plan(JOIN* join,uint32_t idx, double record_count, double read_time,
269
70
                double current_read_time, const char *info);
270
71
void print_keyuse_array(DYNAMIC_ARRAY *keyuse_array);
317
118
 
318
119
bool is_keyword(const char *name, uint32_t len);
319
120
 
320
 
#define MY_DB_OPT_FILE "db.opt"
321
 
bool my_database_names_init(void);
322
 
void my_database_names_free(void);
323
 
bool check_db_dir_existence(const char *db_name);
324
 
bool load_db_opt(Session *session, const char *path, HA_CREATE_INFO *create);
325
 
bool load_db_opt_by_name(Session *session, const char *db_name,
326
 
                         HA_CREATE_INFO *db_create_info);
327
 
const CHARSET_INFO *get_default_db_collation(Session *session, const char *db_name);
328
 
bool my_dbopt_init(void);
329
 
void my_dbopt_cleanup(void);
330
 
extern int creating_database; // How many database locks are made
331
 
extern int creating_table;    // How many mysql_create_table() are running
332
 
 
333
121
/*
334
122
  External variables
335
123
*/
336
124
 
337
125
extern time_t server_start_time, flush_status_time;
338
126
extern char *opt_drizzle_tmpdir;
339
 
            
 
127
 
340
128
#define drizzle_tmpdir (my_tmpdir(&drizzle_tmpdir_list))
341
129
extern MY_TMPDIR drizzle_tmpdir_list;
342
130
extern const LEX_STRING command_name[];
427
215
extern pthread_cond_t COND_global_read_lock;
428
216
extern pthread_attr_t connection_attrib;
429
217
extern I_List<Session> threads;
430
 
extern I_List<NAMED_LIST> key_caches;
431
218
extern MY_BITMAP temp_pool;
432
219
extern String my_empty_string;
433
220
extern const String my_null_string;
439
226
extern const char *opt_date_time_formats[];
440
227
extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
441
228
 
442
 
extern HASH open_cache, lock_db_cache;
443
229
extern Table *unused_tables;
444
230
extern const char* any_db;
445
231
extern struct my_option my_long_options[];
518
304
void unireg_end(void) __attribute__((noreturn));
519
305
bool mysql_create_frm(Session *session, const char *file_name,
520
306
                      const char *db, const char *table,
521
 
                      HA_CREATE_INFO *create_info,
522
 
                      List<Create_field> &create_field,
523
 
                      uint32_t key_count,KEY *key_info,handler *db_type);
 
307
                      HA_CREATE_INFO *create_info,
 
308
                      List<Create_field> &create_field,
 
309
                      uint32_t key_count,KEY *key_info,handler *db_type);
524
310
int rea_create_table(Session *session, const char *path,
525
311
                     const char *db, const char *table_name,
526
312
                     HA_CREATE_INFO *create_info,
527
 
                     List<Create_field> &create_field,
 
313
                     List<Create_field> &create_field,
528
314
                     uint32_t key_count,KEY *key_info,
529
315
                     handler *file);
530
316
int format_number(uint32_t inputflag,uint32_t max_length,char * pos,uint32_t length,
651
437
/* log.cc */
652
438
bool flush_error_log(void);
653
439
 
654
 
/* sql_list.cc */
655
 
void free_list(I_List <i_string_pair> *list);
656
 
void free_list(I_List <i_string> *list);
657
 
 
658
 
/* Some inline functions for more speed */
659
 
 
660
 
inline bool add_item_to_list(Session *session, Item *item)
661
 
{
662
 
  return session->lex->current_select->add_item_to_list(session, item);
663
 
}
664
 
 
665
 
inline bool add_value_to_list(Session *session, Item *value)
666
 
{
667
 
  return session->lex->value_list.push_back(value);
668
 
}
669
 
 
670
 
inline bool add_order_to_list(Session *session, Item *item, bool asc)
671
 
{
672
 
  return session->lex->current_select->add_order_to_list(session, item, asc);
673
 
}
674
 
 
675
 
inline bool add_group_to_list(Session *session, Item *item, bool asc)
676
 
{
677
 
  return session->lex->current_select->add_group_to_list(session, item, asc);
678
 
}
679
 
 
680
 
inline void mark_as_null_row(Table *table)
681
 
{
682
 
  table->null_row=1;
683
 
  table->status|=STATUS_NULL_ROW;
684
 
  memset(table->null_flags, 255, table->s->null_bytes);
685
 
}
686
440
 
687
441
inline ulong sql_rnd()
688
442
{
691
445
  return tmp;
692
446
}
693
447
 
694
 
Comp_creator *comp_eq_creator(bool invert);
695
 
Comp_creator *comp_ge_creator(bool invert);
696
 
Comp_creator *comp_gt_creator(bool invert);
697
 
Comp_creator *comp_le_creator(bool invert);
698
 
Comp_creator *comp_lt_creator(bool invert);
699
 
Comp_creator *comp_ne_creator(bool invert);
700
 
 
701
 
Item * all_any_subquery_creator(Item *left_expr,
702
 
                                chooser_compare_func_creator cmp,
703
 
                                bool all,
704
 
                                SELECT_LEX *select_lex);
705
 
 
706
 
/**
707
 
  clean/setup table fields and map.
708
 
 
709
 
  @param table        Table structure pointer (which should be setup)
710
 
  @param table_list   TableList structure pointer (owner of Table)
711
 
  @param tablenr     table number
712
 
*/
713
 
inline void setup_table_map(Table *table, TableList *table_list, uint32_t tablenr)
714
 
{
715
 
  table->used_fields= 0;
716
 
  table->const_table= 0;
717
 
  table->null_row= 0;
718
 
  table->status= STATUS_NO_RECORD;
719
 
  table->maybe_null= table_list->outer_join;
720
 
  TableList *embedding= table_list->embedding;
721
 
  while (!table->maybe_null && embedding)
722
 
  {
723
 
    table->maybe_null= embedding->outer_join;
724
 
    embedding= embedding->embedding;
725
 
  }
726
 
  table->tablenr= tablenr;
727
 
  table->map= (table_map) 1 << tablenr;
728
 
  table->force_index= table_list->force_index;
729
 
  table->covering_keys= table->s->keys_for_keyread;
730
 
  table->merge_keys.clear_all();
731
 
}
732
 
 
733
 
#include <drizzled/item/create.h>         /* Factory API for creating Item_* instances */
 
448
 
734
449
 
735
450
/**
736
451
  convert a hex digit into number.