~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
/**
21
 
  @file Handling of MySQL SQL variables
 
21
  @file
 
22
 
 
23
  @brief
 
24
  Handling of MySQL SQL variables
22
25
 
23
26
  @details
24
27
  To add a new variable, one has to do the following:
29
32
  - If the variable is thread specific, add it to 'system_variables' struct.
30
33
    If not, add it to mysqld.cc and an declaration in 'mysql_priv.h'
31
34
  - If the variable should be changed from the command line, add a definition
32
 
    of it in the option structure list in mysqld.cc
 
35
    of it in the my_option structure list in mysqld.cc
33
36
  - Don't forget to initialize new fields in global_system_variables and
34
37
    max_system_variables!
35
38
 
36
39
  @todo
37
40
    Add full support for the variable character_set (for 4.1)
38
41
 
 
42
  @todo
 
43
    When updating myisam_delay_key_write, we should do a 'flush tables'
 
44
    of all MyISAM tables to ensure that they are reopen with the
 
45
    new attribute.
 
46
 
39
47
  @note
40
48
    Be careful with var->save_result: sys_var::check() only updates
41
49
    uint64_t_value; so other members of the union are garbage then; to use
43
51
    example).
44
52
*/
45
53
 
46
 
#include "config.h"
47
 
#include "drizzled/option.h"
 
54
#include <drizzled/server_includes.h>
 
55
#include <mysys/my_getopt.h>
 
56
#include <storage/myisam/myisam.h>
48
57
#include <drizzled/error.h>
49
58
#include <drizzled/gettext.h>
50
59
#include <drizzled/tztime.h>
56
65
#include <drizzled/item/uint.h>
57
66
#include <drizzled/item/null.h>
58
67
#include <drizzled/item/float.h>
59
 
#include <drizzled/plugin.h>
60
 
#include "drizzled/version.h"
61
 
#include "drizzled/strfunc.h"
62
 
#include "drizzled/internal/m_string.h"
63
 
#include "drizzled/pthread_globals.h"
64
 
#include "drizzled/charset.h"
65
 
#include "drizzled/transaction_services.h"
66
68
 
67
69
#include <map>
68
70
#include <algorithm>
69
71
 
70
72
using namespace std;
71
73
 
72
 
namespace drizzled
73
 
{
74
 
 
75
 
namespace internal
76
 
{
77
 
extern bool timed_mutexes;
78
 
}
79
 
 
80
 
extern plugin::StorageEngine *myisam_engine;
81
 
extern bool timed_mutexes;
82
 
 
83
 
extern struct option my_long_options[];
84
74
extern const CHARSET_INFO *character_set_filesystem;
 
75
extern I_List<NAMED_LIST> key_caches;
85
76
extern size_t my_thread_stack_size;
86
77
 
87
 
class sys_var_pluginvar;
88
78
static DYNAMIC_ARRAY fixed_show_vars;
89
 
typedef map<string, sys_var *> SystemVariableMap;
90
 
static SystemVariableMap system_variable_map;
 
79
static map<const string, sys_var *> system_variable_hash;
91
80
extern char *opt_drizzle_tmpdir;
92
81
 
93
 
extern TYPELIB tx_isolation_typelib;
94
 
 
95
82
const char *bool_type_names[]= { "OFF", "ON", NULL };
96
83
TYPELIB bool_typelib=
97
84
{
98
85
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
99
86
};
100
87
 
 
88
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
89
TYPELIB delay_key_write_typelib=
 
90
{
 
91
  array_elements(delay_key_write_type_names)-1, "",
 
92
  delay_key_write_type_names, NULL
 
93
};
 
94
 
101
95
static bool set_option_bit(Session *session, set_var *var);
102
96
static bool set_option_autocommit(Session *session, set_var *var);
103
97
static int  check_pseudo_thread_id(Session *session, set_var *var);
104
98
static int check_tx_isolation(Session *session, set_var *var);
105
 
static void fix_tx_isolation(Session *session, sql_var_t type);
 
99
static void fix_tx_isolation(Session *session, enum_var_type type);
106
100
static int check_completion_type(Session *session, set_var *var);
107
 
static void fix_completion_type(Session *session, sql_var_t type);
108
 
static void fix_max_join_size(Session *session, sql_var_t type);
109
 
static void fix_session_mem_root(Session *session, sql_var_t type);
110
 
static void fix_server_id(Session *session, sql_var_t type);
 
101
static void fix_completion_type(Session *session, enum_var_type type);
 
102
static void fix_net_read_timeout(Session *session, enum_var_type type);
 
103
static void fix_net_write_timeout(Session *session, enum_var_type type);
 
104
static void fix_net_retry_count(Session *session, enum_var_type type);
 
105
static void fix_max_join_size(Session *session, enum_var_type type);
 
106
static void fix_session_mem_root(Session *session, enum_var_type type);
 
107
static void fix_trans_mem_root(Session *session, enum_var_type type);
 
108
static void fix_server_id(Session *session, enum_var_type type);
 
109
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
111
110
static bool get_unsigned32(Session *session, set_var *var);
112
111
static bool get_unsigned64(Session *session, set_var *var);
113
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
 
                          const std::string &name, int64_t val);
 
113
                          const char *name, int64_t val);
 
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
115
static unsigned char *get_error_count(Session *session);
116
116
static unsigned char *get_warning_count(Session *session);
117
117
static unsigned char *get_tmpdir(Session *session);
125
125
  The variables are linked into the list. A variable is added to
126
126
  it in the constructor (see sys_var class for details).
127
127
*/
 
128
 
128
129
static sys_var_chain vars = { NULL, NULL };
129
130
 
130
131
static sys_var_session_uint64_t
131
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
132
 
                             &system_variables::auto_increment_increment);
 
133
                             &SV::auto_increment_increment, NULL, NULL,
 
134
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
133
135
static sys_var_session_uint64_t
134
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
135
 
                          &system_variables::auto_increment_offset);
 
137
                          &SV::auto_increment_offset, NULL, NULL,
 
138
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
136
139
 
137
140
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
138
141
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
139
 
                                                          &system_variables::bulk_insert_buff_size);
 
142
                                                          &SV::bulk_insert_buff_size);
140
143
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
141
 
                                                    &system_variables::completion_type,
 
144
                                                    &SV::completion_type,
142
145
                                                    check_completion_type,
143
146
                                                    fix_completion_type);
144
147
static sys_var_collation_sv
145
 
sys_collation_server(&vars, "collation_server", &system_variables::collation_server, &default_charset_info);
 
148
sys_collation_database(&vars, "collation_database", &SV::collation_database,
 
149
                       &default_charset_info,
 
150
                       sys_var::SESSION_VARIABLE_IN_BINLOG);
 
151
static sys_var_collation_sv
 
152
sys_collation_server(&vars, "collation_server", &SV::collation_server,
 
153
                     &default_charset_info,
 
154
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
 
155
static sys_var_uint32_t_ptr     sys_connect_timeout(&vars, "connect_timeout",
 
156
                                                &connect_timeout);
146
157
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
 
158
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
 
159
                                            &delay_key_write_options,
 
160
                                            &delay_key_write_typelib,
 
161
                                            fix_delay_key_write);
147
162
 
 
163
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
148
164
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
149
 
                                                     &system_variables::join_buff_size);
 
165
                                                     &SV::join_buff_size);
 
166
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
 
167
static sys_var_key_cache_uint32_t  sys_key_cache_block_size(&vars, "key_cache_block_size",
 
168
                                                        offsetof(KEY_CACHE,
 
169
                                                                 param_block_size));
 
170
static sys_var_key_cache_uint32_t       sys_key_cache_division_limit(&vars, "key_cache_division_limit",
 
171
                                                           offsetof(KEY_CACHE,
 
172
                                                                    param_division_limit));
 
173
static sys_var_key_cache_uint32_t  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
 
174
                                                           offsetof(KEY_CACHE,
 
175
                                                                    param_age_threshold));
150
176
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
151
 
                                                       &system_variables::max_allowed_packet);
 
177
                                                       &SV::max_allowed_packet);
152
178
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
153
179
                                               &max_connect_errors);
154
180
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
155
 
                                                  &system_variables::max_error_count);
 
181
                                                  &SV::max_error_count);
156
182
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
157
 
                                                        &system_variables::max_heap_table_size);
 
183
                                                        &SV::max_heap_table_size);
158
184
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
159
 
                                              &system_variables::pseudo_thread_id,
