~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/set_var.cc

  • Committer: Stewart Smith
  • Date: 2008-07-13 08:00:16 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713080016-8qtjv9ypt42azzr6
CRC32() as UDF

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; version 2 of the License.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
19
15
 
20
16
/**
21
17
  @file
46
42
 
47
43
  @note
48
44
    Be careful with var->save_result: sys_var::check() only updates
49
 
    uint64_t_value; so other members of the union are garbage then; to use
 
45
    ulonglong_value; so other members of the union are garbage then; to use
50
46
    them you must first assign a value to them (in specific ::check() for
51
47
    example).
52
48
*/
53
49
 
54
 
#include <drizzled/server_includes.h>
55
 
#include <mysys/my_getopt.h>
56
 
#include <storage/myisam/myisam.h>
57
 
#include <drizzled/error.h>
58
 
#include <drizzled/gettext.h>
59
 
#include <drizzled/tztime.h>
60
 
#include <drizzled/data_home.h>
61
 
#include <drizzled/set_var.h>
62
 
#include <drizzled/session.h>
63
 
#include <drizzled/sql_base.h>
64
 
#include <drizzled/lock.h>
65
 
#include <drizzled/item/uint.h>
66
 
#include <drizzled/item/null.h>
67
 
#include <drizzled/item/float.h>
68
 
 
69
 
#include <map>
70
 
#include <algorithm>
71
 
 
72
 
using namespace std;
73
 
 
74
 
extern const CHARSET_INFO *character_set_filesystem;
75
 
extern I_List<NAMED_LIST> key_caches;
76
 
extern size_t my_thread_stack_size;
 
50
#ifdef USE_PRAGMA_IMPLEMENTATION
 
51
#pragma implementation                          // gcc: Class implementation
 
52
#endif
 
53
 
 
54
#include "mysql_priv.h"
 
55
#include "slave.h"
 
56
#include "rpl_mi.h"
 
57
#include <my_getopt.h>
 
58
#include <thr_alarm.h>
 
59
#include <myisam.h>
 
60
#include <my_dir.h>
 
61
 
 
62
extern CHARSET_INFO *character_set_filesystem;
 
63
 
77
64
 
78
65
static DYNAMIC_ARRAY fixed_show_vars;
79
 
static map<const string, sys_var *> system_variable_hash;
80
 
extern char *opt_drizzle_tmpdir;
 
66
static HASH system_variable_hash;
81
67
 
82
 
const char *bool_type_names[]= { "OFF", "ON", NULL };
 
68
const char *bool_type_names[]= { "OFF", "ON", NullS };
83
69
TYPELIB bool_typelib=
84
70
{
85
71
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
86
72
};
87
73
 
88
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
 
74
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
89
75
TYPELIB delay_key_write_typelib=
90
76
{
91
77
  array_elements(delay_key_write_type_names)-1, "",
92
78
  delay_key_write_type_names, NULL
93
79
};
94
80
 
95
 
static bool set_option_bit(Session *session, set_var *var);
96
 
static bool set_option_autocommit(Session *session, set_var *var);
97
 
static int  check_pseudo_thread_id(Session *session, set_var *var);
98
 
static int check_tx_isolation(Session *session, set_var *var);
99
 
static void fix_tx_isolation(Session *session, enum_var_type type);
100
 
static int check_completion_type(Session *session, set_var *var);
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 *);
110
 
static bool get_unsigned32(Session *session, set_var *var);
111
 
static bool get_unsigned64(Session *session, set_var *var);
112
 
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
113
 
                          const char *name, int64_t val);
114
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
 
static unsigned char *get_error_count(Session *session);
116
 
static unsigned char *get_warning_count(Session *session);
117
 
static unsigned char *get_tmpdir(Session *session);
 
81
const char *slave_exec_mode_names[]=
 
82
{ "STRICT", "IDEMPOTENT", NullS };
 
83
static const unsigned int slave_exec_mode_names_len[]=
 
84
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
 
85
TYPELIB slave_exec_mode_typelib=
 
86
{
 
87
  array_elements(slave_exec_mode_names)-1, "",
 
88
  slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
 
89
};
 
90
 
 
91
static bool sys_update_init_connect(THD*, set_var*);
 
92
static void sys_default_init_connect(THD*, enum_var_type type);
 
93
static bool sys_update_init_slave(THD*, set_var*);
 
94
static void sys_default_init_slave(THD*, enum_var_type type);
 
95
static bool set_option_bit(THD *thd, set_var *var);
 
96
static bool set_option_autocommit(THD *thd, set_var *var);
 
97
static int  check_log_update(THD *thd, set_var *var);
 
98
static bool set_log_update(THD *thd, set_var *var);
 
99
static int  check_pseudo_thread_id(THD *thd, set_var *var);
 
100
static void fix_low_priority_updates(THD *thd, enum_var_type type);
 
101
static int check_tx_isolation(THD *thd, set_var *var);
 
102
static void fix_tx_isolation(THD *thd, enum_var_type type);
 
103
static int check_completion_type(THD *thd, set_var *var);
 
104
static void fix_completion_type(THD *thd, enum_var_type type);
 
105
static void fix_net_read_timeout(THD *thd, enum_var_type type);
 
106
static void fix_net_write_timeout(THD *thd, enum_var_type type);
 
107
static void fix_net_retry_count(THD *thd, enum_var_type type);
 
108
static void fix_max_join_size(THD *thd, enum_var_type type);
 
109
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
 
110
static void fix_max_binlog_size(THD *thd, enum_var_type type);
 
111
static void fix_max_relay_log_size(THD *thd, enum_var_type type);
 
112
static void fix_max_connections(THD *thd, enum_var_type type);
 
113
static void fix_thd_mem_root(THD *thd, enum_var_type type);
 
114
static void fix_trans_mem_root(THD *thd, enum_var_type type);
 
115
static void fix_server_id(THD *thd, enum_var_type type);
 
116
static ulonglong fix_unsigned(THD *, ulonglong, const struct my_option *);
 
117
static bool get_unsigned(THD *thd, set_var *var);
 
118
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
119
                          const char *name, longlong val);
 
120
static KEY_CACHE *create_key_cache(const char *name, uint length);
 
121
static uchar *get_error_count(THD *thd);
 
122
static uchar *get_warning_count(THD *thd);
 
123
static uchar *get_tmpdir(THD *thd);
 
124
static int  sys_check_log_path(THD *thd,  set_var *var);
 
125
static bool sys_update_general_log_path(THD *thd, set_var * var);
 
126
static void sys_default_general_log_path(THD *thd, enum_var_type type);
 
127
static bool sys_update_slow_log_path(THD *thd, set_var * var);
 
128
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
118
129
 
119
130
/*
120
131
  Variable definition list
128
139
 
129
140
static sys_var_chain vars = { NULL, NULL };
130
141
 
131
 
static sys_var_session_uint64_t
 
142
static sys_var_thd_ulong
132
143
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
144
                             &SV::auto_increment_increment, NULL, NULL,
134
145
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
135
 
static sys_var_session_uint64_t
 
146
static sys_var_thd_ulong
136
147
sys_auto_increment_offset(&vars, "auto_increment_offset",
137
148
                          &SV::auto_increment_offset, NULL, NULL,
138
149
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
139
150
 
140
 
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
141
 
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
142
 
                                                          &SV::bulk_insert_buff_size);
143
 
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
144
 
                                                    &SV::completion_type,
145
 
                                                    check_completion_type,
146
 
                                                    fix_completion_type);
 
151
static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
 
152
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
 
153
                                              &binlog_cache_size);
 
154
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
 
155
                                            &SV::binlog_format);
 
156
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
157
                                                  &SV::bulk_insert_buff_size);
 
158
static sys_var_character_set_sv
 
159
sys_character_set_server(&vars, "character_set_server",
 
160
                         &SV::collation_server, &default_charset_info, 0,
 
161
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
162
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
 
163
                                           (char *)my_charset_utf8_general_ci.name);
 
164
static sys_var_character_set_database
 
165
sys_character_set_database(&vars, "character_set_database",
 
166
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
 
167
static sys_var_character_set_client
 
168
sys_character_set_client(&vars, "character_set_client",
 
169
                         &SV::character_set_client,
 
170
                         &default_charset_info,
 
171
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
172
static sys_var_character_set_sv
 
173
sys_character_set_connection(&vars, "character_set_connection",
 
174
                             &SV::collation_connection,
 
175
                             &default_charset_info, 0,
 
176
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
 
177
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
 
178
                                        &SV::character_set_results,
 
179
                                        &default_charset_info, true);
 
180
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
 
181
                                        &SV::character_set_filesystem,
 
182
                                        &character_set_filesystem);
 
183
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
 
184
                                         &SV::completion_type,
 
185
                                         check_completion_type,
 
186
                                         fix_completion_type);
 
187
static sys_var_collation_sv
 
188
sys_collation_connection(&vars, "collation_connection",
 
189
                         &SV::collation_connection, &default_charset_info,
 
190
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
147
191
static sys_var_collation_sv
148
192
sys_collation_database(&vars, "collation_database", &SV::collation_database,
149
193
                       &default_charset_info,
152
196
sys_collation_server(&vars, "collation_server", &SV::collation_server,
153
197
                     &default_charset_info,
154
198
                     sys_var::SESSION_VARIABLE_IN_BINLOG);
155
 
static sys_var_uint32_t_ptr     sys_connect_timeout(&vars, "connect_timeout",
156
 
                                                &connect_timeout);
157
 
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
 
199
static sys_var_long_ptr sys_concurrent_insert(&vars, "concurrent_insert",
 
200
                                              &myisam_concurrent_insert);
 
201
static sys_var_long_ptr sys_connect_timeout(&vars, "connect_timeout",
 
202
                                            &connect_timeout);
 
203
static sys_var_const_str       sys_datadir(&vars, "datadir", mysql_real_data_home);
158
204
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
159
205
                                            &delay_key_write_options,
160
206
                                            &delay_key_write_typelib,
161
207
                                            fix_delay_key_write);
162
208
 
 
209
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
 
210
                                             &expire_logs_days);
163
211
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
164
 
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
165
 
                                                     &SV::join_buff_size);
 
212
static sys_var_long_ptr sys_flush_time(&vars, "flush_time", &flush_time);
 
213
sys_var_str             sys_init_connect(&vars, "init_connect", 0,
 
214
                                         sys_update_init_connect,
 
215
                                         sys_default_init_connect,0);
 
216
sys_var_str             sys_init_slave(&vars, "init_slave", 0,
 
217
                                       sys_update_init_slave,
 
218
                                       sys_default_init_slave,0);
 
219
static sys_var_thd_ulong        sys_interactive_timeout(&vars, "interactive_timeout",
 
220
                                                &SV::net_interactive_timeout);
 
221
static sys_var_thd_ulong        sys_join_buffer_size(&vars, "join_buffer_size",
 
222
                                             &SV::join_buff_size);
166
223
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));
176
 
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
177
 
                                                       &SV::max_allowed_packet);
178
 
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
179
 
                                               &max_connect_errors);
180
 
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
181
 
                                                  &SV::max_error_count);
182
 
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
183
 
                                                        &SV::max_heap_table_size);
184
 
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 
224
static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
 
225
                                                 offsetof(KEY_CACHE,
 
226
                                                          param_block_size));
 
227
static sys_var_key_cache_long   sys_key_cache_division_limit(&vars, "key_cache_division_limit",
 
228
                                                     offsetof(KEY_CACHE,
 
229
                                                              param_division_limit));
 
230
static sys_var_key_cache_long  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
 
231
                                                     offsetof(KEY_CACHE,
 
232
                                                              param_age_threshold));
 
233
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
 
234
                                         &opt_local_infile);
 
235
static sys_var_bool_ptr
 
236
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
 
237
                                    &opt_log_queries_not_using_indexes);
 
238
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
 
239
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
 
240
                                                        &SV::long_query_time);
 
241
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
 
242
                                                 &SV::low_priority_updates,
 
243
                                                 fix_low_priority_updates);
 
244
#ifndef TO_BE_DELETED   /* Alias for the low_priority_updates */
 
245
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
 
246
                                                     &SV::low_priority_updates,
 
247
                                                     fix_low_priority_updates);
 
248
#endif
 
249
static sys_var_thd_ulong        sys_max_allowed_packet(&vars, "max_allowed_packet",
 
250
                                               &SV::max_allowed_packet);
 
251
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
 
252
                                                  &max_binlog_cache_size);
 
253
static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size",
 
254
                                            &max_binlog_size,
 
255
                                            fix_max_binlog_size);
 
256
static sys_var_long_ptr sys_max_connections(&vars, "max_connections",
 
257
                                            &max_connections,
 
258
                                            fix_max_connections);
 
259
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
 
260
                                               &max_connect_errors);
 
261
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
 
262
                                            &SV::max_error_count);
 
263
static sys_var_thd_ulonglong    sys_max_heap_table_size(&vars, "max_heap_table_size",
 
264
                                                &SV::max_heap_table_size);
 
265
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
185
266
                                              &SV::pseudo_thread_id,
186
 
                                              0, check_pseudo_thread_id,
 
267
                                              check_pseudo_thread_id, 0,
187
268
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
188
 
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
189
 
                                                  &SV::max_join_size,
190
 
                                                  fix_max_join_size);
191
 
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
192
 
                                                      &SV::max_seeks_for_key);
193
 
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
194
 
                                                               &SV::max_length_for_sort_data);
195
 
static sys_var_session_size_t   sys_max_sort_length(&vars, "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);
199
 
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
200
 
                                                 &max_write_lock_count);
201
 
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
202
 
                                                           &SV::min_examined_row_limit);
 
269
static sys_var_thd_ha_rows      sys_max_join_size(&vars, "max_join_size",
 
270
                                          &SV::max_join_size,
 
271
                                          fix_max_join_size);
 
272
static sys_var_thd_ulong        sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
273
                                              &SV::max_seeks_for_key);
 
274
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
275
                                                 &SV::max_length_for_sort_data);
 
276
#ifndef TO_BE_DELETED   /* Alias for max_join_size */
 
277
static sys_var_thd_ha_rows      sys_sql_max_join_size(&vars, "sql_max_join_size",
 
278
                                              &SV::max_join_size,
 
279
                                              fix_max_join_size);
 
280
#endif
 
281
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
 
282
                                               &max_relay_log_size,
 
283
                                               fix_max_relay_log_size);
 
284
static sys_var_thd_ulong        sys_max_sort_length(&vars, "max_sort_length",
 
285
                                            &SV::max_sort_length);
 
286
static sys_var_max_user_conn   sys_max_user_connections(&vars, "max_user_connections");
 
287
static sys_var_thd_ulong        sys_max_tmp_tables(&vars, "max_tmp_tables",
 
288
                                           &SV::max_tmp_tables);
 
289
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
 
290
                                                 &max_write_lock_count);
 
291
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
292
                                                          &SV::min_examined_row_limit);
 
293
static sys_var_long_ptr sys_myisam_data_pointer_size(&vars, "myisam_data_pointer_size",
 
294
                                                    &myisam_data_pointer_size);
 
295
static sys_var_thd_ulonglong    sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
 
296
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
 
297
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
203
298
 
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);
 
299
static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
300
                                                &SV::myisam_stats_method,
 
301
                                                &myisam_stats_method_typelib,
 
302
                                                NULL);
 
303
static sys_var_thd_ulong        sys_net_buffer_length(&vars, "net_buffer_length",
 
304
                                              &SV::net_buffer_length);
 
305
static sys_var_thd_ulong        sys_net_read_timeout(&vars, "net_read_timeout",
 
306
                                             &SV::net_read_timeout,
 
307
                                             0, fix_net_read_timeout);
 
308
static sys_var_thd_ulong        sys_net_write_timeout(&vars, "net_write_timeout",
 
309
                                              &SV::net_write_timeout,
 
310
                                              0, fix_net_write_timeout);
 
311
static sys_var_thd_ulong        sys_net_retry_count(&vars, "net_retry_count",
 
312
                                            &SV::net_retry_count,
 
313
                                            0, fix_net_retry_count);
 
314
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
 
315
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
 
316
                                       &global_system_variables.old_mode);
219
317
/* these two cannot be static */
220
 
sys_var_session_bool sys_old_alter_table(&vars, "old_alter_table",
221
 
                                         &SV::old_alter_table);
222
 
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
223
 
                                                      &SV::optimizer_prune_level);
224
 
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
225
 
                                                           &SV::optimizer_search_depth);
 
318
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
 
319
                                            &SV::old_alter_table);
 
320
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
321
                                                  &SV::optimizer_prune_level);
 
322
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
323
                                                   &SV::optimizer_search_depth);
226
324
 
227
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
 
325
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
228
326
TYPELIB optimizer_use_mrr_typelib= {
229
327
  array_elements(optimizer_use_mrr_names) - 1, "",
230
328
  optimizer_use_mrr_names, NULL
231
329
};
232
330
 
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);
237
 
 
238
 
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
239
 
                                                      &SV::preload_buff_size);
240
 
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
241
 
                                                   &SV::read_buff_size);
242
 
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
243
 
                                                       &SV::read_rnd_buff_size);
244
 
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
245
 
                                                      &SV::div_precincrement);
246
 
 
247
 
static sys_var_session_size_t   sys_range_alloc_block_size(&vars, "range_alloc_block_size",
248
 
                                                           &SV::range_alloc_block_size);
249
 
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
250
 
                                                           &SV::query_alloc_block_size,
251
 
                                                           false, fix_session_mem_root);
252
 
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
253
 
                                                        &SV::query_prealloc_size,
254
 
                                                        false, fix_session_mem_root);
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);
262
 
 
 
331
static sys_var_thd_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
332
                                              &SV::optimizer_use_mrr,
 
333
                                              &optimizer_use_mrr_typelib,
 
334
                                              NULL);
 
335
 
 
336
static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
 
337
                                              &SV::preload_buff_size);
 
338
static sys_var_thd_ulong        sys_read_buff_size(&vars, "read_buffer_size",
 
339
                                           &SV::read_buff_size);
 
340
static sys_var_opt_readonly     sys_readonly(&vars, "read_only", &opt_readonly);
 
341
static sys_var_thd_ulong        sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 
342
                                               &SV::read_rnd_buff_size);
 
343
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
 
344
                                              &SV::div_precincrement);
 
345
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
 
346
                                              &rpl_recovery_rank);
 
347
 
 
348
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
349
                                                   &SV::range_alloc_block_size);
 
350
static sys_var_thd_ulong        sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
351
                                                   &SV::query_alloc_block_size,
 
352
                                                   0, fix_thd_mem_root);
 
353
static sys_var_thd_ulong        sys_query_prealloc_size(&vars, "query_prealloc_size",
 
354
                                                &SV::query_prealloc_size,
 
355
                                                0, fix_thd_mem_root);
 
356
static sys_var_readonly        sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
357
static sys_var_thd_ulong        sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
358
                                                   &SV::trans_alloc_block_size,
 
