~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2009-05-11 17:50:22 UTC
  • Revision ID: brian@gaz-20090511175022-y35q9ky6uh9ldcjt
Replacing Sun employee copyright headers (aka... anything done by a Sun
employee is copyright by Sun).

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
 
#include <storage/myisam/myisam.h>
54
 
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
 
56
#include <plugin/myisam/myisam.h>
 
57
#include <drizzled/error.h>
 
58
#include <drizzled/gettext.h>
 
59
#include <drizzled/tztime.h>
 
60
#include <drizzled/data_home.h>
 
61
#include <drizzled/set_var.h>
 
62
#include <drizzled/session.h>
 
63
#include <drizzled/sql_base.h>
 
64
#include <drizzled/lock.h>
 
65
#include <drizzled/item/uint.h>
 
66
#include <drizzled/item/null.h>
 
67
#include <drizzled/item/float.h>
 
68
 
 
69
#include <map>
 
70
#include <algorithm>
 
71
 
 
72
using namespace std;
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 set_option_bit(Session *session, set_var *var);
 
96
static bool set_option_autocommit(Session *session, set_var *var);
 
97
static int  check_pseudo_thread_id(Session *session, set_var *var);
 
98
static int check_tx_isolation(Session *session, set_var *var);
 
99
static void fix_tx_isolation(Session *session, enum_var_type type);
 
100
static int check_completion_type(Session *session, set_var *var);
 
101
static void fix_completion_type(Session *session, enum_var_type type);
 
102
static void fix_net_read_timeout(Session *session, enum_var_type type);
 
103
static void fix_net_write_timeout(Session *session, enum_var_type type);
 
104
static void fix_net_retry_count(Session *session, enum_var_type type);
 
105
static void fix_max_join_size(Session *session, enum_var_type type);
 
106
static void fix_session_mem_root(Session *session, enum_var_type type);
 
107
static void fix_trans_mem_root(Session *session, enum_var_type type);
 
108
static void fix_server_id(Session *session, enum_var_type type);
 
109
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
 
110
static bool get_unsigned32(Session *session, set_var *var);
 
111
static bool get_unsigned64(Session *session, set_var *var);
 
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
113
113
                          const char *name, int64_t val);
114
114
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);
 
115
static unsigned char *get_error_count(Session *session);
 
116
static unsigned char *get_warning_count(Session *session);
 
117
static unsigned char *get_tmpdir(Session *session);
118
118
 
119
119
/*
120
120
  Variable definition list
128
128
 
129
129
static sys_var_chain vars = { NULL, NULL };
130
130
 
131
 
static sys_var_thd_ulong
 
131
static sys_var_session_uint64_t
132
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
133
                             &SV::auto_increment_increment, NULL, NULL,
134
134
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
135
 
static sys_var_thd_ulong
 
135
static sys_var_session_uint64_t
136
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
137
137
                          &SV::auto_increment_offset, NULL, NULL,
138
138
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
139
139
 
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);
 
140
static sys_var_const_str       sys_basedir(&vars, "basedir", drizzle_home);
 
141
static sys_var_session_uint64_t sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
142
                                                          &SV::bulk_insert_buff_size);
 
143
static sys_var_session_uint32_t sys_completion_type(&vars, "completion_type",
 
144
                                                    &SV::completion_type,
 
145
                                                    check_completion_type,
 
146
                                                    fix_completion_type);
180
147
static sys_var_collation_sv
181
148
sys_collation_database(&vars, "collation_database", &SV::collation_database,
182
149
                       &default_charset_info,
185
152
sys_collation_server(&vars, "collation_server", &SV::collation_server,
186
153
                     &default_charset_info,
187
154
                     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);
 
155
static sys_var_uint32_t_ptr     sys_connect_timeout(&vars, "connect_timeout",
 
156
                                                &connect_timeout);
 
157
static sys_var_const_str       sys_datadir(&vars, "datadir", drizzle_real_data_home);
191
158
static sys_var_enum             sys_delay_key_write(&vars, "delay_key_write",
192
159
                                            &delay_key_write_options,
193
160
                                            &delay_key_write_typelib,
194
161
                                            fix_delay_key_write);
195
162
 
196
 
static sys_var_long_ptr sys_expire_logs_days(&vars, "expire_logs_days",
197
 
                                             &expire_logs_days);
198
163
static sys_var_bool_ptr sys_flush(&vars, "flush", &myisam_flush);
199
 
sys_var_str             sys_init_connect(&vars, "init_connect", 0,
200
 
                                         sys_update_init_connect,
201
 
                                         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);
 
164
static sys_var_session_uint64_t sys_join_buffer_size(&vars, "join_buffer_size",
 
165
                                                     &SV::join_buff_size);
209
166
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",
 
167
static sys_var_key_cache_uint32_t  sys_key_cache_block_size(&vars, "key_cache_block_size",
 
168
                                                        offsetof(KEY_CACHE,
 
169
                                                                 param_block_size));
 
170
static sys_var_key_cache_uint32_t       sys_key_cache_division_limit(&vars, "key_cache_division_limit",
 
171
                                                           offsetof(KEY_CACHE,
 
172
                                                                    param_division_limit));
 
173
static sys_var_key_cache_uint32_t  sys_key_cache_age_threshold(&vars, "key_cache_age_threshold",
 
174
                                                           offsetof(KEY_CACHE,
 
175
                                                                    param_age_threshold));
 
176
static sys_var_session_uint32_t sys_max_allowed_packet(&vars, "max_allowed_packet",
 
177
                                                       &SV::max_allowed_packet);
 
178
static sys_var_uint64_t_ptr     sys_max_connect_errors(&vars, "max_connect_errors",
 
179
                                               &max_connect_errors);
 
180
static sys_var_session_uint64_t sys_max_error_count(&vars, "max_error_count",
 
181
                                                  &SV::max_error_count);
 
182
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
 
183
                                                        &SV::max_heap_table_size);
 
184
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
246
185
                                              &SV::pseudo_thread_id,
247
 
                                              check_pseudo_thread_id, 0,
 
186
                                              0, check_pseudo_thread_id,
248
187
                                              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);
 
188
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
 
189
                                                  &SV::max_join_size,
 
190
                                                  fix_max_join_size);
 
191
static sys_var_session_uint64_t sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
192
                                                      &SV::max_seeks_for_key);
 
193
static sys_var_session_uint64_t   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
194
                                                               &SV::max_length_for_sort_data);
 
195
static sys_var_session_size_t   sys_max_sort_length(&vars, "max_sort_length",
 
196
                                                    &SV::max_sort_length);
 
197
static sys_var_session_uint64_t sys_max_tmp_tables(&vars, "max_tmp_tables",
 
198
                                                   &SV::max_tmp_tables);
 
199
static sys_var_uint64_t_ptr     sys_max_write_lock_count(&vars, "max_write_lock_count",
 
200
                                                 &max_write_lock_count);
 
201
static sys_var_session_uint64_t sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
202
                                                           &SV::min_examined_row_limit);
271
203
 
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);
 
204
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
205
                                                            &SV::myisam_stats_method,
 
206
                                                            &myisam_stats_method_typelib,
 
207
                                                            NULL);
 
208
static sys_var_session_uint32_t sys_net_buffer_length(&vars, "net_buffer_length",
 
209
                                                      &SV::net_buffer_length);
 
210
static sys_var_session_uint32_t sys_net_read_timeout(&vars, "net_read_timeout",
 
211
                                                     &SV::net_read_timeout,
 
212
                                                     0, fix_net_read_timeout);
 
213
static sys_var_session_uint32_t sys_net_write_timeout(&vars, "net_write_timeout",
 
214
                                                      &SV::net_write_timeout,
 
215
                                                      0, fix_net_write_timeout);
 
216
static sys_var_session_uint32_t sys_net_retry_count(&vars, "net_retry_count",
 
217
                                                    &SV::net_retry_count,
 
218
                                                    0, fix_net_retry_count);
290
219
/* 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);
 
220
static sys_var_session_bool sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
221
                                                      &SV::optimizer_prune_level);
 
222
static sys_var_session_uint32_t sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
223
                                                           &SV::optimizer_search_depth);
297
224
 
298
225
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
299
226
TYPELIB optimizer_use_mrr_typelib= {
301
228
  optimizer_use_mrr_names, NULL
302
229
};
303
230
 
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);
 
231
static sys_var_session_enum sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
232
                                                  &SV::optimizer_use_mrr,
 
233
                                                  &optimizer_use_mrr_typelib,
 
234
                                                  NULL);
 
235
 
 
236
static sys_var_session_uint64_t sys_preload_buff_size(&vars, "preload_buffer_size",
 
237
                                                      &SV::preload_buff_size);
 
238
static sys_var_session_uint32_t sys_read_buff_size(&vars, "read_buffer_size",
 
239
                                                   &SV::read_buff_size);
 
240
static sys_var_session_uint32_t sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 
241
                                                       &SV::read_rnd_buff_size);
 
242
static sys_var_session_uint32_t sys_div_precincrement(&vars, "div_precision_increment",
 
243
                                                      &SV::div_precincrement);
 
244
 
 
245
static sys_var_session_size_t   sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
246
                                                           &SV::range_alloc_block_size);
 
247
static sys_var_session_uint32_t sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
248
                                                           &SV::query_alloc_block_size,
 
249
                                                           false, fix_session_mem_root);
 
250
static sys_var_session_uint32_t sys_query_prealloc_size(&vars, "query_prealloc_size",
 
251
                                                        &SV::query_prealloc_size,
 
252
                                                        false, fix_session_mem_root);
 
253
static sys_var_readonly sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
 
254
static sys_var_session_uint32_t sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
255
                                                           &SV::trans_alloc_block_size,
 
256
                                                           false, fix_trans_mem_root);
 
257
static sys_var_session_uint32_t sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
258
                                                        &SV::trans_prealloc_size,
 
259
                                                        false, fix_trans_mem_root);
 
260
 
338
261
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
339
262
                                             &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);
 
263
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
 
264
                                           fix_server_id);
 
265
 
 
266
static sys_var_session_size_t   sys_sort_buffer(&vars, "sort_buffer_size",
 
267
                                                &SV::sortbuff_size);
354
268
/*
355
269
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
356
270
  even though it is written to the binlog, the slave ignores the
357
271
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
358
272
  master's (see log_event.cc: Query_log_event::do_apply_event()).
359
273
*/
360
 
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
361
 
                                     &SV::optimizer_switch);
 
274
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
275
                                                               &SV::optimizer_switch);
362
276
 
363
 
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
364
 
                                       &SV::table_plugin);
 
277
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
 
278
                                       &SV::storage_engine);
365
279
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
366
280
                                             system_time_zone);
367
 