160
 
                                              0, check_pseudo_thread_id);
 
185
                                              &SV::pseudo_thread_id,
 
186
                                              0, check_pseudo_thread_id,
 
187
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
161
188
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
162
 
                                                  &system_variables::max_join_size,
 
189
                                                  &SV::max_join_size,
163
190
                                                  fix_max_join_size);
164
191
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
165
 
                                                      &system_variables::max_seeks_for_key);
 
192
                                                      &SV::max_seeks_for_key);
166
193
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
167
 
                                                               &system_variables::max_length_for_sort_data);
 
194
                                                               &SV::max_length_for_sort_data);
168
195
static sys_var_session_size_t   sys_max_sort_length(&vars, "max_sort_length",
169
 
                                                    &system_variables::max_sort_length);
 
196
                                                    &SV::max_sort_length);
 
197
static sys_var_session_uint64_t sys_max_tmp_tables(&vars, "max_tmp_tables",
 
198
                                                   &SV::max_tmp_tables);
170
199
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
171
200
                                                 &max_write_lock_count);
172
201
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
173
 
                                                           &system_variables::min_examined_row_limit);
 
202
                                                           &SV::min_examined_row_limit);
174
203
 
 
204
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
205
                                                            &SV::myisam_stats_method,
 
206
                                                            &myisam_stats_method_typelib,
 
207
                                                            NULL);
 
208
static sys_var_session_uint32_t sys_net_buffer_length(&vars, "net_buffer_length",
 
209
                                                      &SV::net_buffer_length);
 
210
static sys_var_session_uint32_t sys_net_read_timeout(&vars, "net_read_timeout",
 
211
                                                     &SV::net_read_timeout,
 
212
                                                     0, fix_net_read_timeout);
 
213
static sys_var_session_uint32_t sys_net_write_timeout(&vars, "net_write_timeout",
 
214
                                                      &SV::net_write_timeout,
 
215
                                                      0, fix_net_write_timeout);
 
216
static sys_var_session_uint32_t sys_net_retry_count(&vars, "net_retry_count",
 
217
                                                    &SV::net_retry_count,
 
218
                                                    0, fix_net_retry_count);
175
219
/* these two cannot be static */
 
220
sys_var_session_bool sys_old_alter_table(&vars, "old_alter_table",
 
221
                                         &SV::old_alter_table);
176
222
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
177
 
                                                      &system_variables::optimizer_prune_level);
 
223
                                                      &SV::optimizer_prune_level);
178
224
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
179
 
                                                           &system_variables::optimizer_search_depth);
 
225
                                                           &SV::optimizer_search_depth);
 
226
 
 
227
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
228
TYPELIB optimizer_use_mrr_typelib= {
 
229
  array_elements(optimizer_use_mrr_names) - 1, "",
 
230
  optimizer_use_mrr_names, NULL
 
231
};
 
232
 
 
233
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
234
                                                  &SV::optimizer_use_mrr,
 
235
                                                  &optimizer_use_mrr_typelib,
 
236
                                                  NULL);
180
237
 
181
238
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
182
 
                                                      &system_variables::preload_buff_size);
 
239
                                                      &SV::preload_buff_size);
183
240
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
184
 
                                                   &system_variables::read_buff_size);
 
241
                                                   &SV::read_buff_size);
185
242
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
186
 
                                                       &system_variables::read_rnd_buff_size);
 
243
                                                       &SV::read_rnd_buff_size);
187
244
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
188
 
                                                      &system_variables::div_precincrement);
 
245
                                                      &SV::div_precincrement);
189
246
 
190
247
static sys_var_session_size_t   sys_range_alloc_block_size(&vars, "range_alloc_block_size",
191
 
                                                           &system_variables::range_alloc_block_size);
 
248
                                                           &SV::range_alloc_block_size);
192
249
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
193
 
                                                           &system_variables::query_alloc_block_size,
 
250
                                                           &SV::query_alloc_block_size,
194
251
                                                           false, fix_session_mem_root);
195
252
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
196
 
                                                        &system_variables::query_prealloc_size,
 
253
                                                        &SV::query_prealloc_size,
197
254
                                                        false, fix_session_mem_root);
198
255
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
256
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
257
                                                           &SV::trans_alloc_block_size,
 
258
                                                           false, fix_trans_mem_root);
 
259
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
260
                                                        &SV::trans_prealloc_size,
 
261
                                                        false, fix_trans_mem_root);
199
262
 
200
263
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
201
264
                                             &opt_secure_file_priv);
203
266
                                           fix_server_id);
204
267
 
205
268
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
206
 
                                                &system_variables::sortbuff_size);
 
269
                                                &SV::sortbuff_size);
 
270
/*
 
271
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
 
272
  even though it is written to the binlog, the slave ignores the
 
273
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
 
274
  master's (see log_event.cc: Query_log_event::do_apply_event()).
 
275
*/
 
276
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
277
                                                               &SV::optimizer_switch);
207
278
 
208
279
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
209
 
                                       &system_variables::storage_engine);
 
280
                                       &SV::storage_engine);
210
281
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
211
282
                                             system_time_zone);
212
 
static sys_var_size_t_ptr       sys_table_def_size(&vars, "table_definition_cache",
213
 
                                             &table_def_size);
 
283
static sys_var_uint64_t_ptr     sys_table_def_size(&vars, "table_definition_cache",
 
284
                                           &table_def_size);
214
285
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
215
286
                                             &table_cache_size);
216
287
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
217
288
                                                    &table_lock_wait_timeout);
218
289
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
219
 
                                             &system_variables::tx_isolation,
 
290
                                             &SV::tx_isolation,
220
291
                                             &tx_isolation_typelib,
221
292
                                             fix_tx_isolation,
222
293
                                             check_tx_isolation);
223
294
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
224
 
                                           &system_variables::tmp_table_size);
225
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &internal::timed_mutexes);
226
 
static sys_var_const_str  sys_version(&vars, "version", version().c_str());
227
 
 
 
295
                                           &SV::tmp_table_size);
 
296
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
 
297
static sys_var_const_str        sys_version(&vars, "version", server_version);
228
298
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
229
299
                                            COMPILATION_COMMENT);
230
300
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
231
 
                                                      HOST_CPU);
 
301
                                                    MACHINE_TYPE);
232
302
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
233
 
                                                 HOST_OS);
234
 
static sys_var_const_str        sys_version_compile_vendor(&vars, "version_compile_vendor",
235
 
                                                 HOST_VENDOR);
 
303
                                               SYSTEM_TYPE);
 
304
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
 
305
                                                     &SV::net_wait_timeout);
 
306
 
 
307
/* Condition pushdown to storage engine */
 
308
static sys_var_session_bool
 
309
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
 
310
                              &SV::engine_condition_pushdown);
236
311
 
237
312
/* Variables that are bits in Session */
238
313
 
249
324
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
250
325
                                         set_option_bit,
251
326
                                         OPTION_SQL_NOTES);
 
327
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
 
328
                                         set_option_bit,
 
329
                                         OPTION_SAFE_UPDATES);
252
330
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
253
331
                                           set_option_bit,
254
332
                                           OPTION_BUFFER_RESULT);
255
333
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
256
334
                                               set_option_bit,
257
 
                                               OPTION_NO_FOREIGN_KEY_CHECKS, 1);
 
335
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
 
336
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
258
337
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
259
338
                                          set_option_bit,
260
 
                                          OPTION_RELAXED_UNIQUE_CHECKS, 1);
 
339
                                          OPTION_RELAXED_UNIQUE_CHECKS,
 
340
                                          1,
 
341
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
261
342
/* Local state variables */
262
343
 
263
344
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
264
 
                                                 &system_variables::select_limit);
265
 
static sys_var_timestamp sys_timestamp(&vars, "timestamp");
 
345
                                                 &SV::select_limit);
 
346
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
 
347
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
266
348
static sys_var_last_insert_id
267
 
sys_last_insert_id(&vars, "last_insert_id");
 
349
sys_last_insert_id(&vars, "last_insert_id",
 
350
                   sys_var::SESSION_VARIABLE_IN_BINLOG);
268
351
/*
269
352
  identity is an alias for last_insert_id(), so that we are compatible
270
353
  with Sybase
271
354
*/
272
 
static sys_var_last_insert_id sys_identity(&vars, "identity");
 
355
static sys_var_last_insert_id
 
356
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
273
357
 
274
 
static sys_var_session_lc_time_names sys_lc_time_names(&vars, "lc_time_names");
 