359
                                                   0, fix_trans_mem_root);
 
360
static sys_var_thd_ulong        sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
361
                                                &SV::trans_prealloc_size,
 
362
                                                0, fix_trans_mem_root);
 
363
 
 
364
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
263
365
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
264
366
                                             &opt_secure_file_priv);
265
 
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
266
 
                                           fix_server_id);
267
 
 
268
 
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
269
 
                                                &SV::sortbuff_size);
 
367
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
 
368
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
 
369
                                                      &opt_slave_compressed_protocol);
 
370
#ifdef HAVE_REPLICATION
 
371
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
 
372
                                                         &slave_allow_batching);
 
373
static sys_var_set_slave_mode slave_exec_mode(&vars,
 
374
                                              "slave_exec_mode",
 
375
                                              &slave_exec_mode_options,
 
376
                                              &slave_exec_mode_typelib,
 
377
                                              0);
 
378
#endif
 
379
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
 
380
                                             &slow_launch_time);
 
381
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
 
382
                                        &SV::sortbuff_size);
270
383
/*
271
384
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
272
385
  even though it is written to the binlog, the slave ignores the
273
386
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
274
387
  master's (see log_event.cc: Query_log_event::do_apply_event()).
275
388
*/
276
 
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
277
 
                                                               &SV::optimizer_switch);
 
389
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
390
                                     &SV::optimizer_switch);
 
391
static sys_var_const_str        sys_ssl_ca(&vars, "ssl_ca", NULL);
 
392
static sys_var_const_str        sys_ssl_capath(&vars, "ssl_capath", NULL);
 
393
static sys_var_const_str        sys_ssl_cert(&vars, "ssl_cert", NULL);
 
394
static sys_var_const_str        sys_ssl_cipher(&vars, "ssl_cipher", NULL);
 
395
static sys_var_const_str        sys_ssl_key(&vars, "ssl_key", NULL);
278
396
 
279
 
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
280
 
                                       &SV::storage_engine);
 
397
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
 
398
                                       &SV::table_plugin);
 
399
static sys_var_bool_ptr sys_sync_frm(&vars, "sync_frm", &opt_sync_frm);
281
400
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
282
401
                                             system_time_zone);
283
 
static sys_var_uint64_t_ptr     sys_table_def_size(&vars, "table_definition_cache",
 
402
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
284
403
                                           &table_def_size);
285
 
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
 
404
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
286
405
                                             &table_cache_size);
287
 
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
406
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
288
407
                                                    &table_lock_wait_timeout);
289
 
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
290
 
                                             &SV::tx_isolation,
291
 
                                             &tx_isolation_typelib,
292
 
                                             fix_tx_isolation,
293
 
                                             check_tx_isolation);
294
 
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
 
408
static sys_var_long_ptr sys_thread_cache_size(&vars, "thread_cache_size",
 
409
                                              &thread_cache_size);
 
410
sys_var_long_ptr        sys_thread_pool_size(&vars, "thread_pool_size",
 
411
                                              &thread_pool_size);
 
412
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
 
413
                                         &SV::tx_isolation,
 
414
                                         &tx_isolation_typelib,
 
415
                                         fix_tx_isolation,
 
416
                                         check_tx_isolation);
 
417
static sys_var_thd_ulonglong    sys_tmp_table_size(&vars, "tmp_table_size",
295
418
                                           &SV::tmp_table_size);
296
 
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
 
419
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes",
 
420
                                    &timed_mutexes);
297
421
static sys_var_const_str        sys_version(&vars, "version", server_version);
298
422
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
299
 
                                            COMPILATION_COMMENT);
 
423
                                            MYSQL_COMPILATION_COMMENT);
300
424
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
301
425
                                                    MACHINE_TYPE);
302
426
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
303
427
                                               SYSTEM_TYPE);
304
 
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
305
 
                                                     &SV::net_wait_timeout);
 
428
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
 
429
                                             &SV::net_wait_timeout);
306
430
 
307
431
/* Condition pushdown to storage engine */
308
 
static sys_var_session_bool
 
432
static sys_var_thd_bool
309
433
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
310
434
                              &SV::engine_condition_pushdown);
311
435
 
312
 
/* Variables that are bits in Session */
313
 
 
314
 
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
 
436
/* Time/date/datetime formats */
 
437
 
 
438
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
 
439
                                             &SV::time_format,
 
440
                                             MYSQL_TIMESTAMP_TIME);
 
441
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
 
442
                                             &SV::date_format,
 
443
                                             MYSQL_TIMESTAMP_DATE);
 
444
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
 
445
                                                 &SV::datetime_format,
 
446
                                                 MYSQL_TIMESTAMP_DATETIME);
 
447
 
 
448
/* Variables that are bits in THD */
 
449
 
 
450
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
315
451
                               set_option_autocommit,
316
452
                               OPTION_NOT_AUTOCOMMIT,
317
453
                               1);
318
 
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
 
454
static sys_var_thd_bit  sys_big_tables(&vars, "big_tables", 0,
 
455
                                       set_option_bit,
 
456
                                       OPTION_BIG_TABLES);
 
457
#ifndef TO_BE_DELETED   /* Alias for big_tables */
 
458
static sys_var_thd_bit  sys_sql_big_tables(&vars, "sql_big_tables", 0,
 
459
                                           set_option_bit,
 
460
                                           OPTION_BIG_TABLES);
 
461
#endif
 
462
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
319
463
                                        set_option_bit,
320
464
                                        OPTION_BIG_SELECTS);
321
 
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
 
465
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
 
466
                                    check_log_update,
 
467
                                    set_option_bit,
 
468
                                    OPTION_LOG_OFF);
 
469
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
 
470
                                       check_log_update,
 
471
                                       set_log_update,
 
472
                                       OPTION_BIN_LOG);
 
473
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
 
474
                                       check_log_update,
 
475
                                       set_option_bit,
 
476
                                       OPTION_BIN_LOG);
 
477
static sys_var_thd_bit  sys_sql_warnings(&vars, "sql_warnings", 0,
322
478
                                         set_option_bit,
323
479
                                         OPTION_WARNINGS);
324
 
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
 
480
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
325
481
                                         set_option_bit,
326
482
                                         OPTION_SQL_NOTES);
327
 
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
 
483
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
 
484
                                         set_option_bit,
 
485
                                         OPTION_AUTO_IS_NULL, 0,
 
486
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
487
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
328
488
                                         set_option_bit,
329
489
                                         OPTION_SAFE_UPDATES);
330
 
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
 
490
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
331
491
                                           set_option_bit,
332
492
                                           OPTION_BUFFER_RESULT);
333
 
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
493
static sys_var_thd_bit  sys_quote_show_create(&vars, "sql_quote_show_create", 0,
 
494
                                              set_option_bit,
 
495
                                              OPTION_QUOTE_SHOW_CREATE);
 
496
static sys_var_thd_bit  sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
334
497
                                               set_option_bit,
335
498
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
336
499
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
337
 
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
 
500
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
338
501
                                          set_option_bit,
339
502
                                          OPTION_RELAXED_UNIQUE_CHECKS,
340
503
                                          1,
341
504
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
342
505
/* Local state variables */
343
506
 
344
 
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
 
507
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
345
508
                                                 &SV::select_limit);
346
509
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
347
510
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
355
518
static sys_var_last_insert_id
356
519
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
357
520
 
358
 
static sys_var_session_lc_time_names
 
521
static sys_var_thd_lc_time_names
359
522
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
360
523
 
361
524
/*
377
540
  statement-based logging mode: t will be different on master and
378
541
  slave).
379
542
*/
380
 
static sys_var_readonly sys_error_count(&vars, "error_count",
381
 
                                        OPT_SESSION,
382
 
                                        SHOW_INT,
383
 
                                        get_error_count);
384
 
static sys_var_readonly sys_warning_count(&vars, "warning_count",
385
 
                                          OPT_SESSION,
386
 
                                          SHOW_INT,
387
 
                                          get_warning_count);
388
 
 
389
 
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
390
 
                                                  &SV::group_concat_max_len);
391
 
 
392
 
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
 
543
static sys_var_insert_id sys_insert_id(&vars, "insert_id");
 
544
static sys_var_readonly         sys_error_count(&vars, "error_count",
 
545
                                                OPT_SESSION,
 
546
                                                SHOW_LONG,
 
547
                                                get_error_count);
 
548
static sys_var_readonly         sys_warning_count(&vars, "warning_count",
 
549
                                                  OPT_SESSION,
 
550
                                                  SHOW_LONG,
 
551
                                                  get_warning_count);
 
552
 
 
553
static sys_var_rand_seed1 sys_rand_seed1(&vars, "rand_seed1",
 
554
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
555
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
 
556
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
 
557
 
 
558
static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
 
559
                                                        &SV::default_week_format);
 
560
 
 
561
sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
 
562
                                                         &SV::group_concat_max_len);
 
563
 
 
564
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
393
565
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
394
566
 
395
567
/* Global read-only variable containing hostname */
396
568
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
397
569
 
398
 
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create",
 
570
static sys_var_const_str_ptr    sys_repl_report_host(&vars, "report_host", &report_host);
 
571
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
 
572
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
 
573
 
 
574
static uchar *slave_get_report_port(THD *thd)
 
575
{
 
576
  thd->sys_var_tmp.long_value= report_port;
 
577
  return (uchar*) &thd->sys_var_tmp.long_value;
 
578
}
 
579
 
 
580
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
 
581
 
 
582
sys_var_thd_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
399
583
                                           &SV::keep_files_on_create);
400
584
/* Read only variables */
401
585
 
 
586
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
 
587
static sys_var_have_variable sys_have_crypt(&vars, "have_crypt", &have_crypt);
 
588
static sys_var_have_plugin sys_have_csv(&vars, "have_csv", C_STRING_WITH_LEN("csv"), MYSQL_STORAGE_ENGINE_PLUGIN);
 
589
static sys_var_have_variable sys_have_dlopen(&vars, "have_dynamic_loading", &have_dlopen);
 
590
static sys_var_have_plugin sys_have_innodb(&vars, "have_innodb", C_STRING_WITH_LEN("innodb"), MYSQL_STORAGE_ENGINE_PLUGIN);
402
591
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
 
592
/* Global read-only variable describing server license */
 
593
static sys_var_const_str        sys_license(&vars, "license", STRINGIFY_ARG(LICENSE));
 
594
/* Global variables which enable|disable logging */
 
595
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
 
596
                                      QUERY_LOG_GENERAL);
 
597
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
 
598
static sys_var_log_state sys_var_log(&vars, "log", &opt_log,
 
599
                                      QUERY_LOG_GENERAL);
 
600
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
 
601
                                         QUERY_LOG_SLOW);
 
602
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
 
603
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
 
604
                                          &opt_slow_log, QUERY_LOG_SLOW);
 
605
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
 
606
                                     sys_update_general_log_path,
 
607
                                     sys_default_general_log_path,
 
608
                                     opt_logname);
 
609
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
 
610
                                  sys_update_slow_log_path, 
 
611
                                  sys_default_slow_log_path,
 
612
                                  opt_slow_logname);
 
613
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
 
614
                                            &log_output_typelib, 0);
 
615
 
 
616
 
403
617
/*
404
618
  Additional variables (not derived from sys_var class, not accessible as
405
619
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
409
623
 
410
624
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
411
625
static SHOW_VAR fixed_vars[]= {
412
 
  {"back_log",                (char*) &back_log,                    SHOW_INT},
 
626
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
 
627
  {"character_sets_dir",      mysql_charsets_dir,                   SHOW_CHAR},
 
628
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
413
629
  {"language",                language,                             SHOW_CHAR},
414
630
#ifdef HAVE_MLOCKALL
415
631
  {"locked_in_memory",        (char*) &locked_in_memory,            SHOW_MY_BOOL},
416
632
#endif
 
633
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
 
634
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
 
635
  {"lower_case_file_system",  (char*) &lower_case_file_system,      SHOW_MY_BOOL},
 
636
  {"lower_case_table_names",  (char*) &lower_case_table_names,      SHOW_INT},
417
637
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
 
638
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
418
639
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
419
640
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
420
 
  {"port",                    (char*) &drizzled_port,               SHOW_INT},
 
641
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
421
642
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
422
 
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_INT},
 
643
  {"skip_external_locking",   (char*) &my_disable_locking,          SHOW_MY_BOOL},
 
644
  {"skip_networking",         (char*) &opt_disable_networking,      SHOW_BOOL},
 
645
  {"skip_show_database",      (char*) &opt_skip_show_db,            SHOW_BOOL},
 
646
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
423
647
};
424
648
 
425
 
bool sys_var::check(Session *, set_var *var)
 
649
 
 
650
bool sys_var::check(THD *thd __attribute__((__unused__)), set_var *var)
426
651
{
427
 
  var->save_result.uint64_t_value= var->value->val_int();
 
652
  var->save_result.ulonglong_value= var->value->val_int();
428
653
  return 0;
429
654
}
430
655
 
431
 
bool sys_var_str::check(Session *session, set_var *var)
 
656
bool sys_var_str::check(THD *thd, set_var *var)
432
657
{
433
658
  int res;
434
659
  if (!check_func)
435
660
    return 0;
436
661
 
437
 
  if ((res=(*check_func)(session, var)) < 0)
 
662
  if ((res=(*check_func)(thd, var)) < 0)
438
663
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
439
664
             name, var->value->str_value.ptr());
440
665
  return res;
445
670
*/
446
671
 
447
672
 
 
673
/*
 
674
  Update variables 'init_connect, init_slave'.
 
675
 
 
676
  In case of 'DEFAULT' value
 
677
  (for example: 'set GLOBAL init_connect=DEFAULT')
 
678
  'var' parameter is NULL pointer.
 
679
*/
 
680
 
 
681
bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
 
682
                        set_var *var)
 
683
{
 
684
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
 
685
  uint new_length= (var ? var->value->str_value.length() : 0);
 
686
  if (!old_value)
 
687
    old_value= (char*) "";
 
688
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
 
689
    return 1;
 
690
  /*
 
691
    Replace the old value in such a way that the any thread using
 
692
    the value will work.
 
693
  */
 
694
  rw_wrlock(var_mutex);
 
695
  old_value= var_str->value;
 
696
  var_str->value= res;
 
697
  var_str->value_length= new_length;
 
698
  rw_unlock(var_mutex);
 
699
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
700
  return 0;
 
701
}
 
702
 
 
703
 
 
704
static bool sys_update_init_connect(THD *thd __attribute__((__unused__)), set_var *var)
 
705
{
 
706
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
 
707
}
 
708
 
 
709
 
 
710
static void sys_default_init_connect(THD* thd __attribute__((__unused__)),
 
711
                                     enum_var_type type __attribute__((__unused__)))
 
712
{
 
713
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
 
714
}
 
715
 
 
716
 
 
717
static bool sys_update_init_slave(THD *thd __attribute__((__unused__)),
 
718
                                  set_var *var)
 
719
{
 
720
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
 
721
}
 
722
 
 
723
 
 
724
static void sys_default_init_slave(THD* thd __attribute__((__unused__)),
 
725
                                   enum_var_type type __attribute__((__unused__)))
 
726
{
 
727
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
 
728
}
 
729
 
 
730
 
 
731
/**
 
732
  If one sets the LOW_PRIORIY UPDATES flag, we also must change the
 
733
  used lock type.
 
734
*/
 
735
 
 
736
static void fix_low_priority_updates(THD *thd, enum_var_type type)
 
737
{
 
738
  if (type == OPT_GLOBAL)
 
739
    thr_upgraded_concurrent_insert_lock= 
 
740
      (global_system_variables.low_priority_updates ?
 
741
       TL_WRITE_LOW_PRIORITY : TL_WRITE);
 
742
  else
 
743
    thd->update_lock_default= (thd->variables.low_priority_updates ?
 
744
                               TL_WRITE_LOW_PRIORITY : TL_WRITE);
 
745
}
 
746
 
 
747
 
 
748
static void
 
749
fix_myisam_max_sort_file_size(THD *thd __attribute__((__unused__)),
 
750
                              enum_var_type type __attribute__((__unused__)))
 
751
{
 
752
  myisam_max_temp_length=
 
753
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
 
754
}
 
755
 
448
756
/**
449
757
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
450
758
*/
451
759
 
452
 
static void fix_max_join_size(Session *session, enum_var_type type)
 
760
static void fix_max_join_size(THD *thd, enum_var_type type)
453
761
{
454
762
  if (type != OPT_GLOBAL)
455
763
  {
456
 
    if (session->variables.max_join_size == HA_POS_ERROR)
457
 
      session->options|= OPTION_BIG_SELECTS;
 
764
    if (thd->variables.max_join_size == HA_POS_ERROR)
 
765
      thd->options|= OPTION_BIG_SELECTS;
458
766
    else
459
 
      session->options&= ~OPTION_BIG_SELECTS;
 
767
      thd->options&= ~OPTION_BIG_SELECTS;
460
768
  }
461
769
}
462
770
 
465
773
  Can't change the 'next' tx_isolation while we are already in
466
774
  a transaction
467
775
*/
468
 
static int check_tx_isolation(Session *session, set_var *var)
 
776
static int check_tx_isolation(THD *thd, set_var *var)
469
777
{
470
 
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
 
778
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
471
779
  {
472
780
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
473
781
    return 1;
479
787
  If one doesn't use the SESSION modifier, the isolation level
480
788
  is only active for the next command.
481
789
*/
482
 
static void fix_tx_isolation(Session *session, enum_var_type type)
 
790
static void fix_tx_isolation(THD *thd, enum_var_type type)
483
791
{
484
792
  if (type == OPT_SESSION)
485
 
    session->session_tx_isolation= ((enum_tx_isolation)
486
 
                                    session->variables.tx_isolation);
 
793
    thd->session_tx_isolation= ((enum_tx_isolation)
 
794
                                thd->variables.tx_isolation);
487
795
}
488
796
 
489
 
static void fix_completion_type(Session *, enum_var_type) {}
 
797
static void fix_completion_type(THD *thd __attribute__((unused)),
 
798
                                enum_var_type type __attribute__((unused))) {}
490
799
 
491
 
static int check_completion_type(Session *, set_var *var)
 
800
static int check_completion_type(THD *thd __attribute__((__unused__)),
 
801
                                 set_var *var)
492
802
{
493
 
  int64_t val= var->value->val_int();
 
803
  longlong val= var->value->val_int();
494
804
  if (val < 0 || val > 2)
495
805
  {
496
806
    char buf[64];
502
812
 
503
813
 
504
814
/*
505
 
  If we are changing the thread variable, we have to copy it to Protocol too
 
815
  If we are changing the thread variable, we have to copy it to NET too
506
816
*/
507
817
 
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)
 
818
#ifdef HAVE_REPLICATION
 
819
static void fix_net_read_timeout(THD *thd, enum_var_type type)
 
820
{
 
821
  if (type != OPT_GLOBAL)
 
822
    my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
 
823
}
 
824
 
 
825
 
 
826
static void fix_net_write_timeout(THD *thd, enum_var_type type)
 
827
{
 
828
  if (type != OPT_GLOBAL)
 
829
    my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
 
830
}
 
831
 
 
832
static void fix_net_retry_count(THD *thd, enum_var_type type)
 
833
{
 
834
  if (type != OPT_GLOBAL)
 
835
    thd->net.retry_count=thd->variables.net_retry_count;
 
836
}
 
837
#else /* HAVE_REPLICATION */
 
838
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
 
839
                                 enum_var_type type __attribute__((unused)))
 
840
{}
 
841
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
 
842
                                  enum_var_type type __attribute__((unused)))
 
843
{}
 
844
static void fix_net_retry_count(THD *thd __attribute__((unused)),
 
845
                                enum_var_type type __attribute__((unused)))
 
846
{}
 
847
#endif /* HAVE_REPLICATION */
 
848
 
 
849
 
 
850
extern void fix_delay_key_write(THD *thd __attribute__((__unused__)),
 
851
                                enum_var_type type __attribute__((__unused__)))
529
852
{
530
853
  switch ((enum_delay_key_write) delay_key_write_options) {
531
854
  case DELAY_KEY_WRITE_NONE:
541
864
  }
542
865
}
543
866
 
544
 
 
545
 
static void fix_session_mem_root(Session *session, enum_var_type type)
546
 
{
547
 
  if (type != OPT_GLOBAL)
548
 
    reset_root_defaults(session->mem_root,
549
 
                        session->variables.query_alloc_block_size,
550
 
                        session->variables.query_prealloc_size);
551
 
}
552
 
 
553
 
 
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)
564
 