static sys_var_long_ptr sys_table_def_size(&vars, "table_definition_cache",
 
281
static sys_var_uint64_t_ptr     sys_table_def_size(&vars, "table_definition_cache",
368
282
                                           &table_def_size);
369
 
static sys_var_long_ptr sys_table_cache_size(&vars, "table_open_cache",
 
283
static sys_var_uint64_t_ptr     sys_table_cache_size(&vars, "table_open_cache",
370
284
                                             &table_cache_size);
371
 
static sys_var_long_ptr sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
 
285
static sys_var_uint64_t_ptr     sys_table_lock_wait_timeout(&vars, "table_lock_wait_timeout",
372
286
                                                    &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",
 
287
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
 
288
                                             &SV::tx_isolation,
 
289
                                             &tx_isolation_typelib,
 
290
                                             fix_tx_isolation,
 
291
                                             check_tx_isolation);
 
292
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
383
293
                                           &SV::tmp_table_size);
384
294
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
385
295
static sys_var_const_str        sys_version(&vars, "version", server_version);
386
296
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
387
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
297
                                            COMPILATION_COMMENT);
388
298
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
389
299
                                                    MACHINE_TYPE);
390
300
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
391
301
                                               SYSTEM_TYPE);
392
 
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
393
 
                                             &SV::net_wait_timeout);
 
302
static sys_var_session_uint32_t sys_net_wait_timeout(&vars, "wait_timeout",
 
303
                                                     &SV::net_wait_timeout);
394
304
 
395
305
/* Condition pushdown to storage engine */
396
 
static sys_var_thd_bool
 
306
static sys_var_session_bool
397
307
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
398
308
                              &SV::engine_condition_pushdown);
399
309
 
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,
 
310
/* Variables that are bits in Session */
 
311
 
 
312
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
415
313
                               set_option_autocommit,
416
314
                               OPTION_NOT_AUTOCOMMIT,
417
315
                               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,
 
316
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
427
317
                                        set_option_bit,
428
318
                                        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,
 
319
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
434
320
                                         set_option_bit,
435
321
                                         OPTION_WARNINGS);
436
 
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
 
322
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
437
323
                                         set_option_bit,
438
324
                                         OPTION_SQL_NOTES);
439
 
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
 
325
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
440
326
                                         set_option_bit,
441
327
                                         OPTION_SAFE_UPDATES);
442
 
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
 
328
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
443
329
                                           set_option_bit,
444
330
                                           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,
 
331
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
449
332
                                               set_option_bit,
450
333
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
451
334
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
452
 
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
 
335
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
453
336
                                          set_option_bit,
454
337
                                          OPTION_RELAXED_UNIQUE_CHECKS,
455
338
                                          1,
456
339
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
457
340
/* Local state variables */
458
341
 
459
 
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
 
342
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
460
343
                                                 &SV::select_limit);
461
344
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
462
345
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
470
353
static sys_var_last_insert_id
471
354
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
472
355
 
473
 
static sys_var_thd_lc_time_names
 
356
static sys_var_session_lc_time_names
474
357
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
475
358
 
476
359
/*
492
375
  statement-based logging mode: t will be different on master and
493
376
  slave).
494
377
*/
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",
 
378
static sys_var_readonly sys_error_count(&vars, "error_count",
 
379
                                        OPT_SESSION,
 
380
                                        SHOW_INT,
 
381
                                        get_error_count);
 
382
static sys_var_readonly sys_warning_count(&vars, "warning_count",
 
383
                                          OPT_SESSION,
 
384
                                          SHOW_INT,
 
385
                                          get_warning_count);
 
386
 
 
387
sys_var_session_uint64_t sys_group_concat_max_len(&vars, "group_concat_max_len",
 
388
                                                  &SV::group_concat_max_len);
 
389
 
 
390
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
517
391
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
518
392
 
519
393
/* Global read-only variable containing hostname */
520
394
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
521
395
 
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", 
 
396
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create",
535
397
                                           &SV::keep_files_on_create);
536
398
/* Read only variables */
537
399
 
538
 
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
539
400
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
540
401
/*
541
402
  Additional variables (not derived from sys_var class, not accessible as
546
407
 
547
408
#define FIXED_VARS_SIZE (sizeof(fixed_vars) / sizeof(SHOW_VAR))
548
409
static SHOW_VAR fixed_vars[]= {
549
 
  {"back_log",                (char*) &back_log,                    SHOW_LONG},
550
 
  {"init_file",               (char*) &opt_init_file,               SHOW_CHAR_PTR},
 
410
  {"back_log",                (char*) &back_log,                    SHOW_INT},
551
411
  {"language",                language,                             SHOW_CHAR},
552
412
#ifdef HAVE_MLOCKALL
553
413
  {"locked_in_memory",        (char*) &locked_in_memory,            SHOW_MY_BOOL},
554
414
#endif
555
 
  {"log_bin",                 (char*) &opt_bin_log,                 SHOW_BOOL},
556
 
  {"log_error",               (char*) log_error_file,               SHOW_CHAR},
557
415
  {"myisam_recover_options",  (char*) &myisam_recover_options_str,  SHOW_CHAR_PTR},
558
 
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
559
416
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
560
417
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
561
 
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
 
418
  {"port",                    (char*) &drizzled_port,               SHOW_INT},
562
419
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
563
 
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
 
420
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_INT},
564
421
};
565
422
 
566
 
 
567
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
423
bool sys_var::check(Session *, set_var *var)
568
424
{
569
425
  var->save_result.uint64_t_value= var->value->val_int();
570
426
  return 0;
571
427
}
572
428
 
573
 
bool sys_var_str::check(THD *thd, set_var *var)
 
429
bool sys_var_str::check(Session *session, set_var *var)
574
430
{
575
431
  int res;
576
432
  if (!check_func)
577
433
    return 0;
578
434
 
579
 
  if ((res=(*check_func)(thd, var)) < 0)
 
435
  if ((res=(*check_func)(session, var)) < 0)
580
436
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
581
437
             name, var->value->str_value.ptr());
582
438
  return res;
587
443
*/
588
444
 
589
445
 
590
 
/*
591
 
  Update variables 'init_connect, init_slave'.
592
 
 
593
 
  In case of 'DEFAULT' value
594
 
  (for example: 'set GLOBAL init_connect=DEFAULT')
595
 
  'var' parameter is NULL pointer.
596
 
*/
597
 
 
598
 
bool update_sys_var_str(sys_var_str *var_str, rw_lock_t *var_mutex,
599
 
                        set_var *var)
600
 
{
601
 
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
602
 
  uint32_t new_length= (var ? var->value->str_value.length() : 0);
603
 
  if (!old_value)
604
 
    old_value= (char*) "";
605
 
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
606
 
    return 1;
607
 
  /*
608
 
    Replace the old value in such a way that the any thread using
609
 
    the value will work.
610
 
  */
611
 
  rw_wrlock(var_mutex);
612
 
  old_value= var_str->value;
613
 
  var_str->value= res;
614
 
  var_str->value_length= new_length;
615
 
  rw_unlock(var_mutex);
616
 
  free(old_value);
617
 
  return 0;
618
 
}
619
 
 
620
 
 
621
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
622
 
{
623
 
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
624
 
}
625
 
 
626
 
 
627
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
628
 
                                     enum_var_type type __attribute__((unused)))
629
 
{
630
 
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
631
 
}
632
 
 
633
 
 
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
446
/**
674
447
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
675
448
*/
676
449
 
677
 
static void fix_max_join_size(THD *thd, enum_var_type type)
 
450
static void fix_max_join_size(Session *session, enum_var_type type)
678
451
{
679
452
  if (type != OPT_GLOBAL)
680
453
  {
681
 
    if (thd->variables.max_join_size == HA_POS_ERROR)
682
 
      thd->options|= OPTION_BIG_SELECTS;
 
454
    if (session->variables.max_join_size == HA_POS_ERROR)
 
455
      session->options|= OPTION_BIG_SELECTS;
683
456
    else
684
 
      thd->options&= ~OPTION_BIG_SELECTS;
 
457
      session->options&= ~OPTION_BIG_SELECTS;
685
458
  }
686
459
}
687
460
 
690
463
  Can't change the 'next' tx_isolation while we are already in
691
464
  a transaction
692
465
*/
693
 
static int check_tx_isolation(THD *thd, set_var *var)
 
466
static int check_tx_isolation(Session *session, set_var *var)
694
467
{
695
 
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
 
468
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
696
469
  {
697
470
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
698
471
    return 1;
704
477
  If one doesn't use the SESSION modifier, the isolation level
705
478
  is only active for the next command.
706
479
*/
707
 
static void fix_tx_isolation(THD *thd, enum_var_type type)
 
480
static void fix_tx_isolation(Session *session, enum_var_type type)
708
481
{
709
482
  if (type == OPT_SESSION)
710
 
    thd->session_tx_isolation= ((enum_tx_isolation)
711
 
                                thd->variables.tx_isolation);
 
483
    session->session_tx_isolation= ((enum_tx_isolation)
 
484
                                    session->variables.tx_isolation);
712
485
}
713
486
 
714
 
static void fix_completion_type(THD *thd __attribute__((unused)),
715
 
                                enum_var_type type __attribute__((unused))) {}
 
487
static void fix_completion_type(Session *, enum_var_type) {}
716
488
 
717
 
static int check_completion_type(THD *thd __attribute__((unused)),
718
 
                                 set_var *var)
 
489
static int check_completion_type(Session *, set_var *var)
719
490
{
720
491
  int64_t val= var->value->val_int();
721
492
  if (val < 0 || val > 2)
729
500
 
730
501
 
731
502
/*
732
 
  If we are changing the thread variable, we have to copy it to NET too
 
503
  If we are changing the thread variable, we have to copy it to Protocol too
733
504
*/
734
505
 
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)))
 
506
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
507
{
 
508
  if (type != OPT_GLOBAL)
 
509
    session->protocol->setReadTimeout(session->variables.net_read_timeout);
 
510
}
 
511
 
 
512
 
 
513
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
514
{
 
515
  if (type != OPT_GLOBAL)
 
516
    session->protocol->setWriteTimeout(session->variables.net_write_timeout);
 
517
}
 
518
 
 
519
static void fix_net_retry_count(Session *session, enum_var_type type)
 
520
{
 
521
  if (type != OPT_GLOBAL)
 
522
    session->protocol->setRetryCount(session->variables.net_retry_count);
 
523
}
 
524
 
 
525
 
 
526
extern void fix_delay_key_write(Session *, enum_var_type)
757
527
{
758
528
  switch ((enum_delay_key_write) delay_key_write_options) {
759
529
  case DELAY_KEY_WRITE_NONE:
769
539
  }
770
540
}
771
541
 
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)))
932
 
{
933
 
  server_id_supplied = 1;
934
 
  thd->server_id= server_id;
935
 
}
936
 
 
937
 
 
938
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
542
 
 
543
static void fix_session_mem_root(Session *session, enum_var_type type)
 
544
{
 
545
  if (type != OPT_GLOBAL)
 
546
    reset_root_defaults(session->mem_root,
 
547
                        session->variables.query_alloc_block_size,
 
548
                        session->variables.query_prealloc_size);
 
549
}
 
550
 
 
551
 
 
552
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
553
{
 
554
  if (type != OPT_GLOBAL)
 
555
    reset_root_defaults(&session->transaction.mem_root,
 
556
                        session->variables.trans_alloc_block_size,
 
557
                        session->variables.trans_prealloc_size);
 
558
}
 
559
 
 
560
 
 
561
static void fix_server_id(Session *, enum_var_type)
 
