~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2009-03-27 22:55:28 UTC
  • mto: This revision was merged to the branch mainline in revision 968.
  • Revision ID: brian@tangent.org-20090327225528-8y76cfx8a4oemqv9
Remove ref_count

Show diffs side-by-side

added added

removed removed

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