{
565
 
}
566
 
 
567
 
 
568
 
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
569
 
                          const char *name, int64_t val)
 
867
bool sys_var_set::update(THD *thd __attribute__((__unused__)),
 
868
                         set_var *var)
 
869
{
 
870
  *value= var->save_result.ulong_value;
 
871
  return 0;
 
872
}
 
873
 
 
874
uchar *sys_var_set::value_ptr(THD *thd,
 
875
                              enum_var_type type __attribute__((__unused__)),
 
876
                              LEX_STRING *base __attribute__((__unused__)))
 
877
{
 
878
  char buff[256];
 
879
  String tmp(buff, sizeof(buff), &my_charset_latin1);
 
880
  ulong length;
 
881
  ulong val= *value;
 
882
 
 
883
  tmp.length(0);
 
884
  for (uint i= 0; val; val>>= 1, i++)
 
885
  {
 
886
    if (val & 1)
 
887
    {
 
888
      tmp.append(enum_names->type_names[i],
 
889
                 enum_names->type_lengths[i]);
 
890
      tmp.append(',');
 
891
    }
 
892
  }
 
893
 
 
894
  if ((length= tmp.length()))
 
895
    length--;
 
896
  return (uchar*) thd->strmake(tmp.ptr(), length);
 
897
}
 
898
 
 
899
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((__unused__)),
 
900
                                         enum_var_type type __attribute__((__unused__)))
 
901
{
 
902
  slave_exec_mode_options= 0;
 
903
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
 
904
}
 
905
 
 
906
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
 
907
{
 
908
  bool rc=  sys_var_set::check(thd, var);
 
909
  if (!rc &&
 
910
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
 
911
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
 
912
  {
 
913
    rc= true;
 
914
    my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
 
915
  }
 
916
  return rc;
 
917
}
 
918
 
 
919
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
 
920
{
 
921
  bool rc;
 
922
  pthread_mutex_lock(&LOCK_global_system_variables);
 
923
  rc= sys_var_set::update(thd, var);
 
924
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
925
  return rc;
 
926
}
 
927
 
 
928
void fix_slave_exec_mode(enum_var_type type __attribute__((__unused__)))
 
929
{
 
930
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
 
931
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
 
932
  {
 
933
    sql_print_error("Ambiguous slave modes combination."
 
934
                    " STRICT will be used");
 
935
    bit_do_clear(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT);
 
936
  }
 
937
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 0)
 
938
    bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
 
939
}
 
940
 
 
941
bool sys_var_thd_binlog_format::is_readonly() const
 
942
{
 
943
  /*
 
944
    Under certain circumstances, the variable is read-only (unchangeable):
 
945
  */
 
946
  THD *thd= current_thd;
 
947
  /*
 
948
    If RBR and open temporary tables, their CREATE TABLE may not be in the
 
949
    binlog, so we can't toggle to SBR in this connection.
 
950
    The test below will also prevent SET GLOBAL, well it was not easy to test
 
951
    if global or not here.
 
952
    And this test will also prevent switching from RBR to RBR (a no-op which
 
953
    should not happen too often).
 
954
 
 
955
    If we don't have row-based replication compiled in, the variable
 
956
    is always read-only.
 
957
  */
 
958
  if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
 
959
      thd->temporary_tables)
 
960
  {
 
961
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
 
962
    return 1;
 
963
  }
 
964
  /*
 
965
    if in a stored function/trigger, it's too late to change mode
 
966
  */
 
967
  if (thd->in_sub_stmt)
 
968
  {
 
969
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
 
970
    return 1;    
 
971
  }
 
972
  return sys_var_thd_enum::is_readonly();
 
973
}
 
974
 
 
975
 
 
976
void fix_binlog_format_after_update(THD *thd,
 
977
                                    enum_var_type type __attribute__((__unused__)))
 
978
{
 
979
  thd->reset_current_stmt_binlog_row_based();
 
980
}
 
981
 
 
982
 
 
983
static void fix_max_binlog_size(THD *thd __attribute__((__unused__)),
 
984
                                enum_var_type type __attribute__((__unused__)))
 
985
{
 
986
  mysql_bin_log.set_max_size(max_binlog_size);
 
987
#ifdef HAVE_REPLICATION
 
988
  if (!max_relay_log_size)
 
989
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
 
990
#endif
 
991
  return;
 
992
}
 
993
 
 
994
static void fix_max_relay_log_size(THD *thd __attribute__((__unused__)),
 
995
                                   enum_var_type type __attribute__((__unused__)))
 
996
{
 
997
#ifdef HAVE_REPLICATION
 
998
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
 
999
                                        max_relay_log_size: max_binlog_size);
 
1000
#endif
 
1001
  return;
 
1002
}
 
1003
 
 
1004
static void fix_max_connections(THD *thd __attribute__((__unused__)),
 
1005
                                enum_var_type type __attribute__((__unused__)))
 
1006
{
 
1007
  resize_thr_alarm(max_connections +  10);
 
1008
}
 
1009
 
 
1010
 
 
1011
static void fix_thd_mem_root(THD *thd, enum_var_type type)
 
1012
{
 
1013
  if (type != OPT_GLOBAL)
 
1014
    reset_root_defaults(thd->mem_root,
 
1015
                        thd->variables.query_alloc_block_size,
 
1016
                        thd->variables.query_prealloc_size);
 
1017
}
 
1018
 
 
1019
 
 
1020
static void fix_trans_mem_root(THD *thd, enum_var_type type)
 
1021
{
 
1022
  if (type != OPT_GLOBAL)
 
1023
    reset_root_defaults(&thd->transaction.mem_root,
 
1024
                        thd->variables.trans_alloc_block_size,
 
1025
                        thd->variables.trans_prealloc_size);
 
1026
}
 
1027
 
 
1028
 
 
1029
static void fix_server_id(THD *thd __attribute__((__unused__)),
 
1030
                          enum_var_type type __attribute__((__unused__)))
 
1031
{
 
1032
  server_id_supplied = 1;
 
1033
  thd->server_id= server_id;
 
1034
}
 
1035
 
 
1036
 
 
1037
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
1038
                          const char *name, longlong val)
570
1039
{
571
1040
  if (fixed)
572
1041
  {
573
1042
    char buf[22];
574
1043
 
575
1044
    if (unsignd)
576
 
      ullstr((uint64_t) val, buf);
 
1045
      ullstr((ulonglong) val, buf);
577
1046
    else
578
1047
      llstr(val, buf);
579
1048
 
580
 
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
 
1049
    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
581
1050
                        ER_TRUNCATED_WRONG_VALUE,
582
1051
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
583
1052
  }
584
1053
  return false;
585
1054
}
586
1055
 
587
 
static uint64_t fix_unsigned(Session *session, uint64_t num,
 
1056
static ulonglong fix_unsigned(THD *thd, ulonglong num,
588
1057
                              const struct my_option *option_limits)
589
1058
{
590
 
  bool fixed= false;
591
 
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
592
 
 
593
 
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
594
 
  return out;
595
 
}
596
 
 
597
 
 
598
 
static size_t fix_size_t(Session *session, size_t num,
599
 
                           const struct my_option *option_limits)
600
 
{
601
 
  bool fixed= false;
602
 
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
603
 
 
604
 
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
605
 
  return out;
606
 
}
607
 
 
608
 
static bool get_unsigned32(Session *, set_var *var)
609
 
{
610
 
  if (var->value->unsigned_flag)
611
 
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
612
 
  else
613
 
  {
614
 
    int64_t v= var->value->val_int();
615
 
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
616
 
  }
617
 
  return 0;
618
 
}
619
 
 
620
 
static bool get_unsigned64(Session *, set_var *var)
621
 
{
622
 
  if (var->value->unsigned_flag)
623
 
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
624
 
  else
625
 
  {
626
 
    int64_t v= var->value->val_int();
627
 
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
628
 
  }
629
 
  return 0;
630
 
}
631
 
 
632
 
static bool get_size_t(Session *, set_var *var)
633
 
{
634
 
  if (var->value->unsigned_flag)
635
 
    var->save_result.size_t_value= (size_t) var->value->val_int();
636
 
  else
637
 
  {
638
 
    ssize_t v= (ssize_t)var->value->val_int();
639
 
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
640
 
  }
641
 
  return 0;
642
 
}
643
 
 
644
 
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
645
 
{
646
 
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
647
 
  return 0;
648
 
}
649
 
 
650
 
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
651
 
{
652
 
  uint32_t tmp= var->save_result.uint32_t_value;
653
 
  pthread_mutex_lock(&LOCK_global_system_variables);
654
 
  if (option_limits)
655
 
  {
656
 
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
657
 
    if(newvalue==tmp)
658
 
      *value= newvalue;
659
 
  }
660
 
  else
661
 
    *value= (uint32_t) tmp;
662
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
663
 
  return 0;
664
 
}
665
 
 
666
 
 
667
 
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
668
 
{
669
 
  bool not_used;
670
 
  pthread_mutex_lock(&LOCK_global_system_variables);
671
 
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
672
 
                                           option_limits, &not_used);
673
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
674
 
}
675
 
 
676
 
 
677
 
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
678
 
{
679
 
  uint64_t tmp= var->save_result.uint64_t_value;
680
 
  pthread_mutex_lock(&LOCK_global_system_variables);
681
 
  if (option_limits)
682
 
  {
683
 
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
684
 
    if(newvalue==tmp)
685
 
      *value= newvalue;
686
 
  }
687
 
  else
688
 
    *value= (uint64_t) tmp;
689
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
690
 
  return 0;
691
 
}
692
 
 
693
 
 
694
 
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
695
 
{
696
 
  bool not_used;
697
 
  pthread_mutex_lock(&LOCK_global_system_variables);
698
 
  *value= getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1059
  my_bool fixed= false;
 
1060
  ulonglong out= getopt_ull_limit_value(num, option_limits, &fixed);
 
1061
 
 
1062
  throw_bounds_warning(thd, fixed, true, option_limits->name, (longlong) num);
 
1063
  return out;
 
1064
}
 
1065
 
 
1066
static bool get_unsigned(THD *thd __attribute__((__unused__)), set_var *var)
 
1067
{
 
1068
  if (var->value->unsigned_flag)
 
1069
    var->save_result.ulonglong_value= (ulonglong) var->value->val_int();
 
1070
  else
 
1071
  {
 
1072
    longlong v= var->value->val_int();
 
1073
    var->save_result.ulonglong_value= (ulonglong) ((v < 0) ? 0 : v);
 
1074
  }
 
1075
  return 0;
 
1076
}
 
1077
 
 
1078
 
 
1079
sys_var_long_ptr::
 
1080
sys_var_long_ptr(sys_var_chain *chain, const char *name_arg, ulong *value_ptr_arg,
 
1081
                 sys_after_update_func after_update_arg)
 
1082
  :sys_var_long_ptr_global(chain, name_arg, value_ptr_arg,
 
1083
                           &LOCK_global_system_variables, after_update_arg)
 
1084
{}
 
1085
 
 
1086
 
 
1087
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
 
1088
{
 
1089
  return get_unsigned(thd, var);
 
1090
}
 
1091
 
 
1092
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
 
1093
{
 
1094
  ulonglong tmp= var->save_result.ulonglong_value;
 
1095
  pthread_mutex_lock(guard);
 
1096
  if (option_limits)
 
1097
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
 
1098
  else
 
1099
  {
 
1100
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1101
    /* Avoid overflows on 32 bit systems */
 
1102
    if (tmp > ULONG_MAX)
 
1103
    {
 
1104
      tmp= ULONG_MAX;
 
1105
      throw_bounds_warning(thd, true, true, name,
 
1106
                           (longlong) var->save_result.ulonglong_value);
 
1107
    }
 
1108
#endif
 
1109
    *value= (ulong) tmp;
 
1110
  }
 
1111
 
 
1112
  pthread_mutex_unlock(guard);
 
1113
  return 0;
 
1114
}
 
1115
 
 
1116
 
 
1117
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
 
1118
{
 
1119
  my_bool not_used;
 
1120
  pthread_mutex_lock(guard);
 
1121
  *value= (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
 
1122
                                         option_limits, &not_used);
 
1123
  pthread_mutex_unlock(guard);
 
1124
}
 
1125
 
 
1126
 
 
1127
bool sys_var_ulonglong_ptr::update(THD *thd, set_var *var)
 
1128
{
 
1129
  ulonglong tmp= var->save_result.ulonglong_value;
 
1130
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1131
  if (option_limits)
 
1132
    *value= (ulonglong) fix_unsigned(thd, tmp, option_limits);
 
1133
  else
 
1134
    *value= (ulonglong) tmp;
 
1135
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
1136
  return 0;
 
1137
}
 
1138
 
 
1139
 
 
1140
void sys_var_ulonglong_ptr::set_default(THD *thd __attribute__((__unused__)),
 
1141
                                        enum_var_type type __attribute__((__unused__)))
 
1142
{
 
1143
  my_bool not_used;
 
1144
  pthread_mutex_lock(&LOCK_global_system_variables);
 
1145
  *value= getopt_ull_limit_value((ulonglong) option_limits->def_value,
699
1146
                                 option_limits, &not_used);
700
1147
  pthread_mutex_unlock(&LOCK_global_system_variables);
701
1148
}
702
1149
 
703
1150
 
704
 
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
705
 
{
706
 
  size_t tmp= var->save_result.size_t_value;
707
 
  pthread_mutex_lock(&LOCK_global_system_variables);
708
 
  if (option_limits)
709
 
    *value= fix_size_t(session, tmp, option_limits);
710
 
  else
711
 
    *value= tmp;
712
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
713
 
  return 0;
714
 
}
715
 
 
716
 
 
717
 
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
718
 
{
719
 
  bool not_used;
720
 
  pthread_mutex_lock(&LOCK_global_system_variables);
721
 
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
722
 
                                         option_limits, &not_used);
723
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
724
 
}
725
 
 
726
 
bool sys_var_bool_ptr::update(Session *, set_var *var)
727
 
{
728
 
  *value= (bool) var->save_result.uint32_t_value;
729
 
  return 0;
730
 
}
731
 
 
732
 
 
733
 
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
734
 
{
735
 
  *value= (bool) option_limits->def_value;
736
 
}
737
 
 
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
 
 
758
 
/*
759
 
  32 bit types for session variables
760
 
*/
761
 
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
762
 
{
763
 
  return (get_unsigned32(session, var) ||
764
 
          (check_func && (*check_func)(session, var)));
765
 
}
766
 
 
767
 
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
768
 
{
769
 
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
770
 
 
 
1151
bool sys_var_bool_ptr::update(THD *thd __attribute__((__unused__)), set_var *var)
 
1152
{
 
1153
  *value= (my_bool) var->save_result.ulong_value;
 
1154
  return 0;
 
1155
}
 
1156
 
 
1157
 
 
1158
void sys_var_bool_ptr::set_default(THD *thd __attribute__((__unused__)), enum_var_type type __attribute__((__unused__)))
 
1159
{
 
1160
  *value= (my_bool) option_limits->def_value;
 
1161
}
 
1162
 
 
1163
 
 
1164
bool sys_var_enum::update(THD *thd __attribute__((__unused__)), set_var *var)
 
1165
{
 
1166
  *value= (uint) var->save_result.ulong_value;
 
1167
  return 0;
 
1168
}
 
1169
 
 
1170
 
 
1171
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((__unused__)),
 
1172
                               enum_var_type type __attribute__((__unused__)),
 
1173
                               LEX_STRING *base __attribute__((__unused__)))
 
1174
{
 
1175
  return (uchar*) enum_names->type_names[*value];
 
1176
}
 
1177
 
 
1178
 
 
1179
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((__unused__)),
 
1180
                                     enum_var_type type __attribute__((__unused__)),
 
1181
                                     LEX_STRING *base __attribute__((__unused__)))
 
1182
{
 
1183
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
 
1184
}
 
1185
 
 
1186
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
 
1187
{
 
1188
  return (get_unsigned(thd, var) ||
 
1189
          (check_func && (*check_func)(thd, var)));
 
1190
}
 
1191
 
 
1192
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
 
1193
{
 
1194
  ulonglong tmp= var->save_result.ulonglong_value;
 
1195
  
771
1196
  /* Don't use bigger value than given with --maximum-variable-name=.. */
772
 
  if ((uint32_t) tmp > max_system_variables.*offset)
 
1197
  if ((ulong) tmp > max_system_variables.*offset)
773
1198
  {
774
 
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
 
1199
    throw_bounds_warning(thd, true, true, name, (longlong) tmp);
775
1200
    tmp= max_system_variables.*offset;
776
1201
  }
777
 
 
 
1202
  
778
1203
  if (option_limits)
779
 
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
780
 
  else if (tmp > UINT32_MAX)
 
1204
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
 
1205
#if SIZEOF_LONG < SIZEOF_LONG_LONG
 
1206
  else if (tmp > ULONG_MAX)
781
1207
  {
782
 
    tmp= UINT32_MAX;
783
 
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1208
    tmp= ULONG_MAX;
 
1209
    throw_bounds_warning(thd, true, true, name, (longlong) var->save_result.ulonglong_value);
784
1210
  }
785
 
 
 
1211
#endif
 
1212
  
786
1213
  if (var->type == OPT_GLOBAL)
787
 
     global_system_variables.*offset= (uint32_t) tmp;
 
1214
     global_system_variables.*offset= (ulong) tmp;
788
1215
   else
789
 
     session->variables.*offset= (uint32_t) tmp;
 
1216
     thd->variables.*offset= (ulong) tmp;
790
1217
 
791
1218
   return 0;
792
1219
 }