358
static sys_var_session_lc_time_names
 
359
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
275
360
 
276
361
/*
 
362
  insert_id should *not* be marked as written to the binlog (i.e., it
 
363
  should *not* have binlog_status==SESSION_VARIABLE_IN_BINLOG),
 
364
  because we want any statement that refers to insert_id explicitly to
 
365
  be unsafe.  (By "explicitly", we mean using @@session.insert_id,
 
366
  whereas insert_id is used "implicitly" when NULL value is inserted
 
367
  into an auto_increment column).
 
368
 
277
369
  We want statements referring explicitly to @@session.insert_id to be
278
370
  unsafe, because insert_id is modified internally by the slave sql
279
371
  thread when NULL values are inserted in an AUTO_INCREMENT column.
295
387
                                          get_warning_count);
296
388
 
297
389
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
298
 
                                                  &system_variables::group_concat_max_len);
 
390
                                                  &SV::group_concat_max_len);
299
391
 
300
 
sys_var_session_time_zone sys_time_zone(&vars, "time_zone");
 
392
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
 
393
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
301
394
 
302
395
/* Global read-only variable containing hostname */
303
396
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
304
397
 
 
398
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create",
 
399
                                           &SV::keep_files_on_create);
 
400
/* Read only variables */
 
401
 
 
402
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
305
403
/*
306
404
  Additional variables (not derived from sys_var class, not accessible as
307
405
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
309
407
  TODO: remove this list completely
310
408
*/
311
409
 
312
 
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(drizzle_show_var))
313
 
static drizzle_show_var fixed_vars[]= {
314
 
  {"back_log",                (char*) &back_log,                SHOW_INT},
315
 
  {"language",                language,                         SHOW_CHAR},
316
 
  {"pid_file",                (char*) pidfile_name,             SHOW_CHAR},
317
 
  {"plugin_dir",              (char*) opt_plugin_dir,           SHOW_CHAR},
318
 
  {"thread_stack",            (char*) &my_thread_stack_size,    SHOW_INT},
 
410
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
 
411
static SHOW_VAR fixed_vars[]= {
 
412
  {"back_log",                (char*) &back_log,                    SHOW_INT},
 
413
  {"language",                language,                             SHOW_CHAR},
 
414
#ifdef HAVE_MLOCKALL
 
415
  {"locked_in_memory",        (char*) &locked_in_memory,            SHOW_MY_BOOL},
 
416
#endif
 
417
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
 
418
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
 
419
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
 
420
  {"port",                    (char*) &drizzled_port,               SHOW_INT},
 
421
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
 
422
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_INT},
319
423
};
320
424
 
321
425
bool sys_var::check(Session *, set_var *var)
331
435
    return 0;
332
436
 
333
437
  if ((res=(*check_func)(session, var)) < 0)
334
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), getName().c_str(), var->value->str_value.ptr());
 
438
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
 
439
             name, var->value->str_value.ptr());
335
440
  return res;
336
441
}
337
442
 
344
449
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
345
450
*/
346
451
 
347
 
static void fix_max_join_size(Session *session, sql_var_t type)
 
452
static void fix_max_join_size(Session *session, enum_var_type type)
348
453
{
349
454
  if (type != OPT_GLOBAL)
350
455
  {
374
479
  If one doesn't use the SESSION modifier, the isolation level
375
480
  is only active for the next command.
376
481
*/
377
 
static void fix_tx_isolation(Session *session, sql_var_t type)
 
482
static void fix_tx_isolation(Session *session, enum_var_type type)
378
483
{
379
484
  if (type == OPT_SESSION)
380
485
    session->session_tx_isolation= ((enum_tx_isolation)
381
486
                                    session->variables.tx_isolation);
382
487
}
383
488
 
384
 
static void fix_completion_type(Session *, sql_var_t) {}
 
489
static void fix_completion_type(Session *, enum_var_type) {}
385
490
 
386
491
static int check_completion_type(Session *, set_var *var)
387
492
{
389
494
  if (val < 0 || val > 2)
390
495
  {
391
496
    char buf[64];
392
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->getName().c_str(), internal::llstr(val, buf));
 
497
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, llstr(val, buf));
393
498
    return 1;
394
499
  }
395
500
  return 0;
396
501
}
397
502
 
398
503
 
399
 
static void fix_session_mem_root(Session *session, sql_var_t type)
 
504
/*
 
505
  If we are changing the thread variable, we have to copy it to Protocol too
 
506
*/
 
507
 
 
508
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
509
{
 
510
  if (type != OPT_GLOBAL)
 
511
    session->protocol->setReadTimeout(session->variables.net_read_timeout);
 
512
}
 
513
 
 
514
 
 
515
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
516
{
 
517
  if (type != OPT_GLOBAL)
 
518
    session->protocol->setWriteTimeout(session->variables.net_write_timeout);
 
519
}
 
520
 
 
521
static void fix_net_retry_count(Session *session, enum_var_type type)
 
522
{
 
523
  if (type != OPT_GLOBAL)
 
524
    session->protocol->setRetryCount(session->variables.net_retry_count);
 
525
}
 
526
 
 
527
 
 
528
extern void fix_delay_key_write(Session *, enum_var_type)
 
529
{
 
530
  switch ((enum_delay_key_write) delay_key_write_options) {
 
531
  case DELAY_KEY_WRITE_NONE:
 
532
    myisam_delay_key_write=0;
 
533
    break;
 
534
  case DELAY_KEY_WRITE_ON:
 
535
    myisam_delay_key_write=1;
 
536
    break;
 
537
  case DELAY_KEY_WRITE_ALL:
 
538
    myisam_delay_key_write=1;
 
539
    ha_open_options|= HA_OPEN_DELAY_KEY_WRITE;
 
540
    break;
 
541
  }
 
542
}
 
543
 
 
544
 
 
545
static void fix_session_mem_root(Session *session, enum_var_type type)
400
546
{
401
547
  if (type != OPT_GLOBAL)
402
548
    reset_root_defaults(session->mem_root,
405
551
}
406
552
 
407
553
 
408
 
static void fix_server_id(Session *, sql_var_t)
 
554
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
555
{
 
556
  if (type != OPT_GLOBAL)
 
557
    reset_root_defaults(&session->transaction.mem_root,
 
558
                        session->variables.trans_alloc_block_size,
 
559
                        session->variables.trans_prealloc_size);
 
560
}
 
561
 
 
562
 
 
563
static void fix_server_id(Session *, enum_var_type)
409
564
{
410
565
}
411
566
 
412
567
 
413
568
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
414
 
                          const std::string &name, int64_t val)
 
569
                          const char *name, int64_t val)
415
570
{
416
571
  if (fixed)
417
572
  {
418
573
    char buf[22];
419
574
 
420
575
    if (unsignd)
421
 
      internal::ullstr((uint64_t) val, buf);
 
576
      ullstr((uint64_t) val, buf);
422
577
    else
423
 
      internal::llstr(val, buf);
 
578
      llstr(val, buf);
424
579
 
425
580
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
426
581
                        ER_TRUNCATED_WRONG_VALUE,
427
 
                        ER(ER_TRUNCATED_WRONG_VALUE), name.c_str(), buf);
 
582
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
428
583
  }
429
584
  return false;
430
585
}
431
586
 
432
 
uint64_t fix_unsigned(Session *session, uint64_t num,
433
 
                              const struct option *option_limits)
 
587
static uint64_t fix_unsigned(Session *session, uint64_t num,
 
588
                              const struct my_option *option_limits)
434
589
{
435
590
  bool fixed= false;
436
591
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
441
596
 
442
597
 
443
598
static size_t fix_size_t(Session *session, size_t num,
444
 
                           const struct option *option_limits)
 
599
                           const struct my_option *option_limits)
445
600
{
446
601
  bool fixed= false;
447
602
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
450
605
  return out;
451
606
}
452
607
 
453
 
static bool get_unsigned32(Session *session, set_var *var)
 
608
static bool get_unsigned32(Session *, set_var *var)
454
609
{
455
610
  if (var->value->unsigned_flag)
456
 
    var->save_result.uint32_t_value= 
457
 
      static_cast<uint32_t>(var->value->val_int());
 
611
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
458
612
  else
459
613
  {
460
614
    int64_t v= var->value->val_int();
461
 
    if (v > UINT32_MAX)
462
 
      throw_bounds_warning(session, true, true,var->var->getName().c_str(), v);
463
 
    
464
 
    var->save_result.uint32_t_value= 
465
 
      static_cast<uint32_t>((v > UINT32_MAX) ? UINT32_MAX : (v < 0) ? 0 : v);
 
615
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
466
616
  }
467
 
  return false;
 
617
  return 0;
468
618
}
469
619
 