562
{
 
563
}
 
564
 
 
565
 
 
566
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
939
567
                          const char *name, int64_t val)
940
568
{
941
569
  if (fixed)
947
575
    else
948
576
      llstr(val, buf);
949
577
 
950
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
578
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
951
579
                        ER_TRUNCATED_WRONG_VALUE,
952
580
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
953
581
  }
954
582
  return false;
955
583
}
956
584
 
957
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
585
static uint64_t fix_unsigned(Session *session, uint64_t num,
958
586
                              const struct my_option *option_limits)
959
587
{
960
588
  bool fixed= false;
961
589
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
962
590
 
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);
 
591
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
592
  return out;
 
593
}
 
594
 
 
595
 
 
596
static size_t fix_size_t(Session *session, size_t num,
 
597
                           const struct my_option *option_limits)
 
598
{
 
599
  bool fixed= false;
 
600
  size_t out= (size_t)getopt_ull_limit_value(num, option_limits, &fixed);
 
601
 
 
602
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
 
603
  return out;
 
604
}
 
605
 
 
606
static bool get_unsigned32(Session *, set_var *var)
 
607
{
 
608
  if (var->value->unsigned_flag)
 
609
    var->save_result.uint32_t_value= (uint32_t) var->value->val_int();
 
610
  else
 
611
  {
 
612
    int64_t v= var->value->val_int();
 
613
    var->save_result.uint32_t_value= (uint32_t) ((v < 0) ? 0 : v);
 
614
  }
 
615
  return 0;
 
616
}
 
617
 
 
618
static bool get_unsigned64(Session *, set_var *var)
 
619
{
 
620
  if (var->value->unsigned_flag)
 
621
      var->save_result.uint64_t_value=(uint64_t) var->value->val_int();
 
622
  else
 
623
  {
 
624
    int64_t v= var->value->val_int();
 
625
      var->save_result.uint64_t_value= (uint64_t) ((v < 0) ? 0 : v);
 
626
  }
 
627
  return 0;
 
628
}
 
629
 
 
630
static bool get_size_t(Session *, set_var *var)
 
631
{
 
632
  if (var->value->unsigned_flag)
 
633
    var->save_result.size_t_value= (size_t) var->value->val_int();
 
634
  else
 
635
  {
 
636
    ssize_t v= (ssize_t)var->value->val_int();
 
637
    var->save_result.size_t_value= (size_t) ((v < 0) ? 0 : v);
 
638
  }
 
639
  return 0;
 
640
}
 
641
 
 
642
bool sys_var_uint32_t_ptr::check(Session *, set_var *var)
 
643
{
 
644
  var->save_result.uint32_t_value= (uint32_t)var->value->val_int();
 
645
  return 0;
 
646
}
 
647
 
 
648
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
 
649
{
 
650
  uint32_t tmp= var->save_result.uint32_t_value;
 
651
  pthread_mutex_lock(&LOCK_global_system_variables);
997
652
  if (option_limits)
998
 
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
999
 
  else
1000
653
  {
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;
 
654
    uint32_t newvalue= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
655
    if(newvalue==tmp)
 
656
      *value= newvalue;
1011
657
  }
1012
 
 
1013
 
  pthread_mutex_unlock(guard);
 
658
  else
 
659
    *value= (uint32_t) tmp;
 
660
  pthread_mutex_unlock(&LOCK_global_system_variables);
1014
661
  return 0;
1015
662
}
1016
663
 
1017
664
 
1018
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
665
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
1019
666
{
1020
667
  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);
 
668
  pthread_mutex_lock(&LOCK_global_system_variables);
 
669
  *value= (uint32_t)getopt_ull_limit_value((uint32_t) option_limits->def_value,
 
670
                                           option_limits, &not_used);
 
671
  pthread_mutex_unlock(&LOCK_global_system_variables);
1025
672
}
1026
673
 
1027
674
 
1028
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
675
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1029
676
{
1030
677
  uint64_t tmp= var->save_result.uint64_t_value;
1031
678
  pthread_mutex_lock(&LOCK_global_system_variables);
1032
679
  if (option_limits)
1033
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
680
  {
 
681
    uint64_t newvalue= (uint64_t) fix_unsigned(session, tmp, option_limits);
 
682
    if(newvalue==tmp)
 
683
      *value= newvalue;
 
684
  }
1034
685
  else
1035
686
    *value= (uint64_t) tmp;
1036
687
  pthread_mutex_unlock(&LOCK_global_system_variables);
1038
689
}
1039
690
 
1040
691
 
1041
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1042
 
                                        enum_var_type type __attribute__((unused)))
 
692
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
1043
693
{
1044
694
  bool not_used;
1045
695
  pthread_mutex_lock(&LOCK_global_system_variables);
1049
699
}
1050
700
 
1051
701
 
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)))
 
702
bool sys_var_size_t_ptr::update(Session *session, set_var *var)
 
703
{
 
704
  size_t tmp= var->save_result.size_t_value;
 
705
  pthread_mutex_lock(&LOCK_global_system_variables);
 
706
  if (option_limits)
 
707
    *value= fix_size_t(session, tmp, option_limits);
 
708
  else
 
709
    *value= tmp;
 
710
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
711
  return 0;
 
712
}
 
713
 
 
714
 
 
715
void sys_var_size_t_ptr::set_default(Session *, enum_var_type)
 
716
{
 
717
  bool not_used;
 
718
  pthread_mutex_lock(&LOCK_global_system_variables);
 
719
  *value= (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
 
720
                                         option_limits, &not_used);
 
721
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
722
}
 
723
 
 
724
bool sys_var_bool_ptr::update(Session *, set_var *var)
 
725
{
 
726
  *value= (bool) var->save_result.uint32_t_value;
 
727
  return 0;
 
728
}
 
729
 
 
730
 
 
731
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
1060
732
{
1061
733
  *value= (bool) option_limits->def_value;
1062
734
}
1063
735
 
1064
736
 
1065
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
737
bool sys_var_enum::update(Session *, set_var *var)
1066
738
{
1067
 
  *value= (uint) var->save_result.ulong_value;
 
739
  *value= (uint32_t) var->save_result.uint32_t_value;
1068
740
  return 0;
1069
741
}
1070
742
 
1071
743
 
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)))
 
744
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, const LEX_STRING *)
1075
745
{
1076
746
  return (unsigned char*) enum_names->type_names[*value];
1077
747
}
1078
748
 
1079
749
 
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)))
 
750
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
 
751
                                             const LEX_STRING *)
1083
752
{
1084
753
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
1085
754
}
1086
755
 
1087
 
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
 
756
/*
 
757
  32 bit types for session variables
 
758
*/
 
759
bool sys_var_session_uint32_t::check(Session *session, set_var *var)
1088
760
{
1089
 
  return (get_unsigned(thd, var) ||
1090
 
          (check_func && (*check_func)(thd, var)));
 
761
  return (get_unsigned32(session, var) ||
 
762
          (check_func && (*check_func)(session, var)));
1091
763
}
1092
764
 
1093
 
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
 
765
bool sys_var_session_uint32_t::update(Session *session, set_var *var)
1094
766
{
1095
 
  uint64_t tmp= var->save_result.uint64_t_value;
1096
 
  
 
767
  uint64_t tmp= (uint64_t) var->save_result.uint32_t_value;
 
768
 
1097
769
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1098
 
  if ((ulong) tmp > max_system_variables.*offset)
 
770
  if ((uint32_t) tmp > max_system_variables.*offset)
1099
771
  {
1100
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
772
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
1101
773
    tmp= max_system_variables.*offset;
1102
774
  }
1103
 
  
 
775
 
1104
776
  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)
 
777
    tmp= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
778
  else if (tmp > UINT32_MAX)
1108
779
  {
1109
 
    tmp= ULONG_MAX;
1110
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
780
    tmp= UINT32_MAX;
 
781
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
1111
782
  }
1112
 
#endif
1113
 
  
 
783
 
1114
784
  if (var->type == OPT_GLOBAL)
1115
 
     global_system_variables.*offset= (ulong) tmp;
 
785
     global_system_variables.*offset= (uint32_t) tmp;
1116
786
   else
1117
 
     thd->variables.*offset= (ulong) tmp;
 
787
     session->variables.*offset= (uint32_t) tmp;
1118
788
 
1119
789
   return 0;
1120
790
 }
1121
791
 
1122
792
 
1123
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
793
 void sys_var_session_uint32_t::set_default(Session *session, enum_var_type type)
1124
794
 {
1125
795
   if (type == OPT_GLOBAL)
1126
796
   {
1127
797
     bool not_used;
1128
798
     /* We will not come here if option_limits is not set */
1129
799
     global_system_variables.*offset=
1130
 
       (ulong) getopt_ull_limit_value((ulong) option_limits->def_value,
 
800
       (uint32_t) getopt_ull_limit_value((uint32_t) option_limits->def_value,
1131
801
                                      option_limits, &not_used);
1132
802
   }
1133
803
   else
1134
 
     thd->variables.*offset= global_system_variables.*offset;
 
804
     session->variables.*offset= global_system_variables.*offset;
1135
805
 }
1136
806
 
1137
807
 
1138
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1139
 
                                    LEX_STRING *base __attribute__((unused)))
 
808
unsigned char *sys_var_session_uint32_t::value_ptr(Session *session,
 
809
                                                enum_var_type type,
 
810
                                                const LEX_STRING *)
1140
811
{
1141
812
  if (type == OPT_GLOBAL)
1142
813
    return (unsigned char*) &(global_system_variables.*offset);
1143
 
  return (unsigned char*) &(thd->variables.*offset);
 
814
  return (unsigned char*) &(session->variables.*offset);
1144
815
}
1145
816
 
1146
817
 
1147
 
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
 
818
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1148
819
{
1149
820
  uint64_t tmp= var->save_result.uint64_t_value;
1150
821
 
1153
824
    tmp= max_system_variables.*offset;
1154
825
 
1155
826
  if (option_limits)
1156
 
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
 
827
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1157
828
  if (var->type == OPT_GLOBAL)
1158
829
  {
1159
830
    /* Lock is needed to make things safe on 32 bit systems */
1160
 
    pthread_mutex_lock(&LOCK_global_system_variables);    
 
831
    pthread_mutex_lock(&LOCK_global_system_variables);
1161
832
    global_system_variables.*offset= (ha_rows) tmp;
1162
833
    pthread_mutex_unlock(&LOCK_global_system_variables);
1163
834
  }
1164
835
  else
1165
 
    thd->variables.*offset= (ha_rows) tmp;
 
836
    session->variables.*offset= (ha_rows) tmp;
1166
837
  return 0;
1167
838
}
1168
839
 
1169
840
 
1170
 
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
 
841
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1171
842
{
1172
843
  if (type == OPT_GLOBAL)
1173
844
  {
1180
851
    pthread_mutex_unlock(&LOCK_global_system_variables);
1181
852
  }
1182
853
  else
1183
 
    thd->variables.*offset= global_system_variables.*offset;
 
854
    session->variables.*offset= global_system_variables.*offset;
1184
855
}
1185
856
 
1186
857
 
1187
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1188
 
                                      LEX_STRING *base __attribute__((unused)))
 