793
1220
 
794
1221
 
795
 
 void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
 
1222
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
796
1223
 {
797
1224
   if (type == OPT_GLOBAL)
798
1225
   {
799
 
     bool not_used;
 
1226
     my_bool not_used;
800
1227
     /* We will not come here if option_limits is not set */
801
1228
     global_system_variables.*offset=
802
 
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
 
1229
       (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
803
1230
                                      option_limits, &not_used);
804
1231
   }
805
1232
   else
806
 
     session->variables.*offset= global_system_variables.*offset;
 
1233
     thd->variables.*offset= global_system_variables.*offset;
807
1234
 }
808
1235
 
809
1236
 
810
 
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
811
 
                                                enum_var_type type,
812
 
                                                const LEX_STRING *)
 
1237
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1238
                                    LEX_STRING *base __attribute__((__unused__)))
813
1239
{
814
1240
  if (type == OPT_GLOBAL)
815
 
    return (unsigned char*) &(global_system_variables.*offset);
816
 
  return (unsigned char*) &(session->variables.*offset);
 
1241
    return (uchar*) &(global_system_variables.*offset);
 
1242
  return (uchar*) &(thd->variables.*offset);
817
1243
}
818
1244
 
819
1245
 
820
 
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
 
1246
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
821
1247
{
822
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1248
  ulonglong tmp= var->save_result.ulonglong_value;
823
1249
 
824
1250
  /* Don't use bigger value than given with --maximum-variable-name=.. */
825
1251
  if ((ha_rows) tmp > max_system_variables.*offset)
826
1252
    tmp= max_system_variables.*offset;
827
1253
 
828
1254
  if (option_limits)
829
 
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
 
1255
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
830
1256
  if (var->type == OPT_GLOBAL)
831
1257
  {
832
1258
    /* Lock is needed to make things safe on 32 bit systems */
833
 
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1259
    pthread_mutex_lock(&LOCK_global_system_variables);    
834
1260
    global_system_variables.*offset= (ha_rows) tmp;
835
1261
    pthread_mutex_unlock(&LOCK_global_system_variables);
836
1262
  }
837
1263
  else
838
 
    session->variables.*offset= (ha_rows) tmp;
 
1264
    thd->variables.*offset= (ha_rows) tmp;
839
1265
  return 0;
840
1266
}
841
1267
 
842
1268
 
843
 
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
 
1269
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
844
1270
{
845
1271
  if (type == OPT_GLOBAL)
846
1272
  {
847
 
    bool not_used;
 
1273
    my_bool not_used;
848
1274
    /* We will not come here if option_limits is not set */
849
1275
    pthread_mutex_lock(&LOCK_global_system_variables);
850
1276
    global_system_variables.*offset=
853
1279
    pthread_mutex_unlock(&LOCK_global_system_variables);
854
1280
  }
855
1281
  else
856
 
    session->variables.*offset= global_system_variables.*offset;
 
1282
    thd->variables.*offset= global_system_variables.*offset;
857
1283
}
858
1284
 
859
1285
 
860
 
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
861
 
                                                  enum_var_type type,
862
 
                                                  const LEX_STRING *)
 
1286
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1287
                                      LEX_STRING *base __attribute__((__unused__)))
863
1288
{
864
1289
  if (type == OPT_GLOBAL)
865
 
    return (unsigned char*) &(global_system_variables.*offset);
866
 
  return (unsigned char*) &(session->variables.*offset);
867
 
}
868
 
 
869
 
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
870
 
{
871
 
  return (get_unsigned64(session, var) ||
872
 
          (check_func && (*check_func)(session, var)));
873
 
}
874
 
 
875
 
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
876
 
{
877
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1290
    return (uchar*) &(global_system_variables.*offset);
 
1291
  return (uchar*) &(thd->variables.*offset);
 
1292
}
 
1293
 
 
1294
bool sys_var_thd_ulonglong::check(THD *thd, set_var *var)
 
1295
{
 
1296
  return get_unsigned(thd, var);
 
1297
}
 
1298
 
 
1299
bool sys_var_thd_ulonglong::update(THD *thd,  set_var *var)
 
1300
{
 
1301
  ulonglong tmp= var->save_result.ulonglong_value;
878
1302
 
879
1303
  if (tmp > max_system_variables.*offset)
880
1304
    tmp= max_system_variables.*offset;
881
1305
 
882
1306
  if (option_limits)
883
 
    tmp= fix_unsigned(session, tmp, option_limits);
 
1307
    tmp= fix_unsigned(thd, tmp, option_limits);
884
1308
  if (var->type == OPT_GLOBAL)
885
1309
  {
886
1310
    /* Lock is needed to make things safe on 32 bit systems */
887
1311
    pthread_mutex_lock(&LOCK_global_system_variables);
888
 
    global_system_variables.*offset= (uint64_t) tmp;
 
1312
    global_system_variables.*offset= (ulonglong) tmp;
889
1313
    pthread_mutex_unlock(&LOCK_global_system_variables);
890
1314
  }
891
1315
  else
892
 
    session->variables.*offset= (uint64_t) tmp;
 
1316
    thd->variables.*offset= (ulonglong) tmp;
893
1317
  return 0;
894
1318
}
895
1319
 
896
1320
 
897
 
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
 
1321
void sys_var_thd_ulonglong::set_default(THD *thd, enum_var_type type)
898
1322
{
899
1323
  if (type == OPT_GLOBAL)
900
1324
  {
901
 
    bool not_used;
 
1325
    my_bool not_used;
902
1326
    pthread_mutex_lock(&LOCK_global_system_variables);
903
1327
    global_system_variables.*offset=
904
 
      getopt_ull_limit_value((uint64_t) option_limits->def_value,
 
1328
      getopt_ull_limit_value((ulonglong) option_limits->def_value,
905
1329
                             option_limits, &not_used);
906
1330
    pthread_mutex_unlock(&LOCK_global_system_variables);
907
1331
  }
908
1332
  else
909
 
    session->variables.*offset= global_system_variables.*offset;
910
 
}
911
 
 
912
 
 
913
 
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
914
 
                                                   enum_var_type type,
915
 
                                                   const LEX_STRING *)
916
 
{
917
 
  if (type == OPT_GLOBAL)
918
 
    return (unsigned char*) &(global_system_variables.*offset);
919
 
  return (unsigned char*) &(session->variables.*offset);
920
 
}
921
 
 
922
 
bool sys_var_session_size_t::check(Session *session, set_var *var)
923
 
{
924
 
  return (get_size_t(session, var) ||
925
 
          (check_func && (*check_func)(session, var)));
926
 
}
927
 
 
928
 
bool sys_var_session_size_t::update(Session *session,  set_var *var)
929
 
{
930
 
  size_t tmp= var->save_result.size_t_value;
931
 
 
932
 
  if (tmp > max_system_variables.*offset)
933
 
    tmp= max_system_variables.*offset;
934
 
 
935
 
  if (option_limits)
936
 
    tmp= fix_size_t(session, tmp, option_limits);
937
 
  if (var->type == OPT_GLOBAL)
938
 
  {
939
 
    /* Lock is needed to make things safe on 32 bit systems */
940
 
    pthread_mutex_lock(&LOCK_global_system_variables);
941
 
    global_system_variables.*offset= tmp;
942
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
943
 
  }
944
 
  else
945
 
    session->variables.*offset= tmp;
946
 
  return 0;
947
 
}
948
 
 
949
 
 
950
 
void sys_var_session_size_t::set_default(Session *session, enum_var_type type)
951
 
{
952
 
  if (type == OPT_GLOBAL)
953
 
  {
954
 
    bool not_used;
955
 
    pthread_mutex_lock(&LOCK_global_system_variables);
956
 
    global_system_variables.*offset=
957
 
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
958
 
                                     option_limits, &not_used);
959
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
960
 
  }
961
 
  else
962
 
    session->variables.*offset= global_system_variables.*offset;
963
 
}
964
 
 
965
 
 
966
 
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
967
 
                                                 enum_var_type type,
968
 
                                                 const LEX_STRING *)
969
 
{
970
 
  if (type == OPT_GLOBAL)
971
 
    return (unsigned char*) &(global_system_variables.*offset);
972
 
  return (unsigned char*) &(session->variables.*offset);
973
 
}
974
 
 
975
 
 
976
 
bool sys_var_session_bool::update(Session *session,  set_var *var)
977
 
{
978
 
  if (var->type == OPT_GLOBAL)
979
 
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
980
 
  else
981
 
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
982
 
  return 0;
983
 
}
984
 
 
985
 
 
986
 
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
987
 
{
988
 
  if (type == OPT_GLOBAL)
989
 
    global_system_variables.*offset= (bool) option_limits->def_value;
990
 
  else
991
 
    session->variables.*offset= global_system_variables.*offset;
992
 
}
993
 
 
994
 
 
995
 
unsigned char *sys_var_session_bool::value_ptr(Session *session,
996
 
                                               enum_var_type type,
997
 
                                               const LEX_STRING *)
998
 
{
999
 
  if (type == OPT_GLOBAL)
1000
 
    return (unsigned char*) &(global_system_variables.*offset);
1001
 
  return (unsigned char*) &(session->variables.*offset);
1002
 
}
1003
 
 
1004
 
 
1005
 
bool sys_var::check_enum(Session *,
 
1333
    thd->variables.*offset= global_system_variables.*offset;
 
1334
}
 
1335
 
 
1336
 
 
1337
uchar *sys_var_thd_ulonglong::value_ptr(THD *thd, enum_var_type type,
 
1338
                                        LEX_STRING *base __attribute__((__unused__)))
 
1339
{
 
1340
  if (type == OPT_GLOBAL)
 
1341
    return (uchar*) &(global_system_variables.*offset);
 
1342
  return (uchar*) &(thd->variables.*offset);
 
1343
}
 
1344
 
 
1345
 
 
1346
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
 
1347
{
 
1348
  if (var->type == OPT_GLOBAL)
 
1349
    global_system_variables.*offset= (my_bool) var->save_result.ulong_value;
 
1350
  else
 
1351
    thd->variables.*offset= (my_bool) var->save_result.ulong_value;
 
1352
  return 0;
 
1353
}
 
1354
 
 
1355
 
 
1356
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
 
1357
{
 
1358
  if (type == OPT_GLOBAL)
 
1359
    global_system_variables.*offset= (my_bool) option_limits->def_value;
 
1360
  else
 
1361
    thd->variables.*offset= global_system_variables.*offset;
 
1362
}
 
1363
 
 
1364
 
 
1365
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1366
                                   LEX_STRING *base __attribute__((__unused__)))
 
1367
{
 
1368
  if (type == OPT_GLOBAL)
 
1369
    return (uchar*) &(global_system_variables.*offset);
 
1370
  return (uchar*) &(thd->variables.*offset);
 
1371
}
 
1372
 
 
1373
 
 
1374
bool sys_var::check_enum(THD *thd __attribute__((__unused__)),
1006
1375
                         set_var *var, const TYPELIB *enum_names)
1007
1376
{
1008
1377
  char buff[STRING_BUFFER_USUAL_SIZE];
1012
1381
  if (var->value->result_type() == STRING_RESULT)
1013
1382
  {
1014
1383
    if (!(res=var->value->val_str(&str)) ||
1015
 
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
1016
 
                                                    res->length(),1)) == 0)
 
1384
        ((long) (var->save_result.ulong_value=
 
1385
                 (ulong) find_type(enum_names, res->ptr(),
 
1386
                                   res->length(),1)-1)) < 0)
1017
1387
    {
1018
1388
      value= res ? res->c_ptr() : "NULL";
1019
1389
      goto err;
1020
1390
    }
1021
 
 
1022
 
    var->save_result.uint32_t_value--;
1023
1391
  }
1024
1392
  else
1025
1393
  {
1026
 
    uint64_t tmp=var->value->val_int();
 
1394
    ulonglong tmp=var->value->val_int();
1027
1395
    if (tmp >= enum_names->count)
1028
1396
    {
1029
1397
      llstr(tmp,buff);
1030
1398
      value=buff;                               // Wrong value is here
1031
1399
      goto err;
1032
1400
    }
1033
 
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
 
1401
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
1034
1402
  }
1035
1403
  return 0;
1036
1404
 
1040
1408
}
1041
1409
 
1042
1410
 
1043
 
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
 
1411
bool sys_var::check_set(THD *thd __attribute__((__unused__)),
 
1412
                        set_var *var, TYPELIB *enum_names)