470
620
static bool get_unsigned64(Session *, set_var *var)
514
664
}
515
665
 
516
666
 
517
 
void sys_var_uint32_t_ptr::set_default(Session *, sql_var_t)
 
667
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
518
668
{
519
669
  bool not_used;
520
670
  pthread_mutex_lock(&LOCK_global_system_variables);
541
691
}
542
692
 
543
693
 
544
 
void sys_var_uint64_t_ptr::set_default(Session *, sql_var_t)
 
694
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
545
695
{
546
696
  bool not_used;
547
697
  pthread_mutex_lock(&LOCK_global_system_variables);
564
714
}
565
715
 
566
716
 
567
 
void sys_var_size_t_ptr::set_default(Session *, sql_var_t)
 
717
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
568
718
{
569
719
  bool not_used;
570
720
  pthread_mutex_lock(&LOCK_global_system_variables);
580
730
}
581
731
 
582
732
 
583
 
void sys_var_bool_ptr::set_default(Session *, sql_var_t)
 
733
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
584
734
{
585
735
  *value= (bool) option_limits->def_value;
586
736
}
587
737
 
588
738
 
 
739
bool sys_var_enum::update(Session *, set_var *var)
 
740
{
 
741
  *value= (uint32_t) var->save_result.uint32_t_value;
 
742
  return 0;
 
743
}
 
744
 
 
745
 
 
746
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, const LEX_STRING *)
 
747
{
 
748
  return (unsigned char*) enum_names->type_names[*value];
 
749
}
 
750
 
 
751
 
 
752
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
 
753
                                             const LEX_STRING *)
 
754
{
 
755
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
756
}
 
757
 
589
758
/*
590
759
  32 bit types for session variables
591
760
*/
602
771
  /* Don't use bigger value than given with --maximum-variable-name=.. */
603
772
  if ((uint32_t) tmp > max_system_variables.*offset)
604
773
  {
605
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
 
774
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
606
775
    tmp= max_system_variables.*offset;
607
776
  }
608
777
 
611
780
  else if (tmp > UINT32_MAX)
612
781
  {
613
782
    tmp= UINT32_MAX;
614
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) var->save_result.uint64_t_value);
 
783
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
615
784
  }
616
785
 
617
786
  if (var->type == OPT_GLOBAL)
623
792
 }
624
793
 
625
794
 
626
 
 void sys_var_session_uint32_t::set_default(Session *session, sql_var_t type)
 
795
 void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
627
796
 {
628
797
   if (type == OPT_GLOBAL)
629
798
   {
639
808
 
640
809
 
641
810
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
642
 
                                                sql_var_t type,
 
811
                                                enum_var_type type,
643
812
                                                const LEX_STRING *)
644
813
{
645
814
  if (type == OPT_GLOBAL)
671
840
}
672
841
 
673
842
 
674
 
void sys_var_session_ha_rows::set_default(Session *session, sql_var_t type)
 
843
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
675
844
{
676
845
  if (type == OPT_GLOBAL)
677
846
  {
689
858
 
690
859
 
691
860
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
692
 
                                                  sql_var_t type,
 
861
                                                  enum_var_type type,
693
862
                                                  const LEX_STRING *)
694
863
{
695
864
  if (type == OPT_GLOBAL)
708
877
  uint64_t tmp= var->save_result.uint64_t_value;
709
878
 
710
879
  if (tmp > max_system_variables.*offset)
711
 
  {
712
 
    throw_bounds_warning(session, true, true, getName(), (int64_t) tmp);
713
880
    tmp= max_system_variables.*offset;
714
 
  }
715
881
 
716
882
  if (option_limits)
717
883
    tmp= fix_unsigned(session, tmp, option_limits);
728
894
}
729
895
 
730
896
 
731
 
void sys_var_session_uint64_t::set_default(Session *session, sql_var_t type)
 
897
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
732
898
{
733
899
  if (type == OPT_GLOBAL)
734
900
  {
745
911
 
746
912
 
747
913
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
748
 
                                                   sql_var_t type,
 
914
                                                   enum_var_type type,
749
915
                                                   const LEX_STRING *)
750
916
{
751
917
  if (type == OPT_GLOBAL)
781
947
}
782
948
 
783
949
 
784
 
void sys_var_session_size_t::set_default(Session *session, sql_var_t type)
 
950
void sys_var_session_size_t::set_default(Session *session, enum_var_type type)
785
951
{
786
952
  if (type == OPT_GLOBAL)
787
953
  {
798
964
 
799
965
 
800
966
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
801
 
                                                 sql_var_t type,
 
967
                                                 enum_var_type type,
802
968
                                                 const LEX_STRING *)
803
969
{
804
970
  if (type == OPT_GLOBAL)
817
983
}
818
984
 
819
985
 
820
 
void sys_var_session_bool::set_default(Session *session,  sql_var_t type)
 
986
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
821
987
{
822
988
  if (type == OPT_GLOBAL)
823
989
    global_system_variables.*offset= (bool) option_limits->def_value;
827
993
 
828
994
 
829
995
unsigned char *sys_var_session_bool::value_ptr(Session *session,
830
 
                                               sql_var_t type,
 
996
                                               enum_var_type type,
831
997
                                               const LEX_STRING *)
832
998
{
833
999
  if (type == OPT_GLOBAL)
860
1026
    uint64_t tmp=var->value->val_int();
861
1027
    if (tmp >= enum_names->count)
862
1028
    {
863
 
      internal::llstr(tmp,buff);
 
1029
      llstr(tmp,buff);
864
1030
      value=buff;                               // Wrong value is here
865
1031
      goto err;
866
1032
    }
869
1035
  return 0;
870
1036
 
871
1037
err:
872
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), value);
 
1038
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, value);
 
1039
  return 1;
 
1040
}
 
1041
 
 
1042
 
 
1043
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
 
1044
{
 
1045
  bool not_used;
 
1046
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
 
1047
  uint32_t error_len= 0;
 
1048
  String str(buff, sizeof(buff), system_charset_info), *res;
 
1049
 
 
1050
  if (var->value->result_type() == STRING_RESULT)
 
1051
  {
 
1052
    if (!(res= var->value->val_str(&str)))
 
1053
    {
 
1054
      strcpy(buff, "NULL");
 
1055
      goto err;
 
1056
    }
 
1057
 
 
1058
    if (!m_allow_empty_value &&
 
1059
        res->length() == 0)
 
1060
    {
 
1061
      buff[0]= 0;
 
1062
      goto err;
 
1063
    }
 
1064
 
 
1065
    var->save_result.uint32_t_value= ((uint32_t)
 
1066
                                   find_set(enum_names, res->c_ptr(),
 
1067
                                            res->length(),
 
1068
                                            NULL,
 
1069
                                            &error, &error_len,
 
1070
                                            &not_used));
 
1071
    if (error_len)
 
1072
    {
 
1073
      size_t len = cmin(sizeof(buff) - 1, error_len);
 
1074
      strncpy(buff, error, len);
 
1075
      buff[len]= '\0';
 
1076
      goto err;
 
1077
    }
 
1078
  }
 
1079
  else
 
1080
  {
 
1081
    uint64_t tmp= var->value->val_int();
 
1082
 
 
1083
    if (!m_allow_empty_value &&
 
1084
        tmp == 0)
 
1085
    {
 
1086
      buff[0]= '0';
 
1087
      buff[1]= 0;
 
1088
      goto err;
 
1089
    }
 
1090
 
 
1091
    /*
 
1092
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
 
1093
      undefined, we guard with a "count<64" test.
 
1094
    */
 
1095
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1096
                 (enum_names->count < 64)))
 
1097
    {
 
1098
      llstr(tmp, buff);
 
1099
      goto err;
 
1100
    }
 
1101
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
 
1102
  }
 
1103
  return 0;
 
1104
 
 
1105
err:
 
1106
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, buff);
873
1107
  return 1;
874
1108
}
875
1109
 
882
1116
  If type is not given, return local value if exists, else global.
883
1117
*/
884
1118
 
885
 
Item *sys_var::item(Session *session, sql_var_t var_type, const LEX_STRING *base)
 