858
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
 
859
                                                  enum_var_type type,
 
860
                                                  const LEX_STRING *)
1189
861
{
1190
862
  if (type == OPT_GLOBAL)
1191
863
    return (unsigned char*) &(global_system_variables.*offset);
1192
 
  return (unsigned char*) &(thd->variables.*offset);
 
864
  return (unsigned char*) &(session->variables.*offset);
1193
865
}
1194
866
 
1195
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
867
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1196
868
{
1197
 
  return get_unsigned(thd, var);
 
869
  return (get_unsigned64(session, var) ||
 
870
          (check_func && (*check_func)(session, var)));
1198
871
}
1199
872
 
1200
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
873
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1201
874
{
1202
875
  uint64_t tmp= var->save_result.uint64_t_value;
1203
876
 
1205
878
    tmp= max_system_variables.*offset;
1206
879
 
1207
880
  if (option_limits)
1208
 
    tmp= fix_unsigned(thd, tmp, option_limits);
 
881
    tmp= fix_unsigned(session, tmp, option_limits);
1209
882
  if (var->type == OPT_GLOBAL)
1210
883
  {
1211
884
    /* Lock is needed to make things safe on 32 bit systems */
1214
887
    pthread_mutex_unlock(&LOCK_global_system_variables);
1215
888
  }
1216
889
  else
1217
 
    thd->variables.*offset= (uint64_t) tmp;
 
890
    session->variables.*offset= (uint64_t) tmp;
1218
891
  return 0;
1219
892
}
1220
893
 
1221
894
 
1222
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
895
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1223
896
{
1224
897
  if (type == OPT_GLOBAL)
1225
898
  {
1231
904
    pthread_mutex_unlock(&LOCK_global_system_variables);
1232
905
  }
1233
906
  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)
 
907
    session->variables.*offset= global_system_variables.*offset;
 
908
}
 
909
 
 
910
 
 
911
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
 
912
                                                   enum_var_type type,
 
913
                                                   const LEX_STRING *)
 
914
{
 
915
  if (type == OPT_GLOBAL)
 
916
    return (unsigned char*) &(global_system_variables.*offset);
 
917
  return (unsigned char*) &(session->variables.*offset);
 
918
}
 
919
 
 
920
bool sys_var_session_size_t::check(Session *session, set_var *var)
 
921
{
 
922
  return (get_size_t(session, var) ||
 
923
          (check_func && (*check_func)(session, var)));
 
924
}
 
925
 
 
926
bool sys_var_session_size_t::update(Session *session,  set_var *var)
 
927
{
 
928
  size_t tmp= var->save_result.size_t_value;
 
929
 
 
930
  if (tmp > max_system_variables.*offset)
 
931
    tmp= max_system_variables.*offset;
 
932
 
 
933
  if (option_limits)
 
934
    tmp= fix_size_t(session, tmp, option_limits);
 
935
  if (var->type == OPT_GLOBAL)
 
936
  {
 
937
    /* Lock is needed to make things safe on 32 bit systems */
 
938
    pthread_mutex_lock(&LOCK_global_system_variables);
 
939
    global_system_variables.*offset= tmp;
 
940
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
941
  }
 
942
  else
 
943
    session->variables.*offset= tmp;
 
944
  return 0;
 
945
}
 
946
 
 
947
 
 
948
void sys_var_session_size_t::set_default(Session *session, enum_var_type type)
 
949
{
 
950
  if (type == OPT_GLOBAL)
 
951
  {
 
952
    bool not_used;
 
953
    pthread_mutex_lock(&LOCK_global_system_variables);
 
954
    global_system_variables.*offset=
 
955
      (size_t)getopt_ull_limit_value((size_t) option_limits->def_value,
 
956
                                     option_limits, &not_used);
 
957
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
958
  }
 
959
  else
 
960
    session->variables.*offset= global_system_variables.*offset;
 
961
}
 
962
 
 
963
 
 
964
unsigned char *sys_var_session_size_t::value_ptr(Session *session,
 
965
                                                 enum_var_type type,
 
966
                                                 const LEX_STRING *)
 
967
{
 
968
  if (type == OPT_GLOBAL)
 
969
    return (unsigned char*) &(global_system_variables.*offset);
 
970
  return (unsigned char*) &(session->variables.*offset);
 
971
}
 
972
 
 
973
 
 
974
bool sys_var_session_bool::update(Session *session,  set_var *var)
 
975
{
 
976
  if (var->type == OPT_GLOBAL)
 
977
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
 
978
  else
 
979
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
 
980
  return 0;
 
981
}
 
982
 
 
983
 
 
984
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1258
985
{
1259
986
  if (type == OPT_GLOBAL)
1260
987
    global_system_variables.*offset= (bool) option_limits->def_value;
1261
988
  else
1262
 
    thd->variables.*offset= global_system_variables.*offset;
 
989
    session->variables.*offset= global_system_variables.*offset;
1263
990
}
1264
991
 
1265
992
 
1266
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1267
 
                                   LEX_STRING *base __attribute__((unused)))
 
993
unsigned char *sys_var_session_bool::value_ptr(Session *session,
 
994
                                               enum_var_type type,
 
995
                                               const LEX_STRING *)
1268
996
{
1269
997
  if (type == OPT_GLOBAL)
1270
998
    return (unsigned char*) &(global_system_variables.*offset);
1271
 
  return (unsigned char*) &(thd->variables.*offset);
 
999
  return (unsigned char*) &(session->variables.*offset);
1272
1000
}
1273
1001
 
1274
1002
 
1275
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
 
1003
bool sys_var::check_enum(Session *,
1276
1004
                         set_var *var, const TYPELIB *enum_names)
1277
1005
{
1278
1006
  char buff[STRING_BUFFER_USUAL_SIZE];
1282
1010
  if (var->value->result_type() == STRING_RESULT)
1283
1011
  {
1284
1012
    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)
 
1013
        (var->save_result.uint32_t_value= find_type(enum_names, res->ptr(),
 
1014
                                                    res->length(),1)) == 0)
1288
1015
    {
1289
1016
      value= res ? res->c_ptr() : "NULL";
1290
1017
      goto err;
1291
1018
    }
 
1019
 
 
1020
    var->save_result.uint32_t_value--;
1292
1021
  }
1293
1022
  else
1294
1023
  {
1299
1028
      value=buff;                               // Wrong value is here
1300
1029
      goto err;
1301
1030
    }
1302
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
1031
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
1303
1032
  }
1304
1033
  return 0;
1305
1034
 
1309
1038
}
1310
1039
 
1311
1040
 
1312
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
1313
 
                        set_var *var, TYPELIB *enum_names)
 
1041
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
1314
1042
{
1315
1043
  bool not_used;
1316
1044
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1321
1049
  {
1322
1050
    if (!(res= var->value->val_str(&str)))
1323
1051
    {
1324
 
      my_stpcpy(buff, "NULL");
 
1052
      strcpy(buff, "NULL");
1325
1053
      goto err;
1326
1054
    }
1327
1055
 
1332
1060
      goto err;
1333
1061
    }
1334
1062
 
1335
 
    var->save_result.ulong_value= ((ulong)
 
1063
    var->save_result.uint32_t_value= ((uint32_t)
1336
1064
                                   find_set(enum_names, res->c_ptr(),
1337
1065
                                            res->length(),
1338
1066
                                            NULL,
1340
1068
                                            &not_used));
1341
1069
    if (error_len)
1342
1070
    {
1343
 
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
 
1071
      size_t len = cmin(sizeof(buff) - 1, error_len);
 
1072
      strncpy(buff, error, len);
 
1073
      buff[len]= '\0';
1344
1074
      goto err;
1345
1075
    }
1346
1076
  }
1366
1096
      llstr(tmp, buff);
1367
1097
      goto err;
1368
1098
    }
1369
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
1099
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
1370
1100
  }
1371
1101
  return 0;
1372
1102
 
1384
1114
  If type is not given, return local value if exists, else global.
1385
1115
*/
1386
1116
 
1387
 
Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
 