1044
1413
{
1045
1414
  bool not_used;
1046
1415
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1047
 
  uint32_t error_len= 0;
 
1416
  uint error_len= 0;
1048
1417
  String str(buff, sizeof(buff), system_charset_info), *res;
1049
1418
 
1050
1419
  if (var->value->result_type() == STRING_RESULT)
1051
1420
  {
1052
1421
    if (!(res= var->value->val_str(&str)))
1053
1422
    {
1054
 
      strcpy(buff, "NULL");
 
1423
      strmov(buff, "NULL");
1055
1424
      goto err;
1056
1425
    }
1057
1426
 
1062
1431
      goto err;
1063
1432
    }
1064
1433
 
1065
 
    var->save_result.uint32_t_value= ((uint32_t)
 
1434
    var->save_result.ulong_value= ((ulong)
1066
1435
                                   find_set(enum_names, res->c_ptr(),
1067
1436
                                            res->length(),
1068
1437
                                            NULL,
1070
1439
                                            &not_used));
1071
1440
    if (error_len)
1072
1441
    {
1073
 
      size_t len = cmin(sizeof(buff) - 1, error_len);
1074
 
      strncpy(buff, error, len);
1075
 
      buff[len]= '\0';
 
1442
      strmake(buff, error, min(sizeof(buff) - 1, error_len));
1076
1443
      goto err;
1077
1444
    }
1078
1445
  }
1079
1446
  else
1080
1447
  {
1081
 
    uint64_t tmp= var->value->val_int();
 
1448
    ulonglong tmp= var->value->val_int();
1082
1449
 
1083
1450
    if (!m_allow_empty_value &&
1084
1451
        tmp == 0)
1092
1459
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1093
1460
      undefined, we guard with a "count<64" test.
1094
1461
    */
1095
 
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
 
1462
    if (unlikely((tmp >= ((1ULL) << enum_names->count)) &&
1096
1463
                 (enum_names->count < 64)))
1097
1464
    {
1098
1465
      llstr(tmp, buff);
1099
1466
      goto err;
1100
1467
    }
1101
 
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
 
1468
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
1102
1469
  }
1103
1470
  return 0;
1104
1471
 
1116
1483
  If type is not given, return local value if exists, else global.
1117
1484
*/
1118
1485
 
1119
 
Item *sys_var::item(Session *session, enum_var_type var_type, const LEX_STRING *base)
 
1486
Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
1120
1487
{
1121
1488
  if (check_type(var_type))
1122
1489
  {
1130
1497
    var_type= OPT_GLOBAL;
1131
1498
  }
1132
1499
  switch (show_type()) {
 
1500
  case SHOW_INT:
 
1501
  {
 
1502
    uint value;
 
1503
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1504
    value= *(uint*) value_ptr(thd, var_type, base);
 
1505
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1506
    return new Item_uint((ulonglong) value);
 
1507
  }
1133
1508
  case SHOW_LONG:
1134
 
  case SHOW_INT:
1135
1509
  {
1136
 
    uint32_t value;
 
1510
    ulong value;
1137
1511
    pthread_mutex_lock(&LOCK_global_system_variables);
1138
 
    value= *(uint*) value_ptr(session, var_type, base);
 
1512
    value= *(ulong*) value_ptr(thd, var_type, base);
1139
1513
    pthread_mutex_unlock(&LOCK_global_system_variables);
1140
 
    return new Item_uint((uint64_t) value);
 
1514
    return new Item_uint((ulonglong) value);
1141
1515
  }
1142
1516
  case SHOW_LONGLONG:
1143
1517
  {
1144
 
    int64_t value;
 
1518
    longlong value;
1145
1519
    pthread_mutex_lock(&LOCK_global_system_variables);
1146
 
    value= *(int64_t*) value_ptr(session, var_type, base);
 
1520
    value= *(longlong*) value_ptr(thd, var_type, base);
1147
1521
    pthread_mutex_unlock(&LOCK_global_system_variables);
1148
1522
    return new Item_int(value);
1149
1523
  }
1151
1525
  {
1152
1526
    double value;
1153
1527
    pthread_mutex_lock(&LOCK_global_system_variables);
1154
 
    value= *(double*) value_ptr(session, var_type, base);
 
1528
    value= *(double*) value_ptr(thd, var_type, base);
1155
1529
    pthread_mutex_unlock(&LOCK_global_system_variables);
1156
1530
    /* 6, as this is for now only used with microseconds */
1157
1531
    return new Item_float(value, 6);
1160
1534
  {
1161
1535
    ha_rows value;
1162
1536
    pthread_mutex_lock(&LOCK_global_system_variables);
1163
 
    value= *(ha_rows*) value_ptr(session, var_type, base);
1164
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1165
 
    return new Item_int((uint64_t) value);
1166
 
  }
1167
 
  case SHOW_SIZE:
1168
 
  {
1169
 
    size_t value;
1170
 
    pthread_mutex_lock(&LOCK_global_system_variables);
1171
 
    value= *(size_t*) value_ptr(session, var_type, base);
1172
 
    pthread_mutex_unlock(&LOCK_global_system_variables);
1173
 
    return new Item_int((uint64_t) value);
 
1537
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1538
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1539
    return new Item_int((ulonglong) value);
1174
1540
  }
1175
1541
  case SHOW_MY_BOOL:
1176
1542
  {
1177
 
    int32_t value;
 
1543
    int32 value;
1178
1544
    pthread_mutex_lock(&LOCK_global_system_variables);
1179
 
    value= *(bool*) value_ptr(session, var_type, base);
 
1545
    value= *(my_bool*) value_ptr(thd, var_type, base);
1180
1546
    pthread_mutex_unlock(&LOCK_global_system_variables);
1181
1547
    return new Item_int(value,1);
1182
1548
  }
1184
1550
  {
1185
1551
    Item *tmp;
1186
1552
    pthread_mutex_lock(&LOCK_global_system_variables);
1187
 
    char *str= *(char**) value_ptr(session, var_type, base);
 
1553
    char *str= *(char**) value_ptr(thd, var_type, base);
1188
1554
    if (str)
1189
1555
    {
1190
 
      uint32_t length= strlen(str);
1191
 
      tmp= new Item_string(session->strmake(str, length), length,
 
1556
      uint length= strlen(str);
 
1557
      tmp= new Item_string(thd->strmake(str, length), length,
1192
1558
                           system_charset_info, DERIVATION_SYSCONST);
1193
1559
    }
1194
1560
    else
1203
1569
  {
1204
1570
    Item *tmp;
1205
1571
    pthread_mutex_lock(&LOCK_global_system_variables);
1206
 
    char *str= (char*) value_ptr(session, var_type, base);
 
1572
    char *str= (char*) value_ptr(thd, var_type, base);
1207
1573
    if (str)
1208
1574
      tmp= new Item_string(str, strlen(str),
1209
1575
                           system_charset_info, DERIVATION_SYSCONST);
1222
1588
}
1223
1589
 
1224
1590
 
1225
 
bool sys_var_session_enum::update(Session *session, set_var *var)
 
1591
bool sys_var_thd_enum::update(THD *thd, set_var *var)
1226
1592
{
1227
1593
  if (var->type == OPT_GLOBAL)
1228
 
    global_system_variables.*offset= var->save_result.uint32_t_value;
 
1594
    global_system_variables.*offset= var->save_result.ulong_value;
1229
1595
  else
1230
 
    session->variables.*offset= var->save_result.uint32_t_value;
 
1596
    thd->variables.*offset= var->save_result.ulong_value;
1231
1597
  return 0;
1232
1598
}
1233
1599
 
1234
1600
 
1235
 
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
 
1601
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
1236
1602
{
1237
1603
  if (type == OPT_GLOBAL)
1238
 
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
 
1604
    global_system_variables.*offset= (ulong) option_limits->def_value;
1239
1605
  else
1240
 
    session->variables.*offset= global_system_variables.*offset;
 
1606
    thd->variables.*offset= global_system_variables.*offset;
1241
1607
}
1242
1608
 
1243
1609
 
1244
 
unsigned char *sys_var_session_enum::value_ptr(Session *session,
1245
 
                                               enum_var_type type,
1246
 
                                               const LEX_STRING *)
 
1610
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1611
                                   LEX_STRING *base __attribute__((__unused__)))
1247
1612
{
1248
 
  uint32_t tmp= ((type == OPT_GLOBAL) ?
 
1613
  ulong tmp= ((type == OPT_GLOBAL) ?
1249
1614
              global_system_variables.*offset :
1250
 
              session->variables.*offset);
1251
 
  return (unsigned char*) enum_names->type_names[tmp];
1252
 
}
1253
 
 
1254
 
bool sys_var_session_bit::check(Session *session, set_var *var)
1255
 
{
1256
 
  return (check_enum(session, var, &bool_typelib) ||
1257
 
          (check_func && (*check_func)(session, var)));
1258
 
}
1259
 
 
1260
 
bool sys_var_session_bit::update(Session *session, set_var *var)
1261
 
{
1262
 
  int res= (*update_func)(session, var);
 
1615
              thd->variables.*offset);
 
1616
  return (uchar*) enum_names->type_names[tmp];
 
1617
}
 
1618
 
 
1619
bool sys_var_thd_bit::check(THD *thd, set_var *var)
 
1620
{
 
1621
  return (check_enum(thd, var, &bool_typelib) ||
 
1622
          (check_func && (*check_func)(thd, var)));
 
1623
}
 
1624
 
 
1625
bool sys_var_thd_bit::update(THD *thd, set_var *var)
 
1626
{
 
1627
  int res= (*update_func)(thd, var);
1263
1628
  return res;
1264
1629
}
1265
1630
 
1266
1631
 
1267
 
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
1268
 
                                              const LEX_STRING *)
 
1632
uchar *sys_var_thd_bit::value_ptr(THD *thd,
 
1633
                                  enum_var_type type __attribute__((__unused__)),
 
1634
                                  LEX_STRING *base __attribute__((__unused__)))
1269
1635
{
1270
1636
  /*
1271
1637
    If reverse is 0 (default) return 1 if bit is set.
1272
1638
    If reverse is 1, return 0 if bit is set
1273
1639
  */
1274
 
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
 
1640
  thd->sys_var_tmp.my_bool_value= ((thd->options & bit_flag) ?
1275
1641
                                   !reverse : reverse);
1276
 
  return (unsigned char*) &session->sys_var_tmp.bool_value;
 
1642
  return (uchar*) &thd->sys_var_tmp.my_bool_value;
 
1643
}
 
1644
 
 
1645
 
 
1646
/** Update a date_time format variable based on given value. */
 
1647
 
 
1648
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
 
1649
                                           DATE_TIME_FORMAT *new_value)
 
1650
{
 
1651
  DATE_TIME_FORMAT *old;
 
1652
 
 
1653
  if (type == OPT_GLOBAL)
 
1654
  {
 
1655
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1656
    old= (global_system_variables.*offset);
 
1657
    (global_system_variables.*offset)= new_value;
 
1658
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1659
  }
 
1660
  else
 
1661
  {
 
1662
    old= (thd->variables.*offset);
 
1663
    (thd->variables.*offset)= new_value;
 
1664
  }
 
1665
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
 
1666
  return;
 
1667
}
 
1668
 
 
1669
 
 
1670
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
 
1671
{
 
1672
  DATE_TIME_FORMAT *new_value;
 
1673
  /* We must make a copy of the last value to get it into normal memory */
 
1674
  new_value= date_time_format_copy((THD*) 0,
 
1675
                                   var->save_result.date_time_format);
 
1676
  if (!new_value)
 
1677
    return 1;                                   // Out of memory
 
1678
  update2(thd, var->type, new_value);           // Can't fail
 
1679
  return 0;
 
1680
}
 
1681
 
 
1682
 
 
1683
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
 
1684
{
 
1685
  char buff[STRING_BUFFER_USUAL_SIZE];
 
1686
  String str(buff,sizeof(buff), system_charset_info), *res;
 
1687
  DATE_TIME_FORMAT *format;
 
1688
 
 
1689
  if (!(res=var->value->val_str(&str)))
 
1690
    res= &my_empty_string;
 
1691
 
 
1692
  if (!(format= date_time_format_make(date_time_type,
 
1693
                                      res->ptr(), res->length())))
 
1694
  {
 
1695
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, res->c_ptr());
 
1696
    return 1;
 
1697
  }
 
1698
  
 
1699
  /*
 
1700
    We must copy result to thread space to not get a memory leak if
 
1701
    update is aborted
 
1702
  */
 
1703
  var->save_result.date_time_format= date_time_format_copy(thd, format);
 
1704
  my_free((char*) format, MYF(0));
 
1705
  return var->save_result.date_time_format == 0;
 
1706
}
 
1707
 
 
1708
 
 
1709
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
 
1710
{
 
1711
  DATE_TIME_FORMAT *res= 0;
 
1712
 
 
1713
  if (type == OPT_GLOBAL)
 
1714
  {
 
1715
    const char *format;
 
1716
    if ((format= opt_date_time_formats[date_time_type]))
 
1717
      res= date_time_format_make(date_time_type, format, strlen(format));
 
1718
  }
 
1719
  else
 
1720
  {
 
1721
    /* Make copy with malloc */
 
1722
    res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
 
1723
  }
 
1724
 
 
1725
  if (res)                                      // Should always be true
 
1726
    update2(thd, type, res);
 
1727
}
 
1728
 
 
1729
 
 
1730
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1731
                                               LEX_STRING *base __attribute__((__unused__)))
 
1732
{
 
1733
  if (type == OPT_GLOBAL)
 
1734
  {
 
1735
    char *res;
 
1736
    /*
 
1737
      We do a copy here just to be sure things will work even if someone
 
1738
      is modifying the original string while the copy is accessed
 
1739
      (Can't happen now in SQL SHOW, but this is a good safety for the future)
 
1740
    */
 
1741
    res= thd->strmake((global_system_variables.*offset)->format.str,
 
1742
                      (global_system_variables.*offset)->format.length);
 
1743
    return (uchar*) res;
 
1744
  }
 
1745
  return (uchar*) (thd->variables.*offset)->format.str;
1277
1746
}
1278
1747
 
1279
1748
 
1283
1752
  const char *new_name;
1284
1753
} my_old_conv;
1285
1754
 
1286
 
bool sys_var_collation::check(Session *, set_var *var)
1287
 
{
1288
 
  const CHARSET_INFO *tmp;
 
1755
static my_old_conv old_conv[]= 
 
1756
{
 
1757
  {     "cp1251_koi8"           ,       "cp1251"        },
 
1758
  {     "cp1250_latin2"         ,       "cp1250"        },
 
1759
  {     "kam_latin2"            ,       "keybcs2"       },
 
1760
  {     "mac_latin2"            ,       "MacRoman"      },
 
1761
  {     "macce_latin2"          ,       "MacCE"         },
 
1762
  {     "pc2_latin2"            ,       "pclatin2"      },
 
1763
  {     "vga_latin2"            ,       "pclatin1"      },
 
1764
  {     "koi8_cp1251"           ,       "koi8r"         },
 
1765
  {     "win1251ukr_koi8_ukr"   ,       "win1251ukr"    },
 
1766
  {     "koi8_ukr_win1251ukr"   ,       "koi8u"         },
 
1767
  {     NULL                    ,       NULL            }
 
1768
};
 
1769
 
 
1770
CHARSET_INFO *get_old_charset_by_name(const char *name)
 
1771
{
 
1772
  my_old_conv *conv;
 
1773
 
 
1774
  for (conv= old_conv; conv->old_name; conv++)
 
1775
  {
 
1776
    if (!my_strcasecmp(&my_charset_latin1, name, conv->old_name))
 
1777
      return get_charset_by_csname(conv->new_name, MY_CS_PRIMARY, MYF(0));
 
1778
  }
 
1779
  return NULL;
 
1780
}
 
1781
 
 
1782
 
 
1783
bool sys_var_collation::check(THD *thd __attribute__((__unused__)),
 
1784
                              set_var *var)
 
1785
{
 
1786
  CHARSET_INFO *tmp;
1289
1787
 
1290
1788
  if (var->value->result_type() == STRING_RESULT)
1291
1789
  {
1296
1794
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1297
1795
      return 1;
1298
1796
    }
1299
 
    if (!(tmp=get_charset_by_name(res->c_ptr())))
 
1797
    if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))))
1300
1798
    {
1301
1799
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1302
1800
      return 1;
1304
1802
  }
1305
1803
  else // INT_RESULT
1306
1804
  {
1307
 
    if (!(tmp=get_charset((int) var->value->val_int())))
 
1805
    if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
1308
1806
    {
1309
1807
      char buf[20];
1310
1808
      int10_to_str((int) var->value->val_int(), buf, -10);
1317
1815
}
1318
1816
 
1319
1817
 
1320
 
bool sys_var_collation_sv::update(Session *session, set_var *var)
 
1818
bool sys_var_character_set::check(THD *thd __attribute__((__unused__)),
 
1819
                                  set_var *var)
 
1820
{
 
1821
  CHARSET_INFO *tmp;
 
1822
 
 
1823
  if (var->value->result_type() == STRING_RESULT)
 
1824
  {
 
1825
    char buff[STRING_BUFFER_USUAL_SIZE];
 
1826
    String str(buff,sizeof(buff), system_charset_info), *res;
 
1827
    if (!(res=var->value->val_str(&str)))
 
1828
    {
 
1829
      if (!nullable)
 
1830
      {
 
1831
        my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
 
1832
        return 1;
 
1833
      }
 
1834
      tmp= NULL;
 
1835
    }
 
1836
    else if (!(tmp=get_charset_by_csname(res->c_ptr(),MY_CS_PRIMARY,MYF(0))) &&
 
1837
             !(tmp=get_old_charset_by_name(res->c_ptr())))
 
1838
    {
 
1839
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), res->c_ptr());
 
1840
      return 1;
 
1841
    }
 
1842
  }
 
1843
  else // INT_RESULT
 
1844
  {
 
1845
    if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
 
1846
    {
 
1847
      char buf[20];
 
1848
      int10_to_str((int) var->value->val_int(), buf, -10);
 
1849
      my_error(ER_UNKNOWN_CHARACTER_SET, MYF(0), buf);
 
1850
      return 1;
 
1851
    }
 
1852
  }
 
1853
  var->save_result.charset= tmp;        // Save for update
 
1854
  return 0;
 
1855
}
 
1856
 
 
1857
 
 
1858
bool sys_var_character_set::update(THD *thd, set_var *var)
 
1859
{
 
1860
  ci_ptr(thd,var->type)[0]= var->save_result.charset;
 
1861
  thd->update_charset();
 
1862
  return 0;
 
1863
}
 
1864
 
 
1865
 
 
1866
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1867
                                        LEX_STRING *base __attribute__((__unused__)))
 
1868
{
 
1869
  CHARSET_INFO *cs= ci_ptr(thd,type)[0];
 
1870
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
 
1871
}
 
1872
 
 
1873
 
 
1874
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
 
1875
{
 
1876
  if (type == OPT_GLOBAL)
 
1877
    global_system_variables.*offset= *global_default;
 
1878
  else
 
1879
  {
 
1880
    thd->variables.*offset= global_system_variables.*offset;
 
1881
    thd->update_charset();
 
1882
  }
 
1883
}
 
1884
CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
 
1885
{
 
1886
  if (type == OPT_GLOBAL)
 
1887
    return &(global_system_variables.*offset);
 
1888
  else
 
1889
    return &(thd->variables.*offset);
 
1890
}
 
1891
 
 
1892
 
 
1893
bool sys_var_character_set_client::check(THD *thd, set_var *var)
 
1894
{
 
1895
  if (sys_var_character_set_sv::check(thd, var))
 
1896
    return 1;
 
1897
  /* Currently, UCS-2 cannot be used as a client character set */
 
1898
  if (var->save_result.charset->mbminlen > 1)
 
1899
  {
 
1900
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
 
1901
             var->save_result.charset->csname);
 
1902
    return 1;
 
1903
  }
 
1904
  return 0;
 
1905
}
 
1906
 
 
1907
 
 
1908
CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
 
1909
                                                       enum_var_type type)
 
1910
{
 
1911
  if (type == OPT_GLOBAL)
 
1912
    return &global_system_variables.collation_database;
 
1913
  else
 
1914
    return &thd->variables.collation_database;
 
1915
}
 
1916
 
 
1917
 
 
1918
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
 
1919
{
 
1920
 if (type == OPT_GLOBAL)
 
1921
    global_system_variables.collation_database= default_charset_info;
 
1922
  else
 
1923
  {
 
1924
    thd->variables.collation_database= thd->db_charset;
 
1925
    thd->update_charset();
 
1926
  }
 
1927
}
 
1928
 
 
1929
 
 
1930
bool sys_var_collation_sv::update(THD *thd, set_var *var)
1321
1931
{
1322
1932
  if (var->type == OPT_GLOBAL)
1323
1933
    global_system_variables.*offset= var->save_result.charset;
1324
1934
  else
1325
1935
  {
1326
 
    session->variables.*offset= var->save_result.charset;
1327
 
    session->update_charset();
 
1936
    thd->variables.*offset= var->save_result.charset;
 
1937
    thd->update_charset();
1328
1938
  }
1329
1939
  return 0;
1330
1940
}
1331
1941
 
1332
1942
 
1333
 
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
 
1943
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
1334
1944
{
1335
1945
  if (type == OPT_GLOBAL)
1336
1946
    global_system_variables.*offset= *global_default;
1337
1947
  else
1338
1948
  {
1339
 
    session->variables.*offset= global_system_variables.*offset;
1340
 
    session->update_charset();
 
1949
    thd->variables.*offset= global_system_variables.*offset;
 
1950
    thd->update_charset();
1341
1951
  }
1342
1952
}
1343
1953
 
1344
1954
 
1345
 
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
1346
 
                                               enum_var_type type,
1347
 
                                               const LEX_STRING *)
 
1955
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1956
                                       LEX_STRING *base __attribute__((__unused__)))
1348
1957
{
1349
 
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1350
 
                           global_system_variables.*offset :
1351
 
                           session->variables.*offset);
1352
 
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
 
1958
  CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
 
1959
                     global_system_variables.*offset : thd->variables.*offset);
 
1960
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
1353
1961
}
1354
1962
 
1355
1963
 
1357
1965
 
1358
1966
static KEY_CACHE zero_key_cache;
1359
1967
 
1360
 
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
 
1968
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
1361
1969
{
1362
1970
  safe_mutex_assert_owner(&LOCK_global_system_variables);
1363
1971
  if (!cache_name || ! cache_name->length)
1364
1972
    cache_name= &default_key_cache_base;
1365
1973
  return ((KEY_CACHE*) find_named(&key_caches,
1366
 
                                  cache_name->str, cache_name->length, 0));
 
1974
                                      cache_name->str, cache_name->length, 0));
1367
1975
}
1368
1976
 
1369
1977
 
1370
 
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
1371
 
                                                  const LEX_STRING *base)
 
1978
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((__unused__)),
 
1979
                                          enum_var_type type __attribute__((__unused__)),
 
1980
                                          LEX_STRING *base __attribute__((__unused__)))
1372
1981
{
1373
1982
  KEY_CACHE *key_cache= get_key_cache(base);
1374
1983
  if (!key_cache)
1375
1984
    key_cache= &zero_key_cache;
1376
 
  return (unsigned char*) key_cache + offset ;
 
1985
  return (uchar*) key_cache + offset ;
1377
1986
}
1378
1987
 
1379
1988
 
1380
 
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
 