1119
Item *sys_var::item(Session *session, enum_var_type var_type, const LEX_STRING *base)
886
1120
{
887
1121
  if (check_type(var_type))
888
1122
  {
889
1123
    if (var_type != OPT_DEFAULT)
890
1124
    {
891
1125
      my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0),
892
 
               name.c_str(), var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
 
1126
               name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL");
893
1127
      return 0;
894
1128
    }
895
1129
    /* As there was no local variable, return the global value */
982
1216
    return tmp;
983
1217
  }
984
1218
  default:
985
 
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name.c_str());
 
1219
    my_error(ER_VAR_CANT_BE_READ, MYF(0), name);
986
1220
  }
987
1221
  return 0;
988
1222
}
998
1232
}
999
1233
 
1000
1234
 
1001
 
void sys_var_session_enum::set_default(Session *session, sql_var_t type)
 
1235
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1002
1236
{
1003
1237
  if (type == OPT_GLOBAL)
1004
1238
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
1008
1242
 
1009
1243
 
1010
1244
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1011
 
                                               sql_var_t type,
 
1245
                                               enum_var_type type,
1012
1246
                                               const LEX_STRING *)
1013
1247
{
1014
1248
  uint32_t tmp= ((type == OPT_GLOBAL) ?
1030
1264
}
1031
1265
 
1032
1266
 
1033
 
unsigned char *sys_var_session_bit::value_ptr(Session *session, sql_var_t,
 
1267
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
1034
1268
                                              const LEX_STRING *)
1035
1269
{
1036
1270
  /*
1059
1293
    String str(buff,sizeof(buff), system_charset_info), *res;
1060
1294
    if (!(res=var->value->val_str(&str)))
1061
1295
    {
1062
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
 
1296
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1063
1297
      return 1;
1064
1298
    }
1065
1299
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1073
1307
    if (!(tmp=get_charset((int) var->value->val_int())))
1074
1308
    {
1075
1309
      char buf[20];
1076
 
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
 
1310
      int10_to_str((int) var->value->val_int(), buf, -10);
1077
1311
      my_error(ER_UNKNOWN_COLLATION, MYF(0), buf);
1078
1312
      return 1;
1079
1313
    }
1090
1324
  else
1091
1325
  {
1092
1326
    session->variables.*offset= var->save_result.charset;
 
1327
    session->update_charset();
1093
1328
  }
1094
1329
  return 0;
1095
1330
}
1096
1331
 
1097
1332
 
1098
 
void sys_var_collation_sv::set_default(Session *session, sql_var_t type)
 
1333
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1099
1334
{
1100
1335
  if (type == OPT_GLOBAL)
1101
1336
    global_system_variables.*offset= *global_default;
1102
1337
  else
1103
1338
  {
1104
1339
    session->variables.*offset= global_system_variables.*offset;
 
1340
    session->update_charset();
1105
1341
  }
1106
1342
}
1107
1343
 
1108
1344
 
1109
1345
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1110
 
                                               sql_var_t type,
 
1346
                                               enum_var_type type,
1111
1347
                                               const LEX_STRING *)
1112
1348
{
1113
1349
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1116
1352
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1117
1353
}
1118
1354
 
 
1355
 
 
1356
LEX_STRING default_key_cache_base= {(char *) "default", 7 };
 
1357
 
 
1358
static KEY_CACHE zero_key_cache;
 
1359
 
 
1360
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
 
1361
{
 
1362
  safe_mutex_assert_owner(&LOCK_global_system_variables);
 
1363
  if (!cache_name || ! cache_name->length)
 
1364
    cache_name= &default_key_cache_base;
 
1365
  return ((KEY_CACHE*) find_named(&key_caches,
 
1366
                                  cache_name->str, cache_name->length, 0));
 
1367
}
 
1368
 
 
1369
 
 
1370
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
 
1371
                                                  const LEX_STRING *base)
 
1372
{
 
1373
  KEY_CACHE *key_cache= get_key_cache(base);
 
1374
  if (!key_cache)
 
1375
    key_cache= &zero_key_cache;
 
1376
  return (unsigned char*) key_cache + offset ;
 
1377
}
 
1378
 
 
1379
 
 
1380
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
 
1381
{
 
1382
  uint64_t tmp= var->save_result.uint64_t_value;
 
1383
  LEX_STRING *base_name= &var->base;
 
1384
  KEY_CACHE *key_cache;
 
1385
  bool error= 0;
 
1386
 
 
1387
  /* If no basename, assume it's for the key cache named 'default' */
 
1388
  if (!base_name->length)
 
1389
    base_name= &default_key_cache_base;
 
1390
 
 
1391
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1392
  key_cache= get_key_cache(base_name);
 
1393
 
 
1394
  if (!key_cache)
 
1395
  {
 
1396
    /* Key cache didn't exists */
 
1397
    if (!tmp)                                   // Tried to delete cache
 
1398
      goto end;                                 // Ok, nothing to do
 
1399
    if (!(key_cache= create_key_cache(base_name->str, base_name->length)))
 
1400
    {
 
1401
      error= 1;
 
1402
      goto end;
 
1403
    }
 
1404
  }
 
1405
 
 
1406
  /*
 
1407
    Abort if some other thread is changing the key cache
 
1408
    TODO: This should be changed so that we wait until the previous
 
1409
    assignment is done and then do the new assign
 
1410
  */
 
1411
  if (key_cache->in_init)
 
1412
    goto end;
 
1413
 
 
1414
  if (!tmp)                                     // Zero size means delete
 
1415
  {
 
1416
    if (key_cache == dflt_key_cache)
 
1417
    {
 
1418
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1419
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
 
1420
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
 
1421
      goto end;                                 // Ignore default key cache
 
1422
    }
 
1423
 
 
1424
    if (key_cache->key_cache_inited)            // If initied
 
1425
    {
 
1426
      /*
 
1427
        Move tables using this key cache to the default key cache
 
1428
        and clear the old key cache.
 
1429
      */
 
1430
      NAMED_LIST *list;
 
1431
      key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
 
1432
                                              base_name->length, &list);
 
1433
      key_cache->in_init= 1;
 
1434
      pthread_mutex_unlock(&LOCK_global_system_variables);
 
1435
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
 
1436
      pthread_mutex_lock(&LOCK_global_system_variables);
 
1437
      key_cache->in_init= 0;
 
1438
    }
 
1439
    /*
 
1440
      We don't delete the key cache as some running threads my still be
 
1441
      in the key cache code with a pointer to the deleted (empty) key cache
 
1442
    */
 
1443
    goto end;
 
1444
  }
 
1445
 
 
1446
  key_cache->param_buff_size=
 
1447
    (uint64_t) fix_unsigned(session, tmp, option_limits);
 
1448
 
 
1449
  /* If key cache didn't existed initialize it, else resize it */
 
1450
  key_cache->in_init= 1;
 
1451
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
1452
 
 
1453
  if (!key_cache->key_cache_inited)
 
1454
    error= (bool) (ha_init_key_cache("", key_cache));
 
1455
  else
 
1456
    error= (bool)(ha_resize_key_cache(key_cache));
 
1457
 
 
1458
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1459
  key_cache->in_init= 0;
 
1460
 
 
1461
end:
 
1462
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
1463
  return error;
 
1464
}
 
1465
 
 
1466
 
 
1467
/**
 
1468
  @todo
 
1469
  Abort if some other thread is changing the key cache.
 
1470
  This should be changed so that we wait until the previous
 
1471
  assignment is done and then do the new assign
 
1472
*/
 
1473
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
 
1474
{
 
1475
  uint64_t tmp= (uint64_t) var->value->val_int();
 
1476
  LEX_STRING *base_name= &var->base;
 
1477
  bool error= 0;
 
1478
 
 
1479
  if (!base_name->length)
 
1480
    base_name= &default_key_cache_base;
 
1481
 
 
1482
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1483
  KEY_CACHE *key_cache= get_key_cache(base_name);
 
1484
 
 
1485
  if (!key_cache && !(key_cache= create_key_cache(base_name->str,
 
1486
                                                  base_name->length)))
 
1487
  {
 
1488
    error= 1;
 
1489
    goto end;
 
1490
  }
 
1491
 
 
1492
  /*
 
1493
    Abort if some other thread is changing the key cache
 
1494
    TODO: This should be changed so that we wait until the previous
 
1495
    assignment is done and then do the new assign
 
1496
  */
 
1497
  if (key_cache->in_init)
 
1498
    goto end;
 
1499
 
 
1500
  *((uint32_t*) (((char*) key_cache) + offset))=
 
1501
    (uint32_t) fix_unsigned(session, tmp, option_limits);
 
1502
 
 
1503
  /*
 
1504
    Don't create a new key cache if it didn't exist
 
1505
    (key_caches are created only when the user sets block_size)
 
1506
  */
 
1507
  key_cache->in_init= 1;
 
1508
 
 
1509
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
1510
 
 
1511
  error= (bool) (ha_resize_key_cache(key_cache));
 
1512
 
 
1513
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1514
  key_cache->in_init= 0;
 
1515
 
 
1516
end:
 
1517
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
1518
  return error;
 
1519
}
 