1117
Item *sys_var::item(Session *session, enum_var_type var_type, const LEX_STRING *base)
1388
1118
{
1389
1119
  if (check_type(var_type))
1390
1120
  {
1398
1128
    var_type= OPT_GLOBAL;
1399
1129
  }
1400
1130
  switch (show_type()) {
 
1131
  case SHOW_LONG:
1401
1132
  case SHOW_INT:
1402
1133
  {
1403
1134
    uint32_t value;
1404
1135
    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);
 
1136
    value= *(uint*) value_ptr(session, var_type, base);
1414
1137
    pthread_mutex_unlock(&LOCK_global_system_variables);
1415
1138
    return new Item_uint((uint64_t) value);
1416
1139
  }
1418
1141
  {
1419
1142
    int64_t value;
1420
1143
    pthread_mutex_lock(&LOCK_global_system_variables);
1421
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1144
    value= *(int64_t*) value_ptr(session, var_type, base);
1422
1145
    pthread_mutex_unlock(&LOCK_global_system_variables);
1423
1146
    return new Item_int(value);
1424
1147
  }
1426
1149
  {
1427
1150
    double value;
1428
1151
    pthread_mutex_lock(&LOCK_global_system_variables);
1429
 
    value= *(double*) value_ptr(thd, var_type, base);
 
1152
    value= *(double*) value_ptr(session, var_type, base);
1430
1153
    pthread_mutex_unlock(&LOCK_global_system_variables);
1431
1154
    /* 6, as this is for now only used with microseconds */
1432
1155
    return new Item_float(value, 6);
1435
1158
  {
1436
1159
    ha_rows value;
1437
1160
    pthread_mutex_lock(&LOCK_global_system_variables);
1438
 
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1161
    value= *(ha_rows*) value_ptr(session, var_type, base);
 
1162
    pthread_mutex_unlock(&LOCK_global_system_variables);
 
1163
    return new Item_int((uint64_t) value);
 
1164
  }
 
1165
  case SHOW_SIZE:
 
1166
  {
 
1167
    size_t value;
 
1168
    pthread_mutex_lock(&LOCK_global_system_variables);
 
1169
    value= *(size_t*) value_ptr(session, var_type, base);
1439
1170
    pthread_mutex_unlock(&LOCK_global_system_variables);
1440
1171
    return new Item_int((uint64_t) value);
1441
1172
  }
1443
1174
  {
1444
1175
    int32_t value;
1445
1176
    pthread_mutex_lock(&LOCK_global_system_variables);
1446
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1177
    value= *(bool*) value_ptr(session, var_type, base);
1447
1178
    pthread_mutex_unlock(&LOCK_global_system_variables);
1448
1179
    return new Item_int(value,1);
1449
1180
  }
1451
1182
  {
1452
1183
    Item *tmp;
1453
1184
    pthread_mutex_lock(&LOCK_global_system_variables);
1454
 
    char *str= *(char**) value_ptr(thd, var_type, base);
 
1185
    char *str= *(char**) value_ptr(session, var_type, base);
1455
1186
    if (str)
1456
1187
    {
1457
1188
      uint32_t length= strlen(str);
1458
 
      tmp= new Item_string(thd->strmake(str, length), length,
 
1189
      tmp= new Item_string(session->strmake(str, length), length,
1459
1190
                           system_charset_info, DERIVATION_SYSCONST);
1460
1191
    }
1461
1192
    else
1470
1201
  {
1471
1202
    Item *tmp;
1472
1203
    pthread_mutex_lock(&LOCK_global_system_variables);
1473
 
    char *str= (char*) value_ptr(thd, var_type, base);
 
1204
    char *str= (char*) value_ptr(session, var_type, base);
1474
1205
    if (str)
1475
1206
      tmp= new Item_string(str, strlen(str),
1476
1207
                           system_charset_info, DERIVATION_SYSCONST);
1489
1220
}
1490
1221
 
1491
1222
 
1492
 
bool sys_var_thd_enum::update(THD *thd, set_var *var)
 
1223
bool sys_var_session_enum::update(Session *session, set_var *var)
1493
1224
{
1494
1225
  if (var->type == OPT_GLOBAL)
1495
 
    global_system_variables.*offset= var->save_result.ulong_value;
 
1226
    global_system_variables.*offset= var->save_result.uint32_t_value;
1496
1227
  else
1497
 
    thd->variables.*offset= var->save_result.ulong_value;
 
1228
    session->variables.*offset= var->save_result.uint32_t_value;
1498
1229
  return 0;
1499
1230
}
1500
1231
 
1501
1232
 
1502
 
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
 
1233
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1503
1234
{
1504
1235
  if (type == OPT_GLOBAL)
1505
 
    global_system_variables.*offset= (ulong) option_limits->def_value;
 
1236
    global_system_variables.*offset= (uint32_t) option_limits->def_value;
1506
1237
  else
1507
 
    thd->variables.*offset= global_system_variables.*offset;
 
1238
    session->variables.*offset= global_system_variables.*offset;
1508
1239
}
1509
1240
 
1510
1241
 
1511
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1512
 
                                   LEX_STRING *base __attribute__((unused)))
 
1242
unsigned char *sys_var_session_enum::value_ptr(Session *session,
 
1243
                                               enum_var_type type,
 
1244
                                               const LEX_STRING *)
1513
1245
{
1514
 
  ulong tmp= ((type == OPT_GLOBAL) ?
 
1246
  uint32_t tmp= ((type == OPT_GLOBAL) ?
1515
1247
              global_system_variables.*offset :
1516
 
              thd->variables.*offset);
 
1248
              session->variables.*offset);
1517
1249
  return (unsigned char*) enum_names->type_names[tmp];
1518
1250
}
1519
1251
 
1520
 
bool sys_var_thd_bit::check(THD *thd, set_var *var)
 
1252
bool sys_var_session_bit::check(Session *session, set_var *var)
1521
1253
{
1522
 
  return (check_enum(thd, var, &bool_typelib) ||
1523
 
          (check_func && (*check_func)(thd, var)));
 
1254
  return (check_enum(session, var, &bool_typelib) ||
 
1255
          (check_func && (*check_func)(session, var)));
1524
1256
}
1525
1257
 
1526
 
bool sys_var_thd_bit::update(THD *thd, set_var *var)
 
1258
bool sys_var_session_bit::update(Session *session, set_var *var)
1527
1259
{
1528
 
  int res= (*update_func)(thd, var);
 
1260
  int res= (*update_func)(session, var);
1529
1261
  return res;
1530
1262
}
1531
1263
 
1532
1264
 
1533
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
1534
 
                                  enum_var_type type __attribute__((unused)),
1535
 
                                  LEX_STRING *base __attribute__((unused)))
 
1265
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
 
1266
                                              const LEX_STRING *)
1536
1267
{
1537
1268
  /*
1538
1269
    If reverse is 0 (default) return 1 if bit is set.
1539
1270
    If reverse is 1, return 0 if bit is set
1540
1271
  */
1541
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1272
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1542
1273
                                   !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;
 
1274
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1647
1275
}
1648
1276
 
1649
1277
 
1653
1281
  const char *new_name;
1654
1282
} my_old_conv;
1655
1283
 
1656
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1657
 
                              set_var *var)
 
1284
bool sys_var_collation::check(Session *, set_var *var)
1658
1285
{
1659
1286
  const CHARSET_INFO *tmp;
1660
1287
 
1667
1294
      my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, "NULL");
1668
1295
      return 1;
1669
1296
    }
1670
 
    if (!(tmp=get_charset_by_name(res->c_ptr(),MYF(0))))
 
1297
    if (!(tmp=get_charset_by_name(res->c_ptr())))
1671
1298
    {
1672
1299
      my_error(ER_UNKNOWN_COLLATION, MYF(0), res->c_ptr());
1673
1300
      return 1;
1675
1302
  }
1676
1303
  else // INT_RESULT
1677
1304
  {
1678
 
    if (!(tmp=get_charset((int) var->value->val_int(),MYF(0))))
 
1305
    if (!(tmp=get_charset((int) var->value->val_int())))
1679
1306
    {
1680
1307
      char buf[20];
1681
1308
      int10_to_str((int) var->value->val_int(), buf, -10);
1688
1315
}
1689
1316
 
1690
1317
 
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)
 
1318
bool sys_var_collation_sv::update(Session *session, set_var *var)
1803
1319
{
1804
1320
  if (var->type == OPT_GLOBAL)
1805
1321
    global_system_variables.*offset= var->save_result.charset;
1806
1322
  else
1807
1323
  {
1808
 
    thd->variables.*offset= var->save_result.charset;
1809
 
    thd->update_charset();
 
1324
    session->variables.*offset= var->save_result.charset;
 
1325
    session->update_charset();
1810
1326
  }
1811
1327
  return 0;
1812
1328
}
1813
1329
 
1814
1330
 
1815
 
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
 
1331
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1816
1332
{
1817
1333
  if (type == OPT_GLOBAL)
1818
1334
    global_system_variables.*offset= *global_default;
1819
1335
  else
1820
1336
  {
1821
 
    thd->variables.*offset= global_system_variables.*offset;
1822
 
    thd->update_charset();
 
1337
    session->variables.*offset= global_system_variables.*offset;
 
1338
    session->update_charset();
1823
1339
  }
1824
1340
}
1825
1341
 
1826
1342
 
1827
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1828
 
                                       LEX_STRING *base __attribute__((unused)))
 
1343
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
 
1344
                                               enum_var_type type,
 
1345
                                               const LEX_STRING *)
1829
1346
{
1830
1347
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1831
 
                     global_system_variables.*offset : thd->variables.*offset);
 
1348
                           global_system_variables.*offset :
 
1349
                           session->variables.*offset);
1832
1350
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1833
1351
}
1834
1352
 
1837
1355
 
1838
1356
static KEY_CACHE zero_key_cache;
1839
1357
 
1840
 
KEY_CACHE *get_key_cache(LEX_STRING *cache_name)
 
1358
KEY_CACHE *get_key_cache(const LEX_STRING *cache_name)
1841
1359
{
1842
1360
  safe_mutex_assert_owner(&LOCK_global_system_variables);
1843
1361
  if (!cache_name || ! cache_name->length)
1844
1362
    cache_name= &default_key_cache_base;
1845
1363
  return ((KEY_CACHE*) find_named(&key_caches,
1846
 
                                      cache_name->str, cache_name->length, 0));
 
1364
                                  cache_name->str, cache_name->length, 0));
1847
1365
}
1848
1366
 
1849
1367
 
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)))
 
1368
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
 
1369
                                                  const LEX_STRING *base)
1853
1370
{
1854
1371
  KEY_CACHE *key_cache= get_key_cache(base);
1855
1372
  if (!key_cache)
1858
1375
}
1859
1376
 
1860
1377
 
1861
 
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
 
1378
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1862
1379
{
1863
1380
  uint64_t tmp= var->save_result.uint64_t_value;
1864
1381
  LEX_STRING *base_name= &var->base;
1871
1388
 
1872
1389
  pthread_mutex_lock(&LOCK_global_system_variables);
1873
1390
  key_cache= get_key_cache(base_name);
1874
 
                            
 
1391
 
1875
1392
  if (!key_cache)
1876
1393
  {
1877
1394
    /* Key cache didn't exists */
1896
1413
  {
1897
1414
    if (key_cache == dflt_key_cache)
1898
1415
    {
1899
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1416
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1900
1417
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1901
1418
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1902
1419
      goto end;                                 // Ignore default key cache
1908
1425
        Move tables using this key cache to the default key cache
1909
1426
        and clear the old key cache.
1910
1427
      */
1911
 
      NAMED_LIST *list; 
 
1428
      NAMED_LIST *list;
1912
1429
      key_cache= (KEY_CACHE *) find_named(&key_caches, base_name->str,
1913
1430
                                              base_name->length, &list);
1914
1431
      key_cache->in_init= 1;
1915
1432
      pthread_mutex_unlock(&LOCK_global_system_variables);
1916
 
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
 
1433
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1917
1434
      pthread_mutex_lock(&LOCK_global_system_variables);
1918
1435
      key_cache->in_init= 0;
1919
1436
    }
1925
1442
  }
1926
1443
 
1927
1444
  key_cache->param_buff_size=
1928
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1445
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1929
1446
 
1930
1447
  /* If key cache didn't existed initialize it, else resize it */
1931
1448
  key_cache->in_init= 1;
1937
1454
    error= (bool)(ha_resize_key_cache(key_cache));
1938
1455
 
1939
1456
  pthread_mutex_lock(&LOCK_global_system_variables);
1940
 
  key_cache->in_init= 0;  
 
1457
  key_cache->in_init= 0;
1941
1458
 
1942
1459
end:
1943
1460
  pthread_mutex_unlock(&LOCK_global_system_variables);
1951
1468
  This should be changed so that we wait until the previous
1952
1469
  assignment is done and then do the new assign
1953
1470
*/
1954
 
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
 
1471
bool sys_var_key_cache_uint32_t::update(Session *session, set_var *var)
1955
1472
{
1956
 
  ulong tmp= (ulong) var->value->val_int();
 
1473
  uint64_t tmp= (uint64_t) var->value->val_int();
1957
1474
  LEX_STRING *base_name= &var->base;
1958
1475
  bool error= 0;
1959
1476
 
1978
1495
  if (key_cache->in_init)
1979
1496
    goto end;
1980
1497
 
1981
 
  *((ulong*) (((char*) key_cache) + offset))=
1982
 
    (ulong) fix_unsigned(thd, tmp, option_limits);
 
1498
  *((uint32_t*) (((char*) key_cache) + offset))=
 
1499
    (uint32_t) fix_unsigned(session, tmp, option_limits);
1983
1500
 
1984
1501
  /*
1985
1502
    Don't create a new key cache if it didn't exist
1992
1509
  error= (bool) (ha_resize_key_cache(key_cache));
1993
1510
 
1994
1511
  pthread_mutex_lock(&LOCK_global_system_variables);
1995
 
  key_cache->in_init= 0;  
 
1512
  key_cache->in_init= 0;
1996
1513
 
1997
1514
end:
1998
1515
  pthread_mutex_unlock(&LOCK_global_system_variables);
2000
1517
}
2001
1518
 
2002
1519
 
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
1520
/****************************************************************************/
2146
1521
 
2147
 
bool sys_var_timestamp::update(THD *thd,  set_var *var)
 
1522
bool sys_var_timestamp::update(Session *session,  set_var *var)
2148
1523
{
2149
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
1524
  session->set_time((time_t) var->save_result.uint64_t_value);
2150
1525
  return 0;
2151
1526
}
2152
1527
 
2153
1528
 
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=
 
1529
void sys_var_timestamp::set_default(Session *session, enum_var_type)
 
1530
{
 
1531
  session->user_time=0;
 
1532
}
 
1533
 
 
1534
 
 
1535
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
 
1536
                                            const LEX_STRING *)
 
1537
{
 
1538
  session->sys_var_tmp.long_value= (long) session->start_time;
 
1539
  return (unsigned char*) &session->sys_var_tmp.long_value;
 
1540
}
 
1541
 
 
1542
 
 
1543
bool sys_var_last_insert_id::update(Session *session, set_var *var)
 
1544
{
 
1545
  session->first_successful_insert_id_in_prev_stmt=
2173
1546
    var->save_result.uint64_t_value;
2174
1547
  return 0;
2175
1548
}
2176
1549
 
2177
1550
 
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)))
 