1989
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
1381
1990
{
1382
 
  uint64_t tmp= var->save_result.uint64_t_value;
 
1991
  ulonglong tmp= var->save_result.ulonglong_value;
1383
1992
  LEX_STRING *base_name= &var->base;
1384
1993
  KEY_CACHE *key_cache;
1385
1994
  bool error= 0;
1390
1999
 
1391
2000
  pthread_mutex_lock(&LOCK_global_system_variables);
1392
2001
  key_cache= get_key_cache(base_name);
1393
 
 
 
2002
                            
1394
2003
  if (!key_cache)
1395
2004
  {
1396
2005
    /* Key cache didn't exists */
1415
2024
  {
1416
2025
    if (key_cache == dflt_key_cache)
1417
2026
    {
1418
 
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
2027
      push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1419
2028
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1420
2029
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1421
2030
      goto end;                                 // Ignore default key cache
1427
2036
        Move tables using this key cache to the default key cache
1428
2037
        and clear the old key cache.
1429
2038
      */
1430
 
      NAMED_LIST *list;
 
2039
      NAMED_LIST *list; 
1431
2040
      key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1432
2041
                                              base_name->length, &list);
1433
2042
      key_cache->in_init= 1;
1434
2043
      pthread_mutex_unlock(&LOCK_global_system_variables);
1435
 
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
 
2044
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
1436
2045
      pthread_mutex_lock(&LOCK_global_system_variables);
1437
2046
      key_cache->in_init= 0;
1438
2047
    }
1444
2053
  }
1445
2054
 
1446
2055
  key_cache->param_buff_size=
1447
 
    (uint64_t) fix_unsigned(session, tmp, option_limits);
 
2056
    (ulonglong) fix_unsigned(thd, tmp, option_limits);
1448
2057
 
1449
2058
  /* If key cache didn't existed initialize it, else resize it */
1450
2059
  key_cache->in_init= 1;
1456
2065
    error= (bool)(ha_resize_key_cache(key_cache));
1457
2066
 
1458
2067
  pthread_mutex_lock(&LOCK_global_system_variables);
1459
 
  key_cache->in_init= 0;
 
2068
  key_cache->in_init= 0;  
1460
2069
 
1461
2070
end:
1462
2071
  pthread_mutex_unlock(&LOCK_global_system_variables);
1470
2079
  This should be changed so that we wait until the previous
1471
2080
  assignment is done and then do the new assign
1472
2081
*/
1473
 
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
 
2082
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
1474
2083
{
1475
 
  uint64_t tmp= (uint64_t) var->value->val_int();
 
2084
  ulong tmp= (ulong) var->value->val_int();
1476
2085
  LEX_STRING *base_name= &var->base;
1477
2086
  bool error= 0;
1478
2087
 
1497
2106
  if (key_cache->in_init)
1498
2107
    goto end;
1499
2108
 
1500
 
  *((uint32_t*) (((char*) key_cache) + offset))=
1501
 
    (uint32_t) fix_unsigned(session, tmp, option_limits);
 
2109
  *((ulong*) (((char*) key_cache) + offset))=
 
2110
    (ulong) fix_unsigned(thd, tmp, option_limits);
1502
2111
 
1503
2112
  /*
1504
2113
    Don't create a new key cache if it didn't exist
1511
2120
  error= (bool) (ha_resize_key_cache(key_cache));
1512
2121
 
1513
2122
  pthread_mutex_lock(&LOCK_global_system_variables);
1514
 
  key_cache->in_init= 0;
 
2123
  key_cache->in_init= 0;  
1515
2124
 
1516
2125
end:
1517
2126
  pthread_mutex_unlock(&LOCK_global_system_variables);
1519
2128
}
1520
2129
 
1521
2130
 
 
2131
bool sys_var_log_state::update(THD *thd, set_var *var)
 
2132
{
 
2133
  bool res;
 
2134
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2135
  if (!var->save_result.ulong_value)
 
2136
  {
 
2137
    logger.deactivate_log_handler(thd, log_type);
 
2138
    res= false;
 
2139
  }
 
2140
  else
 
2141
    res= logger.activate_log_handler(thd, log_type);
 
2142
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2143
  return res;
 
2144
}
 
2145
 
 
2146
void sys_var_log_state::set_default(THD *thd,
 
2147
                                    enum_var_type type __attribute__((__unused__)))
 
2148
{
 
2149
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2150
  logger.deactivate_log_handler(thd, log_type);
 
2151
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2152
}
 
2153
 
 
2154
 
 
2155
static int  sys_check_log_path(THD *thd __attribute__((__unused__)),
 
2156
                               set_var *var)
 
2157
{
 
2158
  char path[FN_REFLEN], buff[FN_REFLEN];
 
2159
  struct stat f_stat;
 
2160
  String str(buff, sizeof(buff), system_charset_info), *res;
 
2161
  const char *log_file_str;
 
2162
  size_t path_length;
 
2163
 
 
2164
  if (!(res= var->value->val_str(&str)))
 
2165
    goto err;
 
2166
 
 
2167
  log_file_str= res->c_ptr();
 
2168
  bzero(&f_stat, sizeof(struct stat));
 
2169
 
 
2170
  path_length= unpack_filename(path, log_file_str);
 
2171
 
 
2172
  if (!path_length)
 
2173
  {
 
2174
    /* File name is empty. */
 
2175
 
 
2176
    goto err;
 
2177
  }
 
2178
 
 
2179
  if (!stat(path, &f_stat))
 
2180
  {
 
2181
    /*
 
2182
      A file system object exists. Check if argument is a file and we have
 
2183
      'write' permission.
 
2184
    */
 
2185
 
 
2186
    if (!MY_S_ISREG(f_stat.st_mode) ||
 
2187
        !(f_stat.st_mode & MY_S_IWRITE))
 
2188
      goto err;
 
2189
 
 
2190
    return 0;
 
2191
  }
 
2192
 
 
2193
  /* Get dirname of the file path. */
 
2194
  (void) dirname_part(path, log_file_str, &path_length);
 
2195
 
 
2196
  /* Dirname is empty if file path is relative. */
 
2197
  if (!path_length)
 
2198
    return 0;
 
2199
 
 
2200
  /*
 
2201
    Check if directory exists and we have permission to create file and
 
2202
    write to file.
 
2203
  */
 
2204
  if (my_access(path, (F_OK|W_OK)))
 
2205
    goto err;
 
2206
 
 
2207
  return 0;
 
2208
 
 
2209
err:
 
2210
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
 
2211
           res ? log_file_str : "NULL");
 
2212
  return 1;
 
2213
}
 
2214
 
 
2215
 
 
2216
bool update_sys_var_str_path(THD *thd __attribute__((__unused__)),
 
2217
                             sys_var_str *var_str,
 
2218
                             set_var *var, const char *log_ext,
 
2219
                             bool log_state, uint log_type)
 
2220
{
 
2221
  MYSQL_QUERY_LOG *file_log;
 
2222
  char buff[FN_REFLEN];
 
2223
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
 
2224
  bool result= 0;
 
2225
  uint str_length= (var ? var->value->str_value.length() : 0);
 
2226
 
 
2227
  switch (log_type) {
 
2228
  case QUERY_LOG_SLOW:
 
2229
    file_log= logger.get_slow_log_file_handler();
 
2230
    break;
 
2231
  case QUERY_LOG_GENERAL:
 
2232
    file_log= logger.get_log_file_handler();
 
2233
    break;
 
2234
  default:
 
2235
    assert(0);                                  // Impossible
 
2236
  }
 
2237
 
 
2238
  if (!old_value)
 
2239
  {
 
2240
    old_value= make_default_log_name(buff, log_ext);
 
2241
    str_length= strlen(old_value);
 
2242
  }
 
2243
  if (!(res= my_strndup(old_value, str_length, MYF(MY_FAE+MY_WME))))
 
2244
  {
 
2245
    result= 1;
 
2246
    goto err;
 
2247
  }
 
2248
 
 
2249
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2250
  logger.lock_exclusive();
 
2251
 
 
2252
  if (file_log && log_state)
 
2253
    file_log->close(0);
 
2254
  old_value= var_str->value;
 
2255
  var_str->value= res;
 
2256
  var_str->value_length= str_length;
 
2257
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
2258
  if (file_log && log_state)
 
2259
  {
 
2260
    switch (log_type) {
 
2261
    case QUERY_LOG_SLOW:
 
2262
      file_log->open_slow_log(sys_var_slow_log_path.value);
 
2263
      break;
 
2264
    case QUERY_LOG_GENERAL:
 
2265
      file_log->open_query_log(sys_var_general_log_path.value);
 
2266
      break;
 
2267
    default:
 
2268
      assert(0);
 
2269
    }
 
2270
  }
 
2271
 
 
2272
  logger.unlock();
 
2273
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2274
 
 
2275
err:
 
2276
  return result;
 
2277
}
 
2278
 
 
2279
 
 
2280
static bool sys_update_general_log_path(THD *thd, set_var * var)
 
2281
{
 
2282
  return update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2283
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
 
2284
}
 
2285
 
 
2286
 
 
2287
static void sys_default_general_log_path(THD *thd,
 
2288
                                         enum_var_type type __attribute__((__unused__)))
 
2289
{
 
2290
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
 
2291
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
 
2292
}
 
2293
 
 
2294
 
 
2295
static bool sys_update_slow_log_path(THD *thd, set_var * var)
 
2296
{
 
2297
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2298
                                 var, "-slow.log", opt_slow_log,
 
2299
                                 QUERY_LOG_SLOW);
 
2300
}
 
2301
 
 
2302
 
 
2303
static void sys_default_slow_log_path(THD *thd,
 
2304
                                      enum_var_type type __attribute__((__unused__)))
 
2305
{
 
2306
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
 
2307
                                 0, "-slow.log", opt_slow_log,
 
2308
                                 QUERY_LOG_SLOW);
 
2309
}
 
2310
 
 
2311
 
 
2312
bool sys_var_log_output::update(THD *thd __attribute__((__unused__)),
 
2313
                                set_var *var)
 
2314
{
 
2315
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2316
  logger.lock_exclusive();
 
2317
  logger.init_slow_log(var->save_result.ulong_value);
 
2318
  logger.init_general_log(var->save_result.ulong_value);
 
2319
  *value= var->save_result.ulong_value;
 
2320
  logger.unlock();
 
2321
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2322
  return 0;
 
2323
}
 
2324
 
 
2325
 
 
2326
void sys_var_log_output::set_default(THD *thd __attribute__((__unused__)),
 
2327
                                     enum_var_type type __attribute__((__unused__)))
 
2328
{
 
2329
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2330
  logger.lock_exclusive();
 
2331
  logger.init_slow_log(LOG_FILE);
 
2332
  logger.init_general_log(LOG_FILE);
 
2333
  *value= LOG_FILE;
 
2334
  logger.unlock();
 
2335
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2336
}
 
2337
 
 
2338
 
 
2339
uchar *sys_var_log_output::value_ptr(THD *thd,
 
2340
                                     enum_var_type type __attribute__((__unused__)),
 
2341
                                     LEX_STRING *base __attribute__((__unused__)))
 
2342
{
 
2343
  char buff[256];
 
2344
  String tmp(buff, sizeof(buff), &my_charset_latin1);
 
2345
  ulong length;
 
2346
  ulong val= *value;
 
2347
 
 
2348
  tmp.length(0);
 
2349
  for (uint i= 0; val; val>>= 1, i++)
 
2350
  {
 
2351
    if (val & 1)
 
2352
    {
 
2353
      tmp.append(log_output_typelib.type_names[i],
 
2354
                 log_output_typelib.type_lengths[i]);
 
2355
      tmp.append(',');
 
2356
    }
 
2357
  }
 
2358
 
 
2359
  if ((length= tmp.length()))
 
2360
    length--;
 
2361
  return (uchar*) thd->strmake(tmp.ptr(), length);
 
2362
}
 
2363
 
 
2364
 
 
2365
/*****************************************************************************
 
2366
  Functions to handle SET NAMES and SET CHARACTER SET
 
2367
*****************************************************************************/
 
2368
 
 
2369
int set_var_collation_client::check(THD *thd __attribute__((__unused__)))
 
2370
{
 
2371
  /* Currently, UCS-2 cannot be used as a client character set */
 
2372
  if (character_set_client->mbminlen > 1)
 
2373
  {
 
2374
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "character_set_client",
 
2375
             character_set_client->csname);
 
2376
    return 1;
 
2377
  }
 
2378
  return 0;
 
2379
}
 
2380
 
 
2381
int set_var_collation_client::update(THD *thd)
 
2382
{
 
2383
  thd->variables.character_set_client= character_set_client;
 
2384
  thd->variables.character_set_results= character_set_results;
 
2385
  thd->variables.collation_connection= collation_connection;
 
2386
  thd->update_charset();
 
2387
  thd->protocol_text.init(thd);
 
2388
  return 0;
 
2389
}
 
2390
 
1522
2391
/****************************************************************************/
1523
2392
 
1524
 
bool sys_var_timestamp::update(Session *session,  set_var *var)
1525
 
{
1526
 
  session->set_time((time_t) var->save_result.uint64_t_value);
1527
 
  return 0;
1528
 
}
1529
 
 
1530
 
 
1531
 
void sys_var_timestamp::set_default(Session *session, enum_var_type)
1532
 
{
1533
 
  session->user_time=0;
1534
 
}
1535
 
 
1536
 
 
1537
 
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
1538
 
                                            const LEX_STRING *)
1539
 
{
1540
 
  session->sys_var_tmp.long_value= (long) session->start_time;
1541
 
  return (unsigned char*) &session->sys_var_tmp.long_value;
1542
 
}
1543
 
 
1544
 
 
1545
 
bool sys_var_last_insert_id::update(Session *session, set_var *var)
1546
 
{
1547
 
  session->first_successful_insert_id_in_prev_stmt=
1548
 
    var->save_result.uint64_t_value;
1549
 
  return 0;
1550
 
}
1551
 
 
1552
 
 
1553
 
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
1554
 
                                                 enum_var_type,
1555
 
                                                 const LEX_STRING *)
 
2393
bool sys_var_timestamp::update(THD *thd,  set_var *var)
 
2394
{
 
2395
  thd->set_time((time_t) var->save_result.ulonglong_value);
 
2396
  return 0;
 
2397
}
 
2398
 
 
2399
 
 
2400
void sys_var_timestamp::set_default(THD *thd,
 
2401
                                    enum_var_type type __attribute__((__unused__)))
 
2402
{
 
2403
  thd->user_time=0;
 
2404
}
 
2405
 
 
2406
 
 
2407
uchar *sys_var_timestamp::value_ptr(THD *thd,
 
2408
                                    enum_var_type type __attribute__((__unused__)),
 
2409
                                    LEX_STRING *base __attribute__((__unused__)))
 
2410
{
 
2411
  thd->sys_var_tmp.long_value= (long) thd->start_time;
 
2412
  return (uchar*) &thd->sys_var_tmp.long_value;
 
2413
}
 
2414
 
 
2415
 
 
2416
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
 
2417
{
 
2418
  thd->first_successful_insert_id_in_prev_stmt=
 
2419
    var->save_result.ulonglong_value;
 
2420
  return 0;
 
2421
}
 
2422
 
 
2423
 
 
2424
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
 
2425
                                         enum_var_type type __attribute__((__unused__)),
 
2426
                                         LEX_STRING *base __attribute__((__unused__)))
1556
2427
{
1557
2428
  /*
1558
2429
    this tmp var makes it robust againt change of type of
1559
2430
    read_first_successful_insert_id_in_prev_stmt().
1560
2431
  */
1561
 
  session->sys_var_tmp.uint64_t_value=
1562
 
    session->read_first_successful_insert_id_in_prev_stmt();
1563
 
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
1564
 
}
1565
 
 
1566
 
 
1567
 
bool sys_var_session_time_zone::check(Session *session, set_var *var)
 
2432
  thd->sys_var_tmp.ulonglong_value= 
 
2433
    thd->read_first_successful_insert_id_in_prev_stmt();
 
2434
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
 
2435
}
 
2436
 
 
2437
 
 
2438
bool sys_var_insert_id::update(THD *thd, set_var *var)
 
2439
{
 
2440
  thd->force_one_auto_inc_interval(var->save_result.ulonglong_value);
 
2441
  return 0;
 
2442
}
 
2443
 
 
2444
 
 
2445
uchar *sys_var_insert_id::value_ptr(THD *thd,
 
2446
                                    enum_var_type type __attribute__((__unused__)),
 
2447
                                    LEX_STRING *base __attribute__((__unused__)))
 
2448
{
 
2449
  thd->sys_var_tmp.ulonglong_value=
 
2450
    thd->auto_inc_intervals_forced.minimum();
 
2451
  return (uchar*) &thd->sys_var_tmp.ulonglong_value;
 
2452
}
 
2453
 
 
2454
 
 
2455
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
 
2456
{
 
2457
  thd->rand.seed1= (ulong) var->save_result.ulonglong_value;
 
2458
  return 0;
 
2459
}
 
2460
 
 
2461
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
 
2462
{
 
2463
  thd->rand.seed2= (ulong) var->save_result.ulonglong_value;
 
2464
  return 0;
 
2465
}
 
2466
 
 
2467
 
 
2468
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
1568
2469
{
1569
2470
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
1570
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
2471
  String str(buff, sizeof(buff), &my_charset_latin1);
1571
2472
  String *res= var->value->val_str(&str);
1572
2473
 
1573
 
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
 
2474
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
1574
2475
  {
1575
2476
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
1576
2477
    return 1;
1579
2480
}
1580
2481
 
1581
2482
 
1582
 
bool sys_var_session_time_zone::update(Session *session, set_var *var)
 
2483
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
1583
2484
{
1584
2485
  /* We are using Time_zone object found during check() phase. */
1585
2486
  if (var->type == OPT_GLOBAL)
1589
2490
    pthread_mutex_unlock(&LOCK_global_system_variables);
1590
2491
  }
1591
2492
  else
1592
 
    session->variables.time_zone= var->save_result.time_zone;
 
2493
    thd->variables.time_zone= var->save_result.time_zone;
1593
2494
  return 0;
1594
2495
}
1595
2496
 
1596
2497
 
1597
 
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
1598
 
                                                    enum_var_type type,
1599
 
                                                    const LEX_STRING *)
 
2498
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2499
                                        LEX_STRING *base __attribute__((__unused__)))
1600
2500
{
1601
 
  /*
 
2501
  /* 
1602
2502
    We can use ptr() instead of c_ptr() here because String contaning
1603
2503
    time zone name is guaranteed to be zero ended.
1604
2504
  */
1605
2505
  if (type == OPT_GLOBAL)
1606
 
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
 
2506
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
1607
2507
  else
1608
2508
  {
1609
2509
    /*
1614
2514
      timezone). If it's the global value which was used we can't replicate
1615
2515
      (binlog code stores session value only).
1616
2516
    */
1617
 
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
 
2517
    thd->time_zone_used= 1;
 
2518
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
1618
2519
  }
1619
2520
}
1620
2521
 
1621
2522
 
1622
 
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
 
2523
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
1623
2524
{
1624
2525
 pthread_mutex_lock(&LOCK_global_system_variables);
1625
2526
 if (type == OPT_GLOBAL)
1626
2527
 {
1627
2528
   if (default_tz_name)
1628
2529
   {
1629
 
     String str(default_tz_name, &my_charset_utf8_general_ci);
 
2530
     String str(default_tz_name, &my_charset_latin1);
1630
2531
     /*
1631
2532
       We are guaranteed to find this time zone since its existence
1632
2533
       is checked during start-up.
1633
2534
     */
1634
 
     global_system_variables.time_zone= my_tz_find(session, &str);
 
2535
     global_system_variables.time_zone= my_tz_find(thd, &str);
1635
2536
   }
1636
2537
   else
1637
2538
     global_system_variables.time_zone= my_tz_SYSTEM;
1638
2539
 }
1639
2540
 else
1640
 
   session->variables.time_zone= global_system_variables.time_zone;
 
2541
   thd->variables.time_zone= global_system_variables.time_zone;
1641
2542
 pthread_mutex_unlock(&LOCK_global_system_variables);
1642
2543
}
1643
2544
 
1644
2545
 
1645
 
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
 
2546
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
 
2547
{
 
2548
  if (var->type == OPT_GLOBAL)
 
2549
    return sys_var_thd::check(thd, var);
 
2550
  else
 
2551
  {
 
2552
    /*
 
2553
      Per-session values of max_user_connections can't be set directly.
 
2554
      May be we should have a separate error message for this?
 
2555
    */
 
2556
    my_error(ER_GLOBAL_VARIABLE, MYF(0), name);
 
2557
    return true;
 
2558
  }
 
2559
}
 