1520
 
 
1521
 
1119
1522
/****************************************************************************/
1120
1523
 
1121
1524
bool sys_var_timestamp::update(Session *session,  set_var *var)
1125
1528
}
1126
1529
 
1127
1530
 
1128
 
void sys_var_timestamp::set_default(Session *session, sql_var_t)
 
1531
void sys_var_timestamp::set_default(Session *session, enum_var_type)
1129
1532
{
1130
1533
  session->user_time=0;
1131
1534
}
1132
1535
 
1133
1536
 
1134
 
unsigned char *sys_var_timestamp::value_ptr(Session *session, sql_var_t,
 
1537
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
1135
1538
                                            const LEX_STRING *)
1136
1539
{
1137
 
  session->sys_var_tmp.int32_t_value= (int32_t) session->start_time;
1138
 
  return (unsigned char*) &session->sys_var_tmp.int32_t_value;
 
1540
  session->sys_var_tmp.long_value= (long) session->start_time;
 
1541
  return (unsigned char*) &session->sys_var_tmp.long_value;
1139
1542
}
1140
1543
 
1141
1544
 
1148
1551
 
1149
1552
 
1150
1553
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
1151
 
                                                 sql_var_t,
 
1554
                                                 enum_var_type,
1152
1555
                                                 const LEX_STRING *)
1153
1556
{
1154
1557
  /*
1192
1595
 
1193
1596
 
1194
1597
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
1195
 
                                                    sql_var_t type,
 
1598
                                                    enum_var_type type,
1196
1599
                                                    const LEX_STRING *)
1197
1600
{
1198
1601
  /*
1216
1619
}
1217
1620
 
1218
1621
 
1219
 
void sys_var_session_time_zone::set_default(Session *session, sql_var_t type)
 
1622
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
1220
1623
{
1221
1624
 pthread_mutex_lock(&LOCK_global_system_variables);
1222
1625
 if (type == OPT_GLOBAL)
1248
1651
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
1249
1652
    {
1250
1653
      char buf[20];
1251
 
      internal::int10_to_str((int) var->value->val_int(), buf, -10);
 
1654
      int10_to_str((int) var->value->val_int(), buf, -10);
1252
1655
      my_printf_error(ER_UNKNOWN_ERROR, "Unknown locale: '%s'", MYF(0), buf);
1253
1656
      return 1;
1254
1657
    }
1259
1662
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
1260
1663
    if (!(res=var->value->val_str(&str)))
1261
1664
    {
1262
 
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name.c_str(), "NULL");
 
1665
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1263
1666
      return 1;
1264
1667
    }
1265
1668
    const char *locale_str= res->c_ptr();
1287
1690
 
1288
1691
 
1289
1692
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
1290
 
                                                        sql_var_t type,
 
1693
                                                        enum_var_type type,
1291
1694
                                                        const LEX_STRING *)
1292
1695
{
1293
1696
  return type == OPT_GLOBAL ?
1296
1699
}
1297
1700
 
1298
1701
 
1299
 
void sys_var_session_lc_time_names::set_default(Session *session, sql_var_t type)
 
1702
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
1300
1703
{
1301
1704
  if (type == OPT_GLOBAL)
1302
1705
    global_system_variables.lc_time_names= my_default_lc_time_names;
1334
1737
}
1335
1738
 
1336
1739
 
1337
 
void sys_var_microseconds::set_default(Session *session, sql_var_t type)
 
1740
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
1338
1741
{
1339
1742
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
1340
1743
  if (type == OPT_GLOBAL)
1347
1750
    session->variables.*offset= microseconds;
1348
1751
}
1349
1752
 
 
1753
 
 
1754
unsigned char *sys_var_microseconds::value_ptr(Session *session,
 
1755
                                               enum_var_type type,
 
1756
                                               const LEX_STRING *)
 
1757
{
 
1758
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
1759
                                   global_system_variables.*offset :
 
1760
                                   session->variables.*offset) / 1000000.0;
 
1761
  return (unsigned char*) &session->tmp_double_value;
 
1762
}
 
1763
 
 
1764
 
1350
1765
/*
1351
1766
  Functions to update session->options bits
1352
1767
*/
1378
1793
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1379
1794
    {
1380
1795
      /* We changed to auto_commit mode */
1381
 
      session->options&= ~(uint64_t) (OPTION_BEGIN);
 
1796
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
1797
      session->transaction.all.modified_non_trans_table= false;
1382
1798
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1383
 
      TransactionServices &transaction_services= TransactionServices::singleton();
1384
 
      if (transaction_services.ha_commit_trans(session, true))
1385
 
        return 1;
 
1799
      if (ha_commit(session))
 
1800
        return 1;
1386
1801
    }
1387
1802
    else
1388
1803
    {
 
1804
      session->transaction.all.modified_non_trans_table= false;
1389
1805
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1390
1806
    }
1391
1807
  }
1455
1871
    ptr         pointer to option structure
1456
1872
*/
1457
1873
 
1458
 
static struct option *find_option(struct option *opt, const char *name)
 
1874
static struct my_option *find_option(struct my_option *opt, const char *name)
1459
1875
{
1460
1876
  uint32_t length=strlen(name);
1461
1877
  for (; opt->name; opt++)
1488
1904
*/
1489
1905
 
1490
1906
 
1491
 
int mysql_add_sys_var_chain(sys_var *first, struct option *long_options)
 
1907
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
1492
1908
{
1493
1909
  sys_var *var;
1494
1910
  /* A write lock should be held on LOCK_system_variables_hash */
1495
1911
 
1496
 
  for (var= first; var; var= var->getNext())
 
1912
  for (var= first; var; var= var->next)
1497
1913
  {
1498
 
 
1499
 
    string lower_name(var->getName());
1500
 
    transform(lower_name.begin(), lower_name.end(),
1501
 
              lower_name.begin(), ::tolower);
 
1914
    /* Make a temp string to hold this and then make it lower so that matching
 
1915
     * happens case-insensitive.
 
1916
     */
 
1917
    string var_name(var->name);
 
1918
    transform(var_name.begin(), var_name.end(), var_name.begin(), ::tolower);
 
1919
    var->name_length= var_name.length();
1502
1920
 
1503
1921
    /* this fails if there is a conflicting variable name. */
1504
 
    if (system_variable_map.find(lower_name) != system_variable_map.end())
 
1922
    if (system_variable_hash.count(var_name) == 0)
1505
1923
    {
1506
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Variable named %s already exists!\n"),
1507
 
                    var->getName().c_str());
1508
 
      return 1;
 
1924
      system_variable_hash[var_name]= var;
1509
1925
    } 
1510
 
 
1511
 
    pair<SystemVariableMap::iterator, bool> ret= 
1512
 
      system_variable_map.insert(make_pair(lower_name, var));
1513
 
    if (ret.second == false)
 
1926
    else
1514
1927
    {
1515
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Could not add Variable: %s\n"),
1516
 
                    var->getName().c_str());
 
1928
      for (; first != var; first= first->next)
 
1929
      {
 
1930
        /*
 
1931
         * This is slightly expensive, since we have to do the transform 
 
1932
         * _again_ but should rarely happen unless there is a pretty
 
1933
         * major problem in the code
 
1934
         */
 
1935
        var_name= first->name;
 
1936
        transform(var_name.begin(), var_name.end(),
 
1937
                  var_name.begin(), ::tolower);
 
1938
        system_variable_hash.erase(var_name);
 
1939
      }
1517
1940
      return 1;
1518
1941
    }
1519
 
 
1520
1942
    if (long_options)
1521
 
      var->setOptionLimits(find_option(long_options, var->getName().c_str()));
 
1943
      var->option_limits= find_option(long_options, var->name);
1522
1944
  }
1523
1945
  return 0;
1524
1946
 
1539
1961
 