1551
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
 
1552
                                                 enum_var_type,
 
1553
                                                 const LEX_STRING *)
2181
1554
{
2182
1555
  /*
2183
1556
    this tmp var makes it robust againt change of type of
2184
1557
    read_first_successful_insert_id_in_prev_stmt().
2185
1558
  */
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)
 
1559
  session->sys_var_tmp.uint64_t_value=
 
1560
    session->read_first_successful_insert_id_in_prev_stmt();
 
1561
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
1562
}
 
1563
 
 
1564
 
 
1565
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2223
1566
{
2224
1567
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2225
1568
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2226
1569
  String *res= var->value->val_str(&str);
2227
1570
 
2228
 
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
 
1571
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
2229
1572
  {
2230
1573
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2231
1574
    return 1;
2234
1577
}
2235
1578
 
2236
1579
 
2237
 
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
 
1580
bool sys_var_session_time_zone::update(Session *session, set_var *var)
2238
1581
{
2239
1582
  /* We are using Time_zone object found during check() phase. */
2240
1583
  if (var->type == OPT_GLOBAL)
2244
1587
    pthread_mutex_unlock(&LOCK_global_system_variables);
2245
1588
  }
2246
1589
  else
2247
 
    thd->variables.time_zone= var->save_result.time_zone;
 
1590
    session->variables.time_zone= var->save_result.time_zone;
2248
1591
  return 0;
2249
1592
}
2250
1593
 
2251
1594
 
2252
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2253
 
                                        LEX_STRING *base __attribute__((unused)))
 
1595
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
 
1596
                                                    enum_var_type type,
 
1597
                                                    const LEX_STRING *)
2254
1598
{
2255
 
  /* 
 
1599
  /*
2256
1600
    We can use ptr() instead of c_ptr() here because String contaning
2257
1601
    time zone name is guaranteed to be zero ended.
2258
1602
  */
2268
1612
      timezone). If it's the global value which was used we can't replicate
2269
1613
      (binlog code stores session value only).
2270
1614
    */
2271
 
    thd->time_zone_used= 1;
2272
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
1615
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
2273
1616
  }
2274
1617
}
2275
1618
 
2276
1619
 
2277
 
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
 
1620
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
2278
1621
{
2279
1622
 pthread_mutex_lock(&LOCK_global_system_variables);
2280
1623
 if (type == OPT_GLOBAL)
2286
1629
       We are guaranteed to find this time zone since its existence
2287
1630
       is checked during start-up.
2288
1631
     */
2289
 
     global_system_variables.time_zone= my_tz_find(thd, &str);
 
1632
     global_system_variables.time_zone= my_tz_find(session, &str);
2290
1633
   }
2291
1634
   else
2292
1635
     global_system_variables.time_zone= my_tz_SYSTEM;
2293
1636
 }
2294
1637
 else
2295
 
   thd->variables.time_zone= global_system_variables.time_zone;
 
1638
   session->variables.time_zone= global_system_variables.time_zone;
2296
1639
 pthread_mutex_unlock(&LOCK_global_system_variables);
2297
1640
}
2298
1641
 
2299
1642
 
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)
 
1643
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
2348
1644
{
2349
1645
  MY_LOCALE *locale_match;
2350
1646
 
2351
1647
  if (var->value->result_type() == INT_RESULT)
2352
1648
  {
2353
 
    if (!(locale_match= my_locale_by_number((uint) var->value->val_int())))
 
1649
    if (!(locale_match= my_locale_by_number((uint32_t) var->value->val_int())))
2354
1650
    {
2355
1651
      char buf[20];
2356
1652
      int10_to_str((int) var->value->val_int(), buf, -10);
2360
1656
  }
2361
1657
  else // STRING_RESULT
2362
1658
  {
2363
 
    char buff[6]; 
 
1659
    char buff[6];
2364
1660
    String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
2365
1661
    if (!(res=var->value->val_str(&str)))
2366
1662
    {
2381
1677
}
2382
1678
 
2383
1679
 
2384
 
bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var)
 
1680
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2385
1681
{
2386
1682
  if (var->type == OPT_GLOBAL)
2387
1683
    global_system_variables.lc_time_names= var->save_result.locale_value;
2388
1684
  else
2389
 
    thd->variables.lc_time_names= var->save_result.locale_value;
 
1685
    session->variables.lc_time_names= var->save_result.locale_value;
2390
1686
  return 0;
2391
1687
}
2392
1688
 
2393
1689
 
2394
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2395
 
                                            enum_var_type type,
2396
 
                                            LEX_STRING *base __attribute__((unused)))
 
1690
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
 
1691
                                                        enum_var_type type,
 
1692
                                                        const LEX_STRING *)
2397
1693
{
2398
1694
  return type == OPT_GLOBAL ?
2399
1695
                 (unsigned char *) global_system_variables.lc_time_names->name :
2400
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
1696
                 (unsigned char *) session->variables.lc_time_names->name;
2401
1697
}
2402
1698
 
2403
1699
 
2404
 
void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type)
 
1700
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
2405
1701
{
2406
1702
  if (type == OPT_GLOBAL)
2407
1703
    global_system_variables.lc_time_names= my_default_lc_time_names;
2408
1704
  else
2409
 
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
 
1705
    session->variables.lc_time_names= global_system_variables.lc_time_names;
2410
1706
}
2411
1707
 
2412
1708
/*
2418
1714
    This is used for handling long_query_time
2419
1715
*/
2420
1716
 
2421
 
bool sys_var_microseconds::update(THD *thd, set_var *var)
 
1717
bool sys_var_microseconds::update(Session *session, set_var *var)
2422
1718
{
2423
1719
  double num= var->value->val_real();
2424
1720
  int64_t microseconds;
2434
1730
    pthread_mutex_unlock(&LOCK_global_system_variables);
2435
1731
  }
2436
1732
  else
2437
 
    thd->variables.*offset= microseconds;
 
1733
    session->variables.*offset= microseconds;
2438
1734
  return 0;
2439
1735
}
2440
1736
 
2441
1737
 
2442
 
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
 
1738
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
2443
1739
{
2444
1740
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
2445
1741
  if (type == OPT_GLOBAL)
2449
1745
    pthread_mutex_unlock(&LOCK_global_system_variables);
2450
1746
  }
2451
1747
  else
2452
 
    thd->variables.*offset= microseconds;
 
1748
    session->variables.*offset= microseconds;
2453
1749
}
2454
1750
 
2455
1751
 
2456
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2457
 
                                          LEX_STRING *base __attribute__((unused)))
 
1752
unsigned char *sys_var_microseconds::value_ptr(Session *session,
 
1753
                                               enum_var_type type,
 
1754
                                               const LEX_STRING *)
2458
1755
{
2459
 
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
1756
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2460
1757
                                   global_system_variables.*offset :
2461
 
                                   thd->variables.*offset) / 1000000.0;
2462
 
  return (unsigned char*) &thd->tmp_double_value;
 
1758
                                   session->variables.*offset) / 1000000.0;
 
1759
  return (unsigned char*) &session->tmp_double_value;
2463
1760
}
2464
1761
 
2465
1762
 
2466
1763
/*
2467
 
  Functions to update thd->options bits
 
1764
  Functions to update session->options bits
2468
1765
*/
2469
1766
 
2470
 
static bool set_option_bit(THD *thd, set_var *var)
 
1767
static bool set_option_bit(Session *session, set_var *var)
2471
1768
{
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;
 
1769
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
 
1770
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
1771
    session->options&= ~sys_var->bit_flag;
2475
1772
  else
2476
 
    thd->options|= sys_var->bit_flag;
 
1773
    session->options|= sys_var->bit_flag;
2477
1774
  return 0;
2478
1775
}
2479
1776
 
2480
1777
 
2481
 
static bool set_option_autocommit(THD *thd, set_var *var)
 