2560
 
 
2561
bool sys_var_max_user_conn::update(THD *thd __attribute__((__unused__)),
 
2562
                                   set_var *var)
 
2563
{
 
2564
  assert(var->type == OPT_GLOBAL);
 
2565
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2566
  max_user_connections= (uint)var->save_result.ulonglong_value;
 
2567
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2568
  return 0;
 
2569
}
 
2570
 
 
2571
 
 
2572
void sys_var_max_user_conn::set_default(THD *thd __attribute__((__unused__)),
 
2573
                                        enum_var_type type __attribute__((__unused__)))
 
2574
{
 
2575
  assert(type == OPT_GLOBAL);
 
2576
  pthread_mutex_lock(&LOCK_global_system_variables);
 
2577
  max_user_connections= (ulong) option_limits->def_value;
 
2578
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
2579
}
 
2580
 
 
2581
 
 
2582
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2583
                                        LEX_STRING *base __attribute__((__unused__)))
 
2584
{
 
2585
  if (type != OPT_GLOBAL &&
 
2586
      thd->user_connect && thd->user_connect->user_resources.user_conn)
 
2587
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
 
2588
  return (uchar*) &(max_user_connections);
 
2589
}
 
2590
 
 
2591
 
 
2592
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((__unused__)),
 
2593
                                      set_var *var)
1646
2594
{
1647
2595
  MY_LOCALE *locale_match;
1648
2596
 
1649
2597
  if (var->value->result_type() == INT_RESULT)
1650
2598
  {
1651
 
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
 
2599
    if (!(locale_match= my_locale_by_number((uint) var->value->val_int())))
1652
2600
    {
1653
2601
      char buf[20];
1654
2602
      int10_to_str((int) var->value->val_int(), buf, -10);
1658
2606
  }
1659
2607
  else // STRING_RESULT
1660
2608
  {
1661
 
    char buff[6];
1662
 
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
2609
    char buff[6]; 
 
2610
    String str(buff, sizeof(buff), &my_charset_latin1), *res;
1663
2611
    if (!(res=var->value->val_str(&str)))
1664
2612
    {
1665
2613
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1679
2627
}
1680
2628
 
1681
2629
 
1682
 
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
 
2630
bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var)
1683
2631
{
1684
2632
  if (var->type == OPT_GLOBAL)
1685
2633
    global_system_variables.lc_time_names= var->save_result.locale_value;
1686
2634
  else
1687
 
    session->variables.lc_time_names= var->save_result.locale_value;
 
2635
    thd->variables.lc_time_names= var->save_result.locale_value;
1688
2636
  return 0;
1689
2637
}
1690
2638
 
1691
2639
 
1692
 
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
1693
 
                                                        enum_var_type type,
1694
 
                                                        const LEX_STRING *)
 
2640
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd,
 
2641
                                            enum_var_type type,
 
2642
                                            LEX_STRING *base __attribute__((__unused__)))
1695
2643
{
1696
2644
  return type == OPT_GLOBAL ?
1697
 
                 (unsigned char *) global_system_variables.lc_time_names->name :
1698
 
                 (unsigned char *) session->variables.lc_time_names->name;
 
2645
                 (uchar *) global_system_variables.lc_time_names->name :
 
2646
                 (uchar *) thd->variables.lc_time_names->name;
1699
2647
}
1700
2648
 
1701
2649
 
1702
 
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
 
2650
void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type)
1703
2651
{
1704
2652
  if (type == OPT_GLOBAL)
1705
2653
    global_system_variables.lc_time_names= my_default_lc_time_names;
1706
2654
  else
1707
 
    session->variables.lc_time_names= global_system_variables.lc_time_names;
 
2655
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
1708
2656
}
1709
2657
 
1710
2658
/*
1712
2660
 
1713
2661
  NOTES
1714
2662
    The argument to long query time is in seconds in decimal
1715
 
    which is converted to uint64_t integer holding microseconds for storage.
 
2663
    which is converted to ulonglong integer holding microseconds for storage.
1716
2664
    This is used for handling long_query_time
1717
2665
*/
1718
2666
 
1719
 
bool sys_var_microseconds::update(Session *session, set_var *var)
 
2667
bool sys_var_microseconds::update(THD *thd, set_var *var)
1720
2668
{
1721
2669
  double num= var->value->val_real();
1722
 
  int64_t microseconds;
 
2670
  longlong microseconds;
1723
2671
  if (num > (double) option_limits->max_value)
1724
2672
    num= (double) option_limits->max_value;
1725
2673
  if (num < (double) option_limits->min_value)
1726
2674
    num= (double) option_limits->min_value;
1727
 
  microseconds= (int64_t) (num * 1000000.0 + 0.5);
 
2675
  microseconds= (longlong) (num * 1000000.0 + 0.5);
1728
2676
  if (var->type == OPT_GLOBAL)
1729
2677
  {
1730
2678
    pthread_mutex_lock(&LOCK_global_system_variables);
1732
2680
    pthread_mutex_unlock(&LOCK_global_system_variables);
1733
2681
  }
1734
2682
  else
1735
 
    session->variables.*offset= microseconds;
 
2683
    thd->variables.*offset= microseconds;
1736
2684
  return 0;
1737
2685
}
1738
2686
 
1739
2687
 
1740
 
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
 
2688
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
1741
2689
{
1742
 
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
 
2690
  longlong microseconds= (longlong) (option_limits->def_value * 1000000.0);
1743
2691
  if (type == OPT_GLOBAL)
1744
2692
  {
1745
2693
    pthread_mutex_lock(&LOCK_global_system_variables);
1747
2695
    pthread_mutex_unlock(&LOCK_global_system_variables);
1748
2696
  }
1749
2697
  else
1750
 
    session->variables.*offset= microseconds;
 
2698
    thd->variables.*offset= microseconds;
1751
2699
}
1752
2700
 
1753
2701
 
1754
 
unsigned char *sys_var_microseconds::value_ptr(Session *session,
1755
 
                                               enum_var_type type,
1756
 
                                               const LEX_STRING *)
 
2702
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2703
                                          LEX_STRING *base __attribute__((__unused__)))
1757
2704
{
1758
 
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
2705
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
1759
2706
                                   global_system_variables.*offset :
1760
 
                                   session->variables.*offset) / 1000000.0;
1761
 
  return (unsigned char*) &session->tmp_double_value;
 
2707
                                   thd->variables.*offset) / 1000000.0;
 
2708
  return (uchar*) &thd->tmp_double_value;
1762
2709
}
1763
2710
 
1764
2711
 
1765
2712
/*
1766
 
  Functions to update session->options bits
 
2713
  Functions to update thd->options bits
1767
2714
*/
1768
2715
 
1769
 
static bool set_option_bit(Session *session, set_var *var)
 
2716
static bool set_option_bit(THD *thd, set_var *var)
1770
2717
{
1771
 
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
1772
 
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
1773
 
    session->options&= ~sys_var->bit_flag;
 
2718
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
 
2719
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
 
2720
    thd->options&= ~sys_var->bit_flag;
1774
2721
  else
1775
 
    session->options|= sys_var->bit_flag;
 
2722
    thd->options|= sys_var->bit_flag;
1776
2723
  return 0;
1777
2724
}
1778
2725
 
1779
2726
 
1780
 
static bool set_option_autocommit(Session *session, set_var *var)
 
2727
static bool set_option_autocommit(THD *thd, set_var *var)
1781
2728
{
1782
2729
  /* The test is negative as the flag we use is NOT autocommit */
1783
2730
 
1784
 
  uint64_t org_options= session->options;
 
2731
  ulonglong org_options= thd->options;
1785
2732
 
1786
 
  if (var->save_result.uint32_t_value != 0)
1787
 
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
 
2733
  if (var->save_result.ulong_value != 0)
 
2734
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
1788
2735
  else
1789
 
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
 
2736
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
1790
2737
 
1791
 
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
 
2738
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
1792
2739
  {
1793
2740
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
1794
2741
    {
1795
2742
      /* We changed to auto_commit mode */
1796
 
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
1797
 
      session->transaction.all.modified_non_trans_table= false;
1798
 
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
1799
 
      if (ha_commit(session))
 
2743
      thd->options&= ~(ulonglong) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2744
      thd->transaction.all.modified_non_trans_table= false;
 
2745
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
2746
      if (ha_commit(thd))
1800
2747
        return 1;
1801
2748
    }
1802
2749
    else
1803
2750
    {
1804
 
      session->transaction.all.modified_non_trans_table= false;
1805
 
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
2751
      thd->transaction.all.modified_non_trans_table= false;
 
2752
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
1806
2753
    }
1807
2754
  }
1808
2755
  return 0;
1809
2756
}
1810
2757
 
1811
 
static int check_pseudo_thread_id(Session *, set_var *var)
1812
 
{
1813
 
  var->save_result.uint64_t_value= var->value->val_int();
1814
 
  return 0;
1815
 
}
1816
 
 
1817
 
static unsigned char *get_warning_count(Session *session)
1818
 
{
1819
 
  session->sys_var_tmp.uint32_t_value=
1820
 
    (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
1821
 
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
1822
 
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
1823
 
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
1824
 
}
1825
 
 
1826
 
static unsigned char *get_error_count(Session *session)
1827
 
{
1828
 
  session->sys_var_tmp.uint32_t_value=
1829
 
    session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
1830
 
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
 
2758
static int check_log_update(THD *thd __attribute__((__unused__)),
 
2759
                            set_var *var __attribute__((__unused__)))
 
2760
{
 
2761
  return 0;
 
2762
}
 
2763
 
 
2764
static bool set_log_update(THD *thd __attribute__((__unused__)),
 
2765
                           set_var *var __attribute__((__unused__)))
 
2766
{
 
2767
  /*
 
2768
    The update log is not supported anymore since 5.0.
 
2769
    See sql/mysqld.cc/, comments in function init_server_components() for an
 
2770
    explaination of the different warnings we send below
 
2771
  */
 
2772
 
 
2773
  if (opt_sql_bin_update)
 
2774
  {
 
2775
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2776
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
 
2777
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
 
2778
  }
 
2779
  else
 
2780
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 
2781
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
 
2782
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
 
2783
  set_option_bit(thd, var);
 
2784
  return 0;
 
2785
}
 
2786
 
 
2787
 
 
2788
static int check_pseudo_thread_id(THD *thd __attribute__((__unused__)),
 
2789
                                  set_var *var)
 
2790
{
 
2791
  var->save_result.ulonglong_value= var->value->val_int();
 
2792
  return 0;
 
2793
}
 
2794
 
 
2795
static uchar *get_warning_count(THD *thd)
 
2796
{
 
2797
  thd->sys_var_tmp.long_value=
 
2798
    (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] +
 
2799
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] +
 
2800
     thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]);
 
2801
  return (uchar*) &thd->sys_var_tmp.long_value;
 
2802
}
 
2803
 
 
2804
static uchar *get_error_count(THD *thd)
 
2805
{
 
2806
  thd->sys_var_tmp.long_value= 
 
2807
    thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR];
 
2808
  return (uchar*) &thd->sys_var_tmp.long_value;
1831
2809
}
1832
2810
 
1833
2811
 
1836
2814
 
1837
2815
  This is necessary because if the user does not specify a temporary
1838
2816
  directory via the command line, one is chosen based on the environment
1839
 
  or system defaults.  But we can't just always use drizzle_tmpdir, because
 
2817
  or system defaults.  But we can't just always use mysql_tmpdir, because
1840
2818
  that is actually a call to my_tmpdir() which cycles among possible
1841
2819
  temporary directories.
1842
2820
 
1843
 
  @param session                thread handle
 
2821
  @param thd            thread handle
1844
2822
 
1845
2823
  @retval
1846
2824
    ptr         pointer to NUL-terminated string
1847
2825
*/
1848
 
static unsigned char *get_tmpdir(Session *)
 
2826
static uchar *get_tmpdir(THD *thd __attribute__((__unused__)))
1849
2827
{
1850
 
  assert(drizzle_tmpdir);
1851
 
  return (unsigned char*)drizzle_tmpdir;
 
2828
  if (opt_mysql_tmpdir)
 
2829
    return (uchar *)opt_mysql_tmpdir;
 
2830
  return (uchar*)mysql_tmpdir;
1852
2831
}
1853
2832
 
1854
2833
/****************************************************************************
1871
2850
    ptr         pointer to option structure
1872
2851
*/
1873
2852
 
1874
 
static struct my_option *find_option(struct my_option *opt, const char *name)
 
2853
static struct my_option *find_option(struct my_option *opt, const char *name) 
1875
2854
{
1876
 
  uint32_t length=strlen(name);
 
2855
  uint length=strlen(name);
1877
2856
  for (; opt->name; opt++)
1878
2857
  {
1879
2858
    if (!getopt_compare_strings(opt->name, name, length) &&
1890
2869
}
1891
2870
 
1892
2871
 
 
2872
/**
 
2873
  Return variable name and length for hashing of variables.
 
2874
*/
 
2875
 
 
2876
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
 
2877
                                 my_bool first __attribute__((__unused__)))
 
2878
{
 
2879
  *length= var->name_length;
 
2880
  return (uchar*) var->name;
 
2881
}
 
2882
 
 
2883
 
1893
2884
/*
1894
2885
  Add variables to the dynamic hash of system variables
1895
 
 
 
2886
  
1896
2887
  SYNOPSIS
1897
2888
    mysql_add_sys_var_chain()
1898
2889
    first       Pointer to first system variable to add
1899
2890
    long_opt    (optional)command line arguments may be tied for limit checks.
1900
 
 
 
2891
  
1901
2892
  RETURN VALUES
1902
2893
    0           SUCCESS
1903
2894
    otherwise   FAILURE
1907
2898
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
1908
2899
{
1909
2900
  sys_var *var;
 
2901
  
1910
2902
  /* A write lock should be held on LOCK_system_variables_hash */
1911
 
 
 
2903
  
1912
2904
  for (var= first; var; var= var->next)
1913
2905
  {
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();
1920
 
 
1921
 
    /* this fails if there is a conflicting variable name. */
1922
 
    if (system_variable_hash.count(var_name) == 0)
1923
 
    {
1924
 
      system_variable_hash[var_name]= var;
1925
 
    } 
1926
 
    else
1927
 
    {
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
 
      }
1940
 
      return 1;
1941
 
    }
 
2906
    var->name_length= strlen(var->name);
 
2907
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
 
2908
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
 
2909
      goto error;
1942
2910
    if (long_options)
1943
2911
      var->option_limits= find_option(long_options, var->name);
1944
2912
  }
1945
2913
  return 0;
1946
2914
 
 
2915
error:
 
2916
  for (; first != var; first= first->next)
 
2917
    hash_delete(&system_variable_hash, (uchar*) first);
 
2918
  return 1;
1947
2919
}
1948
 
 
1949
 
 
 
2920
 
 
2921
 
1950
2922
/*
1951
2923
  Remove variables to the dynamic hash of system variables
1952
 
 
 
2924
   
1953
2925
  SYNOPSIS
1954
2926
    mysql_del_sys_var_chain()
1955
2927
    first       Pointer to first system variable to remove
1956
 
 
 
2928
   
1957
2929
  RETURN VALUES
1958
2930
    0           SUCCESS
1959
2931
    otherwise   FAILURE
1960
2932
*/
1961
 
 
 
2933
 
1962
2934
int mysql_del_sys_var_chain(sys_var *first)
1963
2935
{
1964
2936
  int result= 0;
1965
 
  string var_name;
1966
 
 
 
2937
 
1967
2938
  /* A write lock should be held on LOCK_system_variables_hash */
 
2939
   
1968
2940
  for (sys_var *var= first; var; var= var->next)
1969
 
  {
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);
1974
 
  }
 
2941
    result|= hash_delete(&system_variable_hash, (uchar*) var);
1975
2942
 
1976
2943
  return result;
1977
2944
}
1978
 
 
1979
 
 
1980
 
 
 
2945
 
 
2946
 
 
2947
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
 
2948
{
 
2949
  return strcmp(a->name, b->name);
 
2950
}
 
2951
 
 
2952
 
1981
2953
/*
1982
2954
  Constructs an array of system variables for display to the user.
1983
 
 
 
2955
  
1984
2956
  SYNOPSIS
1985
2957
    enumerate_sys_vars()
1986
 
    session         current thread
 
2958
    thd         current thread
1987
2959
    sorted      If TRUE, the system variables should be sorted
1988
 
 
 
2960
  
1989
2961
  RETURN VALUES
1990
2962
    pointer     Array of SHOW_VAR elements for display
1991
2963
    NULL        FAILURE
1992
2964
*/
1993
2965
 
1994
 
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
 
2966
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
1995
2967
{
 
2968
  int count= system_variable_hash.records, i;
1996
2969
  int fixed_count= fixed_show_vars.elements;
1997
 
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
1998
 
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
 
2970
  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
 
2971
  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
1999
2972
 
2000
2973
  if (result)
2001
2974
  {
2002
2975
    SHOW_VAR *show= result + fixed_count;
2003
2976
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
2004
2977
 
2005
 
    map<string, sys_var *>::iterator iter;
2006
 
    for(iter= system_variable_hash.begin();
2007
 
        iter != system_variable_hash.end();
2008
 
        iter++)
 
2978
    for (i= 0; i < count; i++)
2009
2979
    {
2010
 
      sys_var *var= (*iter).second;
 
2980
      sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
2011
2981
      show->name= var->name;
2012
2982
      show->value= (char*) var;
2013
2983
      show->type= SHOW_SYS;
2014
2984
      show++;
2015
2985
    }
2016
2986
 
 
2987
    /* sort into order */
 
2988
    if (sorted)
 
2989
      my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
 
2990
               (qsort_cmp) show_cmp);
 
2991
    
2017
2992
    /* make last element empty */
2018
 
    memset(show, 0, sizeof(SHOW_VAR));
 
2993
    bzero(show, sizeof(SHOW_VAR));
2019
2994
  }
2020
2995
  return result;
2021
2996
}
2022
2997
 
2023
2998
 
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
 
 
2039
2999
/*
2040
3000
  Initialize the system variables
2041
 
 
 
3001
  
2042
3002
  SYNOPSIS
2043
3003
    set_var_init()
2044
 
 
 
3004
  
2045
3005
  RETURN VALUES
2046
3006
    0           SUCCESS
2047
3007
    otherwise   FAILURE
2049
3009
 
2050
3010
int set_var_init()
2051
3011
{
2052
 
  uint32_t count= 0;
2053
 
 
 
3012
  uint count= 0;
 
3013
  
2054
3014
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2055
3015
 
2056
3016
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
2060
3020
  fixed_show_vars.elements= FIXED_VARS_SIZE;
2061
3021
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2062
3022
 
 
3023
  if (hash_init(&system_variable_hash, system_charset_info, count, 0,
 
3024
                0, (hash_get_key) get_sys_var_length, 0, HASH_UNIQUE))
 
3025
    goto error;
 
3026
 
2063
3027
  vars.last->next= NULL;
2064
3028
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2065
3029
    goto error;
2066
3030
 
 
3031
  /*
 
3032
    Special cases
 
3033
    Needed because MySQL can't find the limits for a variable it it has
 
3034
    a different name than the command line option.
 
3035
    As these variables are deprecated, this code will disappear soon...
 
3036
  */
 