1540
1962
int mysql_del_sys_var_chain(sys_var *first)
1541
1963
{
 
1964
  int result= 0;
 
1965
  string var_name;
1542
1966
 
1543
1967
  /* A write lock should be held on LOCK_system_variables_hash */
1544
 
  for (sys_var *var= first; var; var= var->getNext())
 
1968
  for (sys_var *var= first; var; var= var->next)
1545
1969
  {
1546
 
    string lower_name(var->getName());
1547
 
    transform(lower_name.begin(), lower_name.end(),
1548
 
              lower_name.begin(), ::tolower);
1549
 
    system_variable_map.erase(lower_name);
 
1970
    var_name= var->name;
 
1971
    transform(var_name.begin(), var_name.end(),
 
1972
              var_name.begin(), ::tolower);
 
1973
    result|= system_variable_hash.erase(var_name);
1550
1974
  }
1551
 
  return 0;
 
1975
 
 
1976
  return result;
1552
1977
}
1553
1978
 
1554
1979
 
1562
1987
    sorted      If TRUE, the system variables should be sorted
1563
1988
 
1564
1989
  RETURN VALUES
1565
 
    pointer     Array of drizzle_show_var elements for display
 
1990
    pointer     Array of SHOW_VAR elements for display
1566
1991
    NULL        FAILURE
1567
1992
*/
1568
1993
 
1569
 
drizzle_show_var* enumerate_sys_vars(Session *session, bool)
 
1994
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
1570
1995
{
1571
1996
  int fixed_count= fixed_show_vars.elements;
1572
 
  int size= sizeof(drizzle_show_var) * (system_variable_map.size() + fixed_count + 1);
1573
 
  drizzle_show_var *result= (drizzle_show_var*) session->alloc(size);
 
1997
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
 
1998
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
1574
1999
 
1575
2000
  if (result)
1576
2001
  {
1577
 
    drizzle_show_var *show= result + fixed_count;
1578
 
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(drizzle_show_var));
 
2002
    SHOW_VAR *show= result + fixed_count;
 
2003
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
1579
2004
 
1580
 
    SystemVariableMap::const_iterator iter= system_variable_map.begin();
1581
 
    while (iter != system_variable_map.end())
 
2005
    map<string, sys_var *>::iterator iter;
 
2006
    for(iter= system_variable_hash.begin();
 
2007
        iter != system_variable_hash.end();
 
2008
        iter++)
1582
2009
    {
1583
2010
      sys_var *var= (*iter).second;
1584
 
      show->name= var->getName().c_str();
 
2011
      show->name= var->name;
1585
2012
      show->value= (char*) var;
1586
2013
      show->type= SHOW_SYS;
1587
2014
      show++;
1588
 
      ++iter;
1589
2015
    }
1590
2016
 
1591
2017
    /* make last element empty */
1592
 
    memset(show, 0, sizeof(drizzle_show_var));
 
2018
    memset(show, 0, sizeof(SHOW_VAR));
1593
2019
  }
1594
2020
  return result;
1595
2021
}
1596
2022
 
1597
2023
 
 
2024
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
2025
                       uint32_t name_length_arg, unsigned char* data_arg)
 
2026
    :data(data_arg)
 
2027
{
 
2028
  name.assign(name_arg, name_length_arg);
 
2029
  links->push_back(this);
 
2030
}
 
2031
 
 
2032
 
 
2033
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
 
2034
{
 
2035
  return length == name.length() && !name.compare(name_cmp);
 
2036
}
 
2037
 
 
2038
 
1598
2039
/*
1599
2040
  Initialize the system variables
1600
2041
 
1610
2051
{
1611
2052
  uint32_t count= 0;
1612
2053
 
1613
 
  for (sys_var *var= vars.first; var; var= var->getNext(), count++) {};
 
2054
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
1614
2055
 
1615
 
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(drizzle_show_var),
 
2056
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
1616
2057
                            FIXED_VARS_SIZE + 64, 64))
1617
2058
    goto error;
1618
2059
 
1619
2060
  fixed_show_vars.elements= FIXED_VARS_SIZE;
1620
2061
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
1621
2062
 
1622
 
  vars.last->setNext(NULL);
 
2063
  vars.last->next= NULL;
1623
2064
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
1624
2065
    goto error;
1625
2066
 
1637
2078
}
1638
2079
 
1639
2080
 
 
2081
/*
 
2082
  Add elements to the dynamic list of read-only system variables.
 
2083
 
 
2084
  SYNOPSIS
 
2085
    mysql_append_static_vars()
 
2086
    show_vars   Pointer to start of array
 
2087
    count       Number of elements
 
2088
 
 
2089
  RETURN VALUES
 
2090
    0           SUCCESS
 
2091
    otherwise   FAILURE
 
2092
*/
 
2093
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
2094
{
 
2095
  for (; count > 0; count--, show_vars++)
 
2096
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
2097
      return 1;
 
2098
  return 0;
 
2099
}
 
2100
 
 
2101
 
1640
2102
/**
1641
2103
  Find a user set-table variable.
1642
2104
 
1653
2115
 
1654
2116
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
1655
2117
{
1656
 
  string lower_name(str);
1657
 
  transform(lower_name.begin(), lower_name.end(),
1658
 
            lower_name.begin(), ::tolower);
1659
 
 
1660
 
  sys_var *result= NULL;
1661
 
 
1662
 
  SystemVariableMap::iterator iter= system_variable_map.find(lower_name);
1663
 
  if (iter != system_variable_map.end())
1664
 
  {
1665
 
    result= (*iter).second;
1666
 
  } 
1667
 
 
1668
2118
  /*
1669
2119
    This function is only called from the sql_plugin.cc.
1670
2120
    A lock on LOCK_system_variable_hash should be held
1671
2121
  */
1672
 
  if (result == NULL)
 
2122
  string lower_var(str);
 
2123
  transform(lower_var.begin(), lower_var.end(), lower_var.begin(), ::tolower);
 
2124
  map<string, sys_var *>::iterator result_iter=
 
2125
    system_variable_hash.find(lower_var);
 
2126
  if (result_iter == system_variable_hash.end())
1673
2127
  {
1674
2128
    if (no_error)
1675
2129
    {
1682
2136
    }
1683
2137
  }
1684
2138
 
1685
 
  return result;
 
2139
  return (*result_iter).second;
1686
2140
}
1687
2141
 
1688
2142
 
1738
2192
{
1739
2193
  if (var->is_readonly())
1740
2194
  {
1741
 
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->getName().c_str(), "read only");
 
2195
    my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), var->name, "read only");
1742
2196
    return -1;
1743
2197
  }
1744
2198
  if (var->check_type(type))
1745
2199
  {
1746
2200
    int err= type == OPT_GLOBAL ? ER_LOCAL_VARIABLE : ER_GLOBAL_VARIABLE;
1747
 
    my_error(err, MYF(0), var->getName().c_str());
 
2201
    my_error(err, MYF(0), var->name);
1748
2202
    return -1;
1749
2203
  }
1750
2204
  /* value is a NULL pointer if we are using SET ... = DEFAULT */
1752
2206
  {
1753
2207
    if (var->check_default(type))
1754
2208
    {
1755
 
      my_error(ER_NO_DEFAULT, MYF(0), var->getName().c_str());
 
2209
      my_error(ER_NO_DEFAULT, MYF(0), var->name);
1756
2210
      return -1;
1757
2211
    }
1758
2212
    return 0;
1763
2217
    return -1;
1764
2218
  if (var->check_update_type(value->result_type()))
1765
2219
  {
1766
 
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->getName().c_str());
 
2220
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
1767
2221
    return -1;
1768
2222
  }
1769
2223
  return var->check(session, this) ? -1 : 0;
1783
2237
*/
1784
2238
int set_var::update(Session *session)
1785
2239
{
1786
 
  if (! value)
 
2240
  if (!value)
1787
2241
    var->set_default(session, type);
1788
2242
  else if (var->update(session, this))
1789
2243
    return -1;                          // should never happen
1790
 
  if (var->getAfterUpdateTrigger())
1791
 
    (*var->getAfterUpdateTrigger())(session, type);
 
2244
  if (var->after_update)
 
2245
    (*var->after_update)(session, type);
1792
2246
  return 0;
1793
2247
}
1794
2248
 
 
2249
 
1795
2250
/*****************************************************************************
1796
2251
  Functions to handle SET @user_variable=const_expr
1797
2252
*****************************************************************************/
1833
2288
  var->save_result.storage_engine= NULL;