1778
static bool set_option_autocommit(Session *session, set_var *var)
2482
1779
{
2483
1780
  /* The test is negative as the flag we use is NOT autocommit */
2484
1781
 
2485
 
  uint64_t org_options= thd->options;
 
1782
  uint64_t org_options= session->options;
2486
1783
 
2487
 
  if (var->save_result.ulong_value != 0)
2488
 
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
 
1784
  if (var->save_result.uint32_t_value != 0)
 
1785
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2489
1786
  else
2490
 
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
 
1787
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2491
1788
 
2492
 
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
 
1789
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2493
1790
  {
2494
1791
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2495
1792
    {
2496
1793
      /* 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))
 
1794
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
1795
      session->transaction.all.modified_non_trans_table= false;
 
1796
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
1797
      if (ha_commit(session))
2501
1798
        return 1;
2502
1799
    }
2503
1800
    else
2504
1801
    {
2505
 
      thd->transaction.all.modified_non_trans_table= false;
2506
 
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
1802
      session->transaction.all.modified_non_trans_table= false;
 
1803
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2507
1804
    }
2508
1805
  }
2509
1806
  return 0;
2510
1807
}
2511
1808
 
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)
 
1809
static int check_pseudo_thread_id(Session *, set_var *var)
2521
1810
{
2522
1811
  var->save_result.uint64_t_value= var->value->val_int();
2523
1812
  return 0;
2524
1813
}
2525
1814
 
2526
 
static unsigned char *get_warning_count(THD *thd)
 
1815
static unsigned char *get_warning_count(Session *session)
2527
1816
{
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;
 
1817
  session->sys_var_tmp.uint32_t_value=
 
1818
    (session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
 
1819
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
 
1820
     session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
 
1821
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2533
1822
}
2534
1823
 
2535
 
static unsigned char *get_error_count(THD *thd)
 
1824
static unsigned char *get_error_count(Session *session)
2536
1825
{
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;
 
1826
  session->sys_var_tmp.uint32_t_value=
 
1827
    session->warn_count[(uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
 
1828
  return (unsigned char*) &session->sys_var_tmp.uint32_t_value;
2540
1829
}
2541
1830
 
2542
1831
 
2545
1834
 
2546
1835
  This is necessary because if the user does not specify a temporary
2547
1836
  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
 
1837
  or system defaults.  But we can't just always use drizzle_tmpdir, because
2549
1838
  that is actually a call to my_tmpdir() which cycles among possible
2550
1839
  temporary directories.
2551
1840
 
2552
 
  @param thd            thread handle
 
1841
  @param session                thread handle
2553
1842
 
2554
1843
  @retval
2555
1844
    ptr         pointer to NUL-terminated string
2556
1845
*/
2557
 
static unsigned char *get_tmpdir(THD *thd __attribute__((unused)))
 
1846
static unsigned char *get_tmpdir(Session *)
2558
1847
{
2559
 
  if (opt_mysql_tmpdir)
2560
 
    return (unsigned char *)opt_mysql_tmpdir;
2561
 
  return (unsigned char*)mysql_tmpdir;
 
1848
  assert(drizzle_tmpdir);
 
1849
  return (unsigned char*)drizzle_tmpdir;
2562
1850
}
2563
1851
 
2564
1852
/****************************************************************************
2581
1869
    ptr         pointer to option structure
2582
1870
*/
2583
1871
 
2584
 
static struct my_option *find_option(struct my_option *opt, const char *name) 
 
1872
static struct my_option *find_option(struct my_option *opt, const char *name)
2585
1873
{
2586
1874
  uint32_t length=strlen(name);
2587
1875
  for (; opt->name; opt++)
2600
1888
}
2601
1889
 
2602
1890
 
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
1891
/*
2616
1892
  Add variables to the dynamic hash of system variables
2617
 
  
 
1893
 
2618
1894
  SYNOPSIS
2619
1895
    mysql_add_sys_var_chain()
2620
1896
    first       Pointer to first system variable to add
2621
1897
    long_opt    (optional)command line arguments may be tied for limit checks.
2622
 
  
 
1898
 
2623
1899
  RETURN VALUES
2624
1900
    0           SUCCESS
2625
1901
    otherwise   FAILURE
2629
1905
int mysql_add_sys_var_chain(sys_var *first, struct my_option *long_options)
2630
1906
{
2631
1907
  sys_var *var;
2632
 
  
2633
1908
  /* A write lock should be held on LOCK_system_variables_hash */
2634
 
  
 
1909
 
2635
1910
  for (var= first; var; var= var->next)
2636
1911
  {
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;
 
1912
    /* Make a temp string to hold this and then make it lower so that matching
 
1913
     * happens case-insensitive.
 
1914
     */
 
1915
    string var_name(var->name);
 
1916
    transform(var_name.begin(), var_name.end(), var_name.begin(), ::tolower);
 
1917
    var->name_length= var_name.length();
 
1918
 
 
1919
    /* this fails if there is a conflicting variable name. */
 
1920
    if (system_variable_hash.count(var_name) == 0)
 
1921
    {
 
1922
      system_variable_hash[var_name]= var;
 
1923
    } 
 
1924
    else
 
1925
    {
 
1926
      for (; first != var; first= first->next)
 
1927
      {
 
1928
        /*
 
1929
         * This is slightly expensive, since we have to do the transform 
 
1930
         * _again_ but should rarely happen unless there is a pretty
 
1931
         * major problem in the code
 
1932
         */
 
1933
        var_name= first->name;
 
1934
        transform(var_name.begin(), var_name.end(),
 
1935
                  var_name.begin(), ::tolower);
 
1936
        system_variable_hash.erase(var_name);
 
1937
      }
 
1938
      return 1;
 
1939
    }
2641
1940
    if (long_options)
2642
1941
      var->option_limits= find_option(long_options, var->name);
2643
1942
  }
2644
1943
  return 0;
2645
1944
 
2646
 
error:
2647
 
  for (; first != var; first= first->next)
2648
 
    hash_delete(&system_variable_hash, (unsigned char*) first);
2649
 
  return 1;
2650
1945
}
2651
 
 
2652
 
 
 
1946
 
 
1947
 
2653
1948
/*
2654
1949
  Remove variables to the dynamic hash of system variables
2655
 
   
 
1950
 
2656
1951
  SYNOPSIS
2657
1952
    mysql_del_sys_var_chain()
2658
1953
    first       Pointer to first system variable to remove
2659
 
   
 
1954
 
2660
1955
  RETURN VALUES
2661
1956
    0           SUCCESS
2662
1957
    otherwise   FAILURE
2663
1958
*/
2664
 
 
 
1959
 
2665
1960
int mysql_del_sys_var_chain(sys_var *first)
2666
1961
{
2667
1962
  int result= 0;
2668
 
 
 
1963
  string var_name;
 
1964
 
2669
1965
  /* A write lock should be held on LOCK_system_variables_hash */
2670
 
   
2671
1966
  for (sys_var *var= first; var; var= var->next)
2672
 
    result|= hash_delete(&system_variable_hash, (unsigned char*) var);
 
1967
  {
 
1968
    var_name= var->name;
 
1969
    transform(var_name.begin(), var_name.end(),
 
1970
              var_name.begin(), ::tolower);
 
1971
    result|= system_variable_hash.erase(var_name);
 
1972
  }
2673
1973
 
2674
1974
  return result;
2675
1975
}
2676
 
 
2677
 
 
2678
 
static int show_cmp(SHOW_VAR *a, SHOW_VAR *b)
2679
 
{
2680
 
  return strcmp(a->name, b->name);
2681
 
}
2682
 
 
2683
 
 
 
1976
 
 
1977
 
 
1978
 
2684
1979
/*
2685
1980
  Constructs an array of system variables for display to the user.
2686
 
  
 
1981
 
2687
1982
  SYNOPSIS
2688
1983
    enumerate_sys_vars()
2689
 
    thd         current thread
 
1984
    session         current thread
2690
1985
    sorted      If TRUE, the system variables should be sorted
2691
 
  
 
1986
 
2692
1987
  RETURN VALUES
2693
1988
    pointer     Array of SHOW_VAR elements for display
2694
1989
    NULL        FAILURE
2695
1990
*/
2696
1991
 
2697
 
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
 
1992
SHOW_VAR* enumerate_sys_vars(Session *session, bool)
2698
1993
{
2699
 
  int count= system_variable_hash.records, i;
2700
1994
  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);
 
1995
  int size= sizeof(SHOW_VAR) * (system_variable_hash.size() + fixed_count + 1);
 
1996
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2703
1997
 
2704
1998
  if (result)
2705
1999
  {
2706
2000
    SHOW_VAR *show= result + fixed_count;
2707
2001
    memcpy(result, fixed_show_vars.buffer, fixed_count * sizeof(SHOW_VAR));
2708
2002
 
2709
 
    for (i= 0; i < count; i++)
 
2003
    map<string, sys_var *>::iterator iter;
 
2004
    for(iter= system_variable_hash.begin();
 
2005
        iter != system_variable_hash.end();
 
2006
        iter++)
2710
2007
    {
2711
 
      sys_var *var= (sys_var*) hash_element(&system_variable_hash, i);
 
2008
      sys_var *var= (*iter).second;
2712
2009
      show->name= var->name;
2713
2010
      show->value= (char*) var;
2714
2011
      show->type= SHOW_SYS;
2715
2012
      show++;
2716
2013
    }
2717
2014
 
2718
 
    /* sort into order */
2719
 
    if (sorted)
2720
 
      my_qsort(result, count + fixed_count, sizeof(SHOW_VAR),
2721
 
               (qsort_cmp) show_cmp);
2722
 
    
2723
2015
    /* make last element empty */
2724
2016
    memset(show, 0, sizeof(SHOW_VAR));
2725
2017
  }
2727
2019
}
2728
2020
 
2729
2021
 
 
2022
NAMED_LIST::NAMED_LIST(I_List<NAMED_LIST> *links, const char *name_arg,
 
2023
                       uint32_t name_length_arg, unsigned char* data_arg)
 
2024
    :data(data_arg)
 
2025
{
 
2026
  name.assign(name_arg, name_length_arg);
 
2027
  links->push_back(this);
 
2028
}
 
2029
 
 
2030
 
 
2031
bool NAMED_LIST::cmp(const char *name_cmp, uint32_t length)
 
2032
{
 
2033
  return length == name.length() && !name.compare(name_cmp);
 
2034
}
 
2035
 
 
2036
 
2730
2037
/*
2731
2038
  Initialize the system variables
2732
 
  
 
2039
 
2733
2040
  SYNOPSIS
2734
2041
    set_var_init()
2735
 
  
 
2042
 
2736
2043
  RETURN VALUES
2737
2044
    0           SUCCESS
2738
2045
    otherwise   FAILURE
2741
2048
int set_var_init()
2742
2049
{
2743
2050
  uint32_t count= 0;
2744
 
  
 
2051
 
2745
2052
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2746
2053
 
2747
2054
  if (my_init_dynamic_array(&fixed_show_vars, sizeof(SHOW_VAR),
2751
2058
  fixed_show_vars.elements= FIXED_VARS_SIZE;
2752
2059
  memcpy(fixed_show_vars.buffer, fixed_vars, sizeof(fixed_vars));
2753
2060
 
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
2061
  vars.last->next= NULL;
2759
2062
  if (mysql_add_sys_var_chain(vars.first, my_long_options))
2760
2063
    goto error;
2769
2072
 
2770
2073
void set_var_free()
2771
2074
{
2772
 
  hash_free(&system_variable_hash);
2773
2075
  delete_dynamic(&fixed_show_vars);
2774
2076
}
2775
2077
 
2776
2078
 
2777
2079
/*
2778
2080
  Add elements to the dynamic list of read-only system variables.
2779
 
  
 
2081
 
2780
2082
  SYNOPSIS
2781
2083
    mysql_append_static_vars()
2782
2084
    show_vars   Pointer to start of array
2783
2085
    count       Number of elements
2784
 
  
 
2086
 
2785
2087
  RETURN VALUES
2786
2088
    0           SUCCESS
2787
2089
    otherwise   FAILURE
2809
2111
    0           Unknown variable (error message is given)
2810
2112
*/
2811
2113
 
2812
 
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
 
2114
sys_var *intern_find_sys_var(const char *str, uint32_t, bool no_error)
2813
2115
{
2814
 
  sys_var *var;
2815
 
 
2816
2116
  /*
2817
2117
    This function is only called from the sql_plugin.cc.
2818
2118
    A lock on LOCK_system_variable_hash should be held
2819
2119
  */
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);
 
2120
  string lower_var(str);
 
2121
  transform(lower_var.begin(), lower_var.end(), lower_var.begin(), ::tolower);
 
2122
  map<string, sys_var *>::iterator result_iter=
 
2123
    system_variable_hash.find(lower_var);
 
2124
  if (result_iter == system_variable_hash.end())
 
2125
  {
 
2126
    if (no_error)
 
2127
    {
 
2128
      return NULL;
 
2129
    }
 
2130
    else
 
2131
    {
 
2132
      my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
 
2133
      return NULL;
 
2134
    }
 
2135
  }
2824
2136
 
2825
 
  return var;
 
2137
  return (*result_iter).second;
2826
2138
}
2827
2139
 