3037
  sys_sql_max_join_size.option_limits= sys_max_join_size.option_limits;
 
3038
 
2067
3039
  return(0);
2068
3040
 
2069
3041
error:
2074
3046
 
2075
3047
void set_var_free()
2076
3048
{
 
3049
  hash_free(&system_variable_hash);
2077
3050
  delete_dynamic(&fixed_show_vars);
2078
3051
}
2079
3052
 
2080
3053
 
2081
3054
/*
2082
3055
  Add elements to the dynamic list of read-only system variables.
2083
 
 
 
3056
  
2084
3057
  SYNOPSIS
2085
3058
    mysql_append_static_vars()
2086
3059
    show_vars   Pointer to start of array
2087
3060
    count       Number of elements
2088
 
 
 
3061
  
2089
3062
  RETURN VALUES
2090
3063
    0           SUCCESS
2091
3064
    otherwise   FAILURE
2092
3065
*/
2093
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
 
3066
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
2094
3067
{
2095
3068
  for (; count > 0; count--, show_vars++)
2096
 
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
 
3069
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
2097
3070
      return 1;
2098
3071
  return 0;
2099
3072
}
2113
3086
    0           Unknown variable (error message is given)
2114
3087
*/
2115
3088
 
2116
 
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
 
3089
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
2117
3090
{
 
3091
  sys_var *var;
 
3092
 
2118
3093
  /*
2119
3094
    This function is only called from the sql_plugin.cc.
2120
3095
    A lock on LOCK_system_variable_hash should be held
2121
3096
  */
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())
2127
 
  {
2128
 
    if (no_error)
2129
 
    {
2130
 
      return NULL;
2131
 
    }
2132
 
    else
2133
 
    {
2134
 
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2135
 
      return NULL;
2136
 
    }
2137
 
  }
 
3097
  var= (sys_var*) hash_search(&system_variable_hash,
 
3098
                              (uchar*) str, length ? length : strlen(str));
 
3099
  if (!(var || no_error))
 
3100
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
2138
3101
 
2139
 
  return (*result_iter).second;
 
3102
  return var;
2140
3103
}
2141
3104
 
2142
3105
 
2149
3112
  This should ensure that in all normal cases none all or variables are
2150
3113
  updated.
2151
3114
 
2152
 
  @param Session                Thread id
 
3115
  @param THD            Thread id
2153
3116
  @param var_list       List of variables to update
2154
3117
 
2155
3118
  @retval
2160
3123
    -1  ERROR, message not sent
2161
3124
*/
2162
3125
 
2163
 
int sql_set_variables(Session *session, List<set_var_base> *var_list)
 
3126
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
2164
3127
{
2165
3128
  int error;
2166
3129
  List_iterator_fast<set_var_base> it(*var_list);
2168
3131
  set_var_base *var;
2169
3132
  while ((var=it++))
2170
3133
  {
2171
 
    if ((error= var->check(session)))
 
3134
    if ((error= var->check(thd)))
2172
3135
      goto err;
2173
3136
  }
2174
 
  if (!(error= test(session->is_error())))
 
3137
  if (!(error= test(thd->is_error())))
2175
3138
  {
2176
3139
    it.rewind();
2177
3140
    while ((var= it++))
2178
 
      error|= var->update(session);         // Returns 0, -1 or 1
 
3141
      error|= var->update(thd);         // Returns 0, -1 or 1
2179
3142
  }
2180
3143
 
2181
3144
err:
2182
 
  free_underlaid_joins(session, &session->lex->select_lex);
 
3145
  free_underlaid_joins(thd, &thd->lex->select_lex);
2183
3146
  return(error);
2184
3147
}
2185
3148
 
2186
3149
 
 
3150
/**
 
3151
  Say if all variables set by a SET support the ONE_SHOT keyword
 
3152
  (currently, only character set and collation do; later timezones
 
3153
  will).
 
3154
 
 
3155
  @param var_list       List of variables to update
 
3156
 
 
3157
  @note
 
3158
    It has a "not_" because it makes faster tests (no need to "!")
 
3159
 
 
3160
  @retval
 
3161
    0   all variables of the list support ONE_SHOT
 
3162
  @retval
 
3163
    1   at least one does not support ONE_SHOT
 
3164
*/
 
3165
 
 
3166
bool not_all_support_one_shot(List<set_var_base> *var_list)
 
3167
{
 
3168
  List_iterator_fast<set_var_base> it(*var_list);
 
3169
  set_var_base *var;
 
3170
  while ((var= it++))
 
3171
  {
 
3172
    if (var->no_support_one_shot())
 
3173
      return 1;
 
3174
  }
 
3175
  return 0;
 
3176
}
 
3177
 
 
3178
 
2187
3179
/*****************************************************************************
2188
3180
  Functions to handle SET mysql_internal_variable=const_expr
2189
3181
*****************************************************************************/
2190
3182
 
2191
 
int set_var::check(Session *session)
 
3183
int set_var::check(THD *thd)
2192
3184
{
2193
3185
  if (var->is_readonly())
2194
3186
  {
2213
3205
  }
2214
3206
 
2215
3207
  if ((!value->fixed &&
2216
 
       value->fix_fields(session, &value)) || value->check_cols(1))
 
3208
       value->fix_fields(thd, &value)) || value->check_cols(1))
2217
3209
    return -1;
2218
3210
  if (var->check_update_type(value->result_type()))
2219
3211
  {
2220
3212
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
2221
3213
    return -1;
2222
3214
  }
2223
 
  return var->check(session, this) ? -1 : 0;
 
3215
  return var->check(thd, this) ? -1 : 0;
2224
3216
}
2225
3217
 
2226
3218
/**
2227
3219
  Update variable
2228
3220
 
2229
 
  @param   session    thread handler
 
3221
  @param   thd    thread handler
2230
3222
  @returns 0|1    ok or ERROR
2231
3223
 
2232
3224
  @note ERROR can be only due to abnormal operations involving
2235
3227
  Consider set_var::check() method if there is a need to return
2236
3228
  an error due to logics.
2237
3229
*/
2238
 
int set_var::update(Session *session)
 
3230
int set_var::update(THD *thd)
2239
3231
{
2240
3232
  if (!value)
2241
 
    var->set_default(session, type);
2242
 
  else if (var->update(session, this))
 
3233
    var->set_default(thd, type);
 
3234
  else if (var->update(thd, this))
2243
3235
    return -1;                          // should never happen
2244
3236
  if (var->after_update)
2245
 
    (*var->after_update)(session, type);
 
3237
    (*var->after_update)(thd, type);
2246
3238
  return 0;
2247
3239
}
2248
3240
 
2251
3243
  Functions to handle SET @user_variable=const_expr
2252
3244
*****************************************************************************/
2253
3245
 
2254
 
int set_var_user::check(Session *session)
 
3246
int set_var_user::check(THD *thd)
2255
3247
{
2256
3248
  /*
2257
3249
    Item_func_set_user_var can't substitute something else on its place =>
2258
3250
    0 can be passed as last argument (reference on item)
2259
3251
  */
2260
 
  return (user_var_item->fix_fields(session, (Item**) 0) ||
 
3252
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
2261
3253
          user_var_item->check(0)) ? -1 : 0;
2262
3254
}
2263
3255
 
2264
3256
 
2265
 
int set_var_user::update(Session *)
 
3257
int set_var_user::update(THD *thd __attribute__((__unused__)))
2266
3258
{
2267
3259
  if (user_var_item->update())
2268
3260
  {
2279
3271
 
2280
3272
/* Based upon sys_var::check_enum() */
2281
3273
 
2282
 
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
 
3274
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
2283
3275
{
2284
3276
  char buff[STRING_BUFFER_USUAL_SIZE];
2285
3277
  const char *value;
2286
 
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
 
3278
  String str(buff, sizeof(buff), &my_charset_latin1), *res;
2287
3279
 
2288
 
  var->save_result.storage_engine= NULL;
 
3280
  var->save_result.plugin= NULL;
2289
3281
  if (var->value->result_type() == STRING_RESULT)
2290
3282
  {
2291
3283
    LEX_STRING engine_name;
2292
 
    StorageEngine *engine;
 
3284
    handlerton *hton;
2293
3285
    if (!(res=var->value->val_str(&str)) ||
2294
3286
        !(engine_name.str= (char *)res->ptr()) ||
2295
3287
        !(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))
 
3288
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
 
3289
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
 
3290
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
2299
3291
    {
2300
3292
      value= res ? res->c_ptr() : "NULL";
2301
3293
      goto err;
2310
3302
}
2311
3303
 
2312
3304
 
2313
 
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
2314
 
                                                         enum_var_type type,
2315
 
                                                         const LEX_STRING *)
 
3305
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
3306
                                             LEX_STRING *base __attribute__((__unused__)))
2316
3307
{
2317
 
  unsigned char* result;
2318
 
  string engine_name;
2319
 
  StorageEngine *engine= session->variables.*offset;
2320
 
  if (type == OPT_GLOBAL)
2321
 
    engine= global_system_variables.*offset;
2322
 
  engine_name= engine->getName();
2323
 
  result= (unsigned char *) session->strmake(engine_name.c_str(),
2324
 
                                             engine_name.size());
 
3308
  uchar* result;
 
3309
  handlerton *hton;
 
3310
  LEX_STRING *engine_name;
 
3311
  plugin_ref plugin= thd->variables.*offset;
 
3312
  if (type == OPT_GLOBAL)
 
3313
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
 
3314
  hton= plugin_data(plugin, handlerton*);
 
3315
  engine_name= &hton2plugin[hton->slot]->name;
 
3316
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
 
3317
  if (type == OPT_GLOBAL)
 
3318
    plugin_unlock(thd, plugin);
2325
3319
  return result;
2326
3320
}
2327
3321
 
2328
3322
 
2329
 
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
 
3323
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
2330
3324
{
2331
 
  StorageEngine *old_value, *new_value, **value;
 
3325
  plugin_ref old_value, new_value, *value;
2332
3326
  if (type == OPT_GLOBAL)
2333
3327
  {
2334
3328
    value= &(global_system_variables.*offset);
2335
 
    new_value= myisam_engine;
 
3329
    new_value= ha_lock_engine(NULL, myisam_hton);
2336
3330
  }
2337
3331
  else
2338
3332
  {
2339
 
    value= &(session->variables.*offset);
2340
 
    new_value= global_system_variables.*offset;
 
3333
    value= &(thd->variables.*offset);
 
3334
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
2341
3335
  }
2342
3336
  assert(new_value);
2343
3337
  old_value= *value;
2344
3338
  *value= new_value;
 
3339
  plugin_unlock(NULL, old_value);
2345
3340
}
2346
3341
 
2347
3342
 
2348
 
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
 
3343
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
2349
3344
{
2350
 
  StorageEngine **value= &(global_system_variables.*offset), *old_value;
 
3345
  plugin_ref *value= &(global_system_variables.*offset), old_value;
2351
3346
   if (var->type != OPT_GLOBAL)
2352
 
     value= &(session->variables.*offset);
 
3347
     value= &(thd->variables.*offset);
2353
3348
  old_value= *value;
2354
 
  if (old_value != var->save_result.storage_engine)
 
3349
  if (old_value != var->save_result.plugin)
2355
3350
  {
2356
 
    *value= var->save_result.storage_engine;
 
3351
    *value= my_plugin_lock(NULL, &var->save_result.plugin);
 
3352
    plugin_unlock(NULL, old_value);
2357
3353
  }
2358
3354
  return 0;
2359
3355
}
2360
3356
 
2361
3357
bool
2362
 
sys_var_session_optimizer_switch::
2363
 
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
 
3358
sys_var_thd_optimizer_switch::
 
3359
symbolic_mode_representation(THD *thd, ulonglong val, LEX_STRING *rep)
2364
3360
{
2365
3361
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2366
 
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
 
3362
  String tmp(buff, sizeof(buff), &my_charset_latin1);
2367
3363
 
2368
3364
  tmp.length(0);
2369
3365
 
2370
 
  for (uint32_t i= 0; val; val>>= 1, i++)
 
3366
  for (uint i= 0; val; val>>= 1, i++)
2371
3367
  {
2372
3368
    if (val & 1)
2373
3369
    {
2380
3376
  if (tmp.length())
2381
3377
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
2382
3378
 
2383
 
  rep->str= session->strmake(tmp.ptr(), tmp.length());
 
3379
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
2384
3380
 
2385
3381
  rep->length= rep->str ? tmp.length() : 0;
2386
3382
 
2388
3384
}
2389
3385
 
2390
3386
 
2391
 
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
2392
 
                                                           enum_var_type type,
2393
 
                                                           const LEX_STRING *)
 
3387
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3388
                                               LEX_STRING *base __attribute__((__unused__)))
2394
3389
{
2395
3390
  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;
 
3391
  ulonglong val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
3392
                  thd->variables.*offset);
 
3393
  (void) symbolic_mode_representation(thd, val, &opts);
 
3394
  return (uchar *) opts.str;
2400
3395
}
2401
3396
 
2402
3397
 
2403
 
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
 
3398
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
2404
3399
{
2405
3400
  if (type == OPT_GLOBAL)
2406
3401
    global_system_variables.*offset= 0;
2407
3402
  else
2408
 
    session->variables.*offset= global_system_variables.*offset;
 
3403
    thd->variables.*offset= global_system_variables.*offset;
2409
3404
}
2410
3405
 
2411
3406
 
2413
3408
  Named list handling
2414
3409
****************************************************************************/
2415
3410
 
2416
 
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
 
3411
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
2417
3412
                NAMED_LIST **found)
2418
3413
{
2419
3414
  I_List_iterator<NAMED_LIST> it(*list);
2432
3427
 
2433
3428
 
2434
3429
void delete_elements(I_List<NAMED_LIST> *list,
2435
 
                     void (*free_element)(const char *name, unsigned char*))
 
3430
                     void (*free_element)(const char *name, uchar*))
2436
3431
{
2437
3432
  NAMED_LIST *element;
2438
3433
  while ((element= list->get()))
2439
3434
  {
2440
 
    (*free_element)(element->name.c_str(), element->data);
 
3435
    (*free_element)(element->name, element->data);
2441
3436
    delete element;
2442
3437
  }
2443
3438
  return;
2446
3441
 
2447
3442
/* Key cache functions */
2448
3443
 
2449
 
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
 
3444
static KEY_CACHE *create_key_cache(const char *name, uint length)
2450
3445
{
2451
3446
  KEY_CACHE *key_cache;
2452
 
 
2453
 
  if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
 
3447
  
 
3448
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
 
3449
                                             MYF(MY_ZEROFILL | MY_WME))))
2454
3450
  {
2455
 
    memset(key_cache, 0, sizeof(KEY_CACHE));
2456
 
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
 
3451
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
2457
3452
    {
2458
 
      free((char*) key_cache);
 
3453
      my_free((char*) key_cache, MYF(0));
2459
3454
      key_cache= 0;
2460
3455
    }
2461
3456
    else
2475
3470
}
2476
3471
 
2477
3472
 
2478
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
 
3473
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
2479
3474
{
2480
3475
  LEX_STRING key_cache_name;
2481
3476
  KEY_CACHE *key_cache;
2490
3485
}
2491
3486
 
2492
3487
 
2493
 
void free_key_cache(const char *, KEY_CACHE *key_cache)
 
3488
void free_key_cache(const char *name __attribute__((__unused__)),
 
3489
                    KEY_CACHE *key_cache)
2494
3490
{
2495
3491
  ha_end_key_cache(key_cache);
2496
 
  free((char*) key_cache);
 
3492
  my_free((char*) key_cache, MYF(0));
2497
3493
}
2498
3494
 
2499
3495
 
2505
3501
  while ((element= it++))
2506
3502
  {
2507
3503
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
2508
 
    func(element->name.c_str(), key_cache);
 
3504
    func(element->name, key_cache);
2509
3505
  }
2510
3506
  return 0;
2511
3507
}
2512
3508
 
 
3509
 
 
3510
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
 
3511
{
 
3512
  bool result;
 
3513
 
 
3514
  /* Prevent self dead-lock */
 
3515
  if (thd->locked_tables || thd->active_transaction())
 
3516
  {
 
3517
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
 
3518
    return(true);
 
3519
  }
 
3520
 
 
3521
  if (thd->global_read_lock)
 
3522
  {
 
3523
    /*
 
3524
      This connection already holds the global read lock.
 
3525
      This can be the case with:
 
3526
      - FLUSH TABLES WITH READ LOCK
 
3527
      - SET GLOBAL READ_ONLY = 1
 
3528
    */
 
3529
    result= sys_var_bool_ptr::update(thd, var);
 
3530
    return(result);
 
3531
  }
 
3532
 
 
3533
  /*
 
3534
    Perform a 'FLUSH TABLES WITH READ LOCK'.
 
3535
    This is a 3 step process:
 
3536
    - [1] lock_global_read_lock()
 
3537
    - [2] close_cached_tables()
 
3538
    - [3] make_global_read_lock_block_commit()
 
3539
    [1] prevents new connections from obtaining tables locked for write.
 
3540
    [2] waits until all existing connections close their tables.
 
3541
    [3] prevents transactions from being committed.
 
3542
  */
 
3543
 
 
3544
  if (lock_global_read_lock(thd))
 
3545
    return(true);
 
3546
 
 
3547
  /*
 
3548
    This call will be blocked by any connection holding a READ or WRITE lock.
 
3549
    Ideally, we want to wait only for pending WRITE locks, but since:
 
3550
    con 1> LOCK TABLE T FOR READ;
 
3551
    con 2> LOCK TABLE T FOR WRITE; (blocked by con 1)
 
3552
    con 3> SET GLOBAL READ ONLY=1; (blocked by con 2)
 
3553
    can cause to wait on a read lock, it's required for the client application
 
3554
    to unlock everything, and acceptable for the server to wait on all locks.
 
3555
  */
 
3556
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3557
    goto end_with_read_lock;
 
3558
 
 
3559
  if ((result= make_global_read_lock_block_commit(thd)) == true)
 
3560
    goto end_with_read_lock;
 
3561
 
 
3562
  /* Change the opt_readonly system variable, safe because the lock is held */
 
3563
  result= sys_var_bool_ptr::update(thd, var);
 
3564
 
 
3565
end_with_read_lock:
 
3566
  /* Release the lock */
 
3567
  unlock_global_read_lock(thd);
 
3568
  return(result);
 
3569
}
 
3570
 
2513
3571
/****************************************************************************
2514
3572
  Used templates
2515
3573
****************************************************************************/