1834
2289
  if (var->value->result_type() == STRING_RESULT)
1835
2290
  {
1836
 
    res= var->value->val_str(&str);
1837
 
    if (res == NULL || res->ptr() == NULL)
 
2291
    LEX_STRING engine_name;
 
2292
    StorageEngine *engine;
 
2293
    if (!(res=var->value->val_str(&str)) ||
 
2294
        !(engine_name.str= (char *)res->ptr()) ||
 
2295
        !(engine_name.length= res->length()) ||
 
2296
              !(var->save_result.storage_engine=
 
2297
            ha_resolve_by_name(session, &engine_name)) ||
 
2298
        !(engine= var->save_result.storage_engine))
1838
2299
    {
1839
 
      value= "NULL";
 
2300
      value= res ? res->c_ptr() : "NULL";
1840
2301
      goto err;
1841
2302
    }
1842
 
    else
1843
 
    {
1844
 
      const std::string engine_name(res->ptr());
1845
 
      plugin::StorageEngine *engine;
1846
 
      var->save_result.storage_engine= plugin::StorageEngine::findByName(*session, engine_name);
1847
 
      if (var->save_result.storage_engine == NULL)
1848
 
      {
1849
 
        value= res->c_ptr();
1850
 
        goto err;
1851
 
      }
1852
 
      engine= var->save_result.storage_engine;
1853
 
    }
1854
2303
    return 0;
1855
2304
  }
1856
2305
  value= "unknown";
1862
2311
 
1863
2312
 
1864
2313
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
1865
 
                                                         sql_var_t type,
 
2314
                                                         enum_var_type type,
1866
2315
                                                         const LEX_STRING *)
1867
2316
{
1868
2317
  unsigned char* result;
1869
2318
  string engine_name;
1870
 
  plugin::StorageEngine *engine= session->variables.*offset;
 
2319
  StorageEngine *engine= session->variables.*offset;
1871
2320
  if (type == OPT_GLOBAL)
1872
2321
    engine= global_system_variables.*offset;
1873
2322
  engine_name= engine->getName();
1877
2326
}
1878
2327
 
1879
2328
 
1880
 
void sys_var_session_storage_engine::set_default(Session *session, sql_var_t type)
 
2329
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
1881
2330
{
1882
 
  plugin::StorageEngine *old_value, *new_value, **value;
 
2331
  StorageEngine *old_value, *new_value, **value;
1883
2332
  if (type == OPT_GLOBAL)
1884
2333
  {
1885
2334
    value= &(global_system_variables.*offset);
1898
2347
 
1899
2348
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
1900
2349
{
1901
 
  plugin::StorageEngine **value= &(global_system_variables.*offset), *old_value;
 
2350
  StorageEngine **value= &(global_system_variables.*offset), *old_value;
1902
2351
   if (var->type != OPT_GLOBAL)
1903
2352
     value= &(session->variables.*offset);
1904
2353
  old_value= *value;
1909
2358
  return 0;
1910
2359
}
1911
2360
 
1912
 
} /* namespace drizzled */
 
2361
bool
 
2362
sys_var_session_optimizer_switch::
 
2363
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
 
2364
{
 
2365
  char buff[STRING_BUFFER_USUAL_SIZE*8];
 
2366
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2367
 
 
2368
  tmp.length(0);
 
2369
 
 
2370
  for (uint32_t i= 0; val; val>>= 1, i++)
 
2371
  {
 
2372
    if (val & 1)
 
2373
    {
 
2374
      tmp.append(optimizer_switch_typelib.type_names[i],
 
2375
                 optimizer_switch_typelib.type_lengths[i]);
 
2376
      tmp.append(',');
 
2377
    }
 
2378
  }
 
2379
 
 
2380
  if (tmp.length())
 
2381
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
 
2382
 
 
2383
  rep->str= session->strmake(tmp.ptr(), tmp.length());
 
2384
 
 
2385
  rep->length= rep->str ? tmp.length() : 0;
 
2386
 
 
2387
  return rep->length != tmp.length();
 
2388
}
 
2389
 
 
2390
 
 
2391
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
 
2392
                                                           enum_var_type type,
 
2393
                                                           const LEX_STRING *)
 
2394
{
 
2395
  LEX_STRING opts;
 
2396
  uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
2397
                  session->variables.*offset);
 
2398
  (void) symbolic_mode_representation(session, val, &opts);
 
2399
  return (unsigned char *) opts.str;
 
2400
}
 
2401
 
 
2402
 
 
2403
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
 
2404
{
 
2405
  if (type == OPT_GLOBAL)
 
2406
    global_system_variables.*offset= 0;
 
2407
  else
 
2408
    session->variables.*offset= global_system_variables.*offset;
 
2409
}
 
2410
 
 
2411
 
 
2412
/****************************************************************************
 
2413
  Named list handling
 
2414
****************************************************************************/
 
2415
 
 
2416
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
2417
                NAMED_LIST **found)
 
2418
{
 
2419
  I_List_iterator<NAMED_LIST> it(*list);
 
2420
  NAMED_LIST *element;
 
2421
  while ((element= it++))
 
2422
  {
 
2423
    if (element->cmp(name, length))
 
2424
    {
 
2425
      if (found)
 
2426
        *found= element;
 
2427
      return element->data;
 
2428
    }
 
2429
  }
 
2430
  return 0;
 
2431
}
 
2432
 
 
2433
 
 
2434
void delete_elements(I_List<NAMED_LIST> *list,
 
2435
                     void (*free_element)(const char *name, unsigned char*))
 
2436
{
 
2437
  NAMED_LIST *element;
 
2438
  while ((element= list->get()))
 
2439
  {
 
2440
    (*free_element)(element->name.c_str(), element->data);
 
2441
    delete element;
 
2442
  }
 
2443
  return;
 
2444
}
 
2445
 
 
2446
 
 
2447
/* Key cache functions */
 
2448
 
 
2449
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
2450
{
 
2451
  KEY_CACHE *key_cache;
 
2452
 
 
2453
  if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
 
2454
  {
 
2455
    memset(key_cache, 0, sizeof(KEY_CACHE));
 
2456
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
2457
    {
 
2458
      free((char*) key_cache);
 
2459
      key_cache= 0;
 
2460
    }
 
2461
    else
 
2462
    {
 
2463
      /*
 
2464
        Set default values for a key cache
 
2465
        The values in dflt_key_cache_var is set by my_getopt() at startup
 
2466
 
 
2467
        We don't set 'buff_size' as this is used to enable the key cache
 
2468
      */
 
2469
      key_cache->param_block_size=     dflt_key_cache_var.param_block_size;
 
2470
      key_cache->param_division_limit= dflt_key_cache_var.param_division_limit;
 
2471
      key_cache->param_age_threshold=  dflt_key_cache_var.param_age_threshold;
 
2472
    }
 
2473
  }
 
2474
  return(key_cache);
 
2475
}
 
2476
 
 
2477
 
 
2478
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
2479
{
 
2480
  LEX_STRING key_cache_name;
 
2481
  KEY_CACHE *key_cache;
 
2482
 
 
2483
  key_cache_name.str= (char *) name;
 
2484
  key_cache_name.length= length;
 
2485
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2486
  if (!(key_cache= get_key_cache(&key_cache_name)))
 
2487
    key_cache= create_key_cache(name, length);
 
2488
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2489
  return key_cache;
 
2490
}
 
2491
 
 
2492
 
 
2493
void free_key_cache(const char *, KEY_CACHE *key_cache)
 
2494
{
 
2495
  ha_end_key_cache(key_cache);
 
2496
  free((char*) key_cache);
 
2497
}
 
2498
 
 
2499
 
 
2500
bool process_key_caches(process_key_cache_t func)
 
2501
{
 
2502
  I_List_iterator<NAMED_LIST> it(key_caches);
 
2503
  NAMED_LIST *element;
 
2504
 
 
2505
  while ((element= it++))
 
2506
  {
 
2507
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
 
2508
    func(element->name.c_str(), key_cache);
 
2509
  }
 
2510
  return 0;
 
2511
}
 
2512
 
 
2513
/****************************************************************************
 
2514
  Used templates
 
2515
****************************************************************************/
 
2516
 
 
2517
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
 
2518
template class List<set_var_base>;
 
2519
template class List_iterator_fast<set_var_base>;
 
2520
template class I_List_iterator<NAMED_LIST>;
 
2521
#endif