2828
2140
 
2835
2147
  This should ensure that in all normal cases none all or variables are
2836
2148
  updated.
2837
2149
 
2838
 
  @param THD            Thread id
 
2150
  @param Session                Thread id
2839
2151
  @param var_list       List of variables to update
2840
2152
 
2841
2153
  @retval
2846
2158
    -1  ERROR, message not sent
2847
2159
*/
2848
2160
 
2849
 
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
 
2161
int sql_set_variables(Session *session, List<set_var_base> *var_list)
2850
2162
{
2851
2163
  int error;
2852
2164
  List_iterator_fast<set_var_base> it(*var_list);
2854
2166
  set_var_base *var;
2855
2167
  while ((var=it++))
2856
2168
  {
2857
 
    if ((error= var->check(thd)))
 
2169
    if ((error= var->check(session)))
2858
2170
      goto err;
2859
2171
  }
2860
 
  if (!(error= test(thd->is_error())))
 
2172
  if (!(error= test(session->is_error())))
2861
2173
  {
2862
2174
    it.rewind();
2863
2175
    while ((var= it++))
2864
 
      error|= var->update(thd);         // Returns 0, -1 or 1
 
2176
      error|= var->update(session);         // Returns 0, -1 or 1
2865
2177
  }
2866
2178
 
2867
2179
err:
2868
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
2180
  free_underlaid_joins(session, &session->lex->select_lex);
2869
2181
  return(error);
2870
2182
}
2871
2183
 
2872
2184
 
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
2185
/*****************************************************************************
2903
2186
  Functions to handle SET mysql_internal_variable=const_expr
2904
2187
*****************************************************************************/
2905
2188
 
2906
 
int set_var::check(THD *thd)
 
2189
int set_var::check(Session *session)
2907
2190
{
2908
2191
  if (var->is_readonly())
2909
2192
  {
2928
2211
  }
2929
2212
 
2930
2213
  if ((!value->fixed &&
2931
 
       value->fix_fields(thd, &value)) || value->check_cols(1))
 
2214
       value->fix_fields(session, &value)) || value->check_cols(1))
2932
2215
    return -1;
2933
2216
  if (var->check_update_type(value->result_type()))
2934
2217
  {
2935
2218
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
2936
2219
    return -1;
2937
2220
  }
2938
 
  return var->check(thd, this) ? -1 : 0;
 
2221
  return var->check(session, this) ? -1 : 0;
2939
2222
}
2940
2223
 
2941
2224
/**
2942
2225
  Update variable
2943
2226
 
2944
 
  @param   thd    thread handler
 
2227
  @param   session    thread handler
2945
2228
  @returns 0|1    ok or ERROR
2946
2229
 
2947
2230
  @note ERROR can be only due to abnormal operations involving
2950
2233
  Consider set_var::check() method if there is a need to return
2951
2234
  an error due to logics.
2952
2235
*/
2953
 
int set_var::update(THD *thd)
 
2236
int set_var::update(Session *session)
2954
2237
{
2955
2238
  if (!value)
2956
 
    var->set_default(thd, type);
2957
 
  else if (var->update(thd, this))
 
2239
    var->set_default(session, type);
 
2240
  else if (var->update(session, this))
2958
2241
    return -1;                          // should never happen
2959
2242
  if (var->after_update)
2960
 
    (*var->after_update)(thd, type);
 
2243
    (*var->after_update)(session, type);
2961
2244
  return 0;
2962
2245
}
2963
2246
 
2966
2249
  Functions to handle SET @user_variable=const_expr
2967
2250
*****************************************************************************/
2968
2251
 
2969
 
int set_var_user::check(THD *thd)
 
2252
int set_var_user::check(Session *session)
2970
2253
{
2971
2254
  /*
2972
2255
    Item_func_set_user_var can't substitute something else on its place =>
2973
2256
    0 can be passed as last argument (reference on item)
2974
2257
  */
2975
 
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
 
2258
  return (user_var_item->fix_fields(session, (Item**) 0) ||
2976
2259
          user_var_item->check(0)) ? -1 : 0;
2977
2260
}
2978
2261
 
2979
2262
 
2980
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
2263
int set_var_user::update(Session *)
2981
2264
{
2982
2265
  if (user_var_item->update())
2983
2266
  {
2994
2277
 
2995
2278
/* Based upon sys_var::check_enum() */
2996
2279
 
2997
 
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
 
2280
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
2998
2281
{
2999
2282
  char buff[STRING_BUFFER_USUAL_SIZE];
3000
2283
  const char *value;
3001
2284
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci), *res;
3002
2285
 
3003
 
  var->save_result.plugin= NULL;
 
2286
  var->save_result.storage_engine= NULL;
3004
2287
  if (var->value->result_type() == STRING_RESULT)
3005
2288
  {
3006
2289
    LEX_STRING engine_name;
3007
 
    handlerton *hton;
 
2290
    StorageEngine *engine;
3008
2291
    if (!(res=var->value->val_str(&str)) ||
3009
2292
        !(engine_name.str= (char *)res->ptr()) ||
3010
2293
        !(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 *)))
 
2294
              !(var->save_result.storage_engine=
 
2295
            ha_resolve_by_name(session, &engine_name)) ||
 
2296
        !(engine= var->save_result.storage_engine))
3013
2297
    {
3014
2298
      value= res ? res->c_ptr() : "NULL";
3015
2299
      goto err;
3024
2308
}
3025
2309
 
3026
2310
 
3027
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3028
 
                                             LEX_STRING *base __attribute__((unused)))
 
2311
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
 
2312
                                                         enum_var_type type,
 
2313
                                                         const LEX_STRING *)
3029
2314
{
3030
2315
  unsigned char* result;
3031
 
  handlerton *hton;
3032
 
  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);
 
2316
  string engine_name;
 
2317
  StorageEngine *engine= session->variables.*offset;
 
2318
  if (type == OPT_GLOBAL)
 
2319
    engine= global_system_variables.*offset;
 
2320
  engine_name= engine->getName();
 
2321
  result= (unsigned char *) session->strmake(engine_name.c_str(),
 
2322
                                             engine_name.size());
3041
2323
  return result;
3042
2324
}
3043
2325
 
3044
2326
 
3045
 
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
 
2327
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
3046
2328
{
3047
 
  plugin_ref old_value, new_value, *value;
 
2329
  StorageEngine *old_value, *new_value, **value;
3048
2330
  if (type == OPT_GLOBAL)
3049
2331
  {
3050
2332
    value= &(global_system_variables.*offset);
3051
 
    new_value= ha_lock_engine(NULL, myisam_hton);
 
2333
    new_value= myisam_engine;
3052
2334
  }
3053
2335
  else
3054
2336
  {
3055
 
    value= &(thd->variables.*offset);
3056
 
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
 
2337
    value= &(session->variables.*offset);
 
2338
    new_value= global_system_variables.*offset;
3057
2339
  }
3058
2340
  assert(new_value);
3059
2341
  old_value= *value;
3060
2342
  *value= new_value;
3061
 
  plugin_unlock(NULL, old_value);
3062
2343
}
3063
2344
 
3064
2345
 
3065
 
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
 
2346
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3066
2347
{
3067
 
  plugin_ref *value= &(global_system_variables.*offset), old_value;
 
2348
  StorageEngine **value= &(global_system_variables.*offset), *old_value;
3068
2349
   if (var->type != OPT_GLOBAL)
3069
 
     value= &(thd->variables.*offset);
 
2350
     value= &(session->variables.*offset);
3070
2351
  old_value= *value;
3071
 
  if (old_value != var->save_result.plugin)
 
2352
  if (old_value != var->save_result.storage_engine)
3072
2353
  {
3073
 
    *value= my_plugin_lock(NULL, &var->save_result.plugin);
3074
 
    plugin_unlock(NULL, old_value);
 
2354
    *value= var->save_result.storage_engine;
3075
2355
  }
3076
2356
  return 0;
3077
2357
}
3078
2358
 
3079
2359
bool
3080
 
sys_var_thd_optimizer_switch::
3081
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
2360
sys_var_session_optimizer_switch::
 
2361
symbolic_mode_representation(Session *session, uint32_t val, LEX_STRING *rep)
3082
2362
{
3083
2363
  char buff[STRING_BUFFER_USUAL_SIZE*8];
3084
2364
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
3098
2378
  if (tmp.length())
3099
2379
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
3100
2380
 
3101
 
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
 
2381
  rep->str= session->strmake(tmp.ptr(), tmp.length());
3102
2382
 
3103
2383
  rep->length= rep->str ? tmp.length() : 0;
3104
2384
 
3106
2386
}
3107
2387
 
3108
2388
 
3109
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3110
 
                                               LEX_STRING *base __attribute__((unused)))
 
2389
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
 
2390
                                                           enum_var_type type,
 
2391
                                                           const LEX_STRING *)
3111
2392
{
3112
2393
  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);
 
2394
  uint32_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
 
2395
                  session->variables.*offset);
 
2396
  (void) symbolic_mode_representation(session, val, &opts);
3116
2397
  return (unsigned char *) opts.str;
3117
2398
}
3118
2399
 
3119
2400
 
3120
 
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
 
2401
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3121
2402
{
3122
2403
  if (type == OPT_GLOBAL)
3123
2404
    global_system_variables.*offset= 0;
3124
2405
  else
3125
 
    thd->variables.*offset= global_system_variables.*offset;
 
2406
    session->variables.*offset= global_system_variables.*offset;
3126
2407
}
3127
2408
 
3128
2409
 
3154
2435
  NAMED_LIST *element;
3155
2436
  while ((element= list->get()))
3156
2437
  {
3157
 
    (*free_element)(element->name, element->data);
 
2438
    (*free_element)(element->name.c_str(), element->data);
3158
2439
    delete element;
3159
2440
  }
3160
2441
  return;
3166
2447
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
3167
2448
{
3168
2449
  KEY_CACHE *key_cache;
3169
 
  
3170
 
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3171
 
                                             MYF(MY_ZEROFILL | MY_WME))))
 
2450
 
 
2451
  if ((key_cache= (KEY_CACHE*) malloc(sizeof(KEY_CACHE))))
3172
2452
  {
 
2453
    memset(key_cache, 0, sizeof(KEY_CACHE));
3173
2454
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
3174
2455
    {
3175
2456
      free((char*) key_cache);
3207
2488
}
3208
2489
 
3209
2490
 
3210
 
void free_key_cache(const char *name __attribute__((unused)),
3211
 
                    KEY_CACHE *key_cache)
 
2491
void free_key_cache(const char *, KEY_CACHE *key_cache)
3212
2492
{
3213
2493
  ha_end_key_cache(key_cache);
3214
2494
  free((char*) key_cache);
3223
2503
  while ((element= it++))
3224
2504
  {
3225
2505
    KEY_CACHE *key_cache= (KEY_CACHE *) element->data;
3226
 
    func(element->name, key_cache);
 
2506
    func(element->name.c_str(), key_cache);
3227
2507
  }
3228
2508
  return 0;
3229
2509
}
3230
2510
 
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
2511
/****************************************************************************
3294
2512
  Used templates
3295
2513
****************************************************************************/