~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-11-04 15:39:09 UTC
  • mfrom: (575.1.2 devel)
  • Revision ID: brian@tangent.org-20081104153909-c72hn65udxs1ccal
Merge of Monty's work

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
55
#include "rpl_mi.h"
51
56
#include <mysys/my_getopt.h>
52
57
#include <mysys/thr_alarm.h>
53
58
#include <storage/myisam/myisam.h>
54
 
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
 
59
#include <drizzled/error.h>
 
60
#include <drizzled/gettext.h>
 
61
#include <drizzled/tztime.h>
 
62
#include <drizzled/slave.h>
 
63
#include <drizzled/data_home.h>
56
64
 
57
65
extern const CHARSET_INFO *character_set_filesystem;
58
66
 
60
68
static DYNAMIC_ARRAY fixed_show_vars;
61
69
static HASH system_variable_hash;
62
70
 
63
 
const char *bool_type_names[]= { "OFF", "ON", NullS };
 
71
const char *bool_type_names[]= { "OFF", "ON", NULL };
64
72
TYPELIB bool_typelib=
65
73
{
66
74
  array_elements(bool_type_names)-1, "", bool_type_names, NULL
67
75
};
68
76
 
69
 
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NullS };
 
77
const char *delay_key_write_type_names[]= { "OFF", "ON", "ALL", NULL };
70
78
TYPELIB delay_key_write_typelib=
71
79
{
72
80
  array_elements(delay_key_write_type_names)-1, "",
74
82
};
75
83
 
76
84
const char *slave_exec_mode_names[]=
77
 
{ "STRICT", "IDEMPOTENT", NullS };
 
85
{ "STRICT", "IDEMPOTENT", NULL };
78
86
static const unsigned int slave_exec_mode_names_len[]=
79
87
{ sizeof("STRICT") - 1, sizeof("IDEMPOTENT") - 1, 0 };
80
88
TYPELIB slave_exec_mode_typelib=
83
91
  slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
84
92
};
85
93
 
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 bool set_log_update(THD *thd, set_var *var);
94
 
static int  check_pseudo_thread_id(THD *thd, set_var *var);
95
 
static void fix_low_priority_updates(THD *thd, enum_var_type type);
96
 
static int check_tx_isolation(THD *thd, set_var *var);
97
 
static void fix_tx_isolation(THD *thd, enum_var_type type);
98
 
static int check_completion_type(THD *thd, set_var *var);
99
 
static void fix_completion_type(THD *thd, enum_var_type type);
100
 
static void fix_net_read_timeout(THD *thd, enum_var_type type);
101
 
static void fix_net_write_timeout(THD *thd, enum_var_type type);
102
 
static void fix_net_retry_count(THD *thd, enum_var_type type);
103
 
static void fix_max_join_size(THD *thd, enum_var_type type);
104
 
static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type);
105
 
static void fix_max_binlog_size(THD *thd, enum_var_type type);
106
 
static void fix_max_relay_log_size(THD *thd, enum_var_type type);
107
 
static void fix_max_connections(THD *thd, enum_var_type type);
108
 
static void fix_thd_mem_root(THD *thd, enum_var_type type);
109
 
static void fix_trans_mem_root(THD *thd, enum_var_type type);
110
 
static void fix_server_id(THD *thd, enum_var_type type);
111
 
static uint64_t fix_unsigned(THD *, uint64_t, const struct my_option *);
112
 
static bool get_unsigned(THD *thd, set_var *var);
113
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
94
static bool sys_update_init_connect(Session*, set_var*);
 
95
static void sys_default_init_connect(Session*, enum_var_type type);
 
96
static bool sys_update_init_slave(Session*, set_var*);
 
97
static void sys_default_init_slave(Session*, enum_var_type type);
 
98
static bool set_option_bit(Session *session, set_var *var);
 
99
static bool set_option_autocommit(Session *session, set_var *var);
 
100
static int  check_log_update(Session *session, set_var *var);
 
101
static int  check_pseudo_thread_id(Session *session, set_var *var);
 
102
static void fix_low_priority_updates(Session *session, enum_var_type type);
 
103
static int check_tx_isolation(Session *session, set_var *var);
 
104
static void fix_tx_isolation(Session *session, enum_var_type type);
 
105
static int check_completion_type(Session *session, set_var *var);
 
106
static void fix_completion_type(Session *session, enum_var_type type);
 
107
static void fix_net_read_timeout(Session *session, enum_var_type type);
 
108
static void fix_net_write_timeout(Session *session, enum_var_type type);
 
109
static void fix_net_retry_count(Session *session, enum_var_type type);
 
110
static void fix_max_join_size(Session *session, enum_var_type type);
 
111
static void fix_myisam_max_sort_file_size(Session *session, enum_var_type type);
 
112
static void fix_max_binlog_size(Session *session, enum_var_type type);
 
113
static void fix_max_relay_log_size(Session *session, enum_var_type type);
 
114
static void fix_max_connections(Session *session, enum_var_type type);
 
115
static void fix_session_mem_root(Session *session, enum_var_type type);
 
116
static void fix_trans_mem_root(Session *session, enum_var_type type);
 
117
static void fix_server_id(Session *session, enum_var_type type);
 
118
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
 
119
static bool get_unsigned(Session *session, set_var *var);
 
120
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
114
121
                          const char *name, int64_t val);
115
 
static KEY_CACHE *create_key_cache(const char *name, uint length);
116
 
static uchar *get_error_count(THD *thd);
117
 
static uchar *get_warning_count(THD *thd);
118
 
static uchar *get_tmpdir(THD *thd);
119
 
static int  sys_check_log_path(THD *thd,  set_var *var);
120
 
static bool sys_update_general_log_path(THD *thd, set_var * var);
121
 
static void sys_default_general_log_path(THD *thd, enum_var_type type);
122
 
static bool sys_update_slow_log_path(THD *thd, set_var * var);
123
 
static void sys_default_slow_log_path(THD *thd, enum_var_type type);
 
122
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
 
123
static unsigned char *get_error_count(Session *session);
 
124
static unsigned char *get_warning_count(Session *session);
 
125
static unsigned char *get_tmpdir(Session *session);
124
126
 
125
127
/*
126
128
  Variable definition list
134
136
 
135
137
static sys_var_chain vars = { NULL, NULL };
136
138
 
137
 
static sys_var_thd_ulong
 
139
static sys_var_session_ulong
138
140
sys_auto_increment_increment(&vars, "auto_increment_increment",
139
141
                             &SV::auto_increment_increment, NULL, NULL,
140
142
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
141
 
static sys_var_thd_ulong
 
143
static sys_var_session_ulong
142
144
sys_auto_increment_offset(&vars, "auto_increment_offset",
143
145
                          &SV::auto_increment_offset, NULL, NULL,
144
146
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
146
148
static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
147
149
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
148
150
                                              &binlog_cache_size);
149
 
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
 
151
static sys_var_session_binlog_format sys_binlog_format(&vars, "binlog_format",
150
152
                                            &SV::binlog_format);
151
 
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
153
static sys_var_session_ulong    sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
152
154
                                                  &SV::bulk_insert_buff_size);
153
 
static sys_var_character_set_sv
154
 
sys_character_set_server(&vars, "character_set_server",
155
 
                         &SV::collation_server, &default_charset_info, 0,
156
 
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
157
 
sys_var_const_str       sys_charset_system(&vars, "character_set_system",
158
 
                                           (char *)my_charset_utf8_general_ci.name);
159
 
static sys_var_character_set_database
160
 
sys_character_set_database(&vars, "character_set_database",
161
 
                           sys_var::SESSION_VARIABLE_IN_BINLOG);
162
 
static sys_var_character_set_client
163
 
sys_character_set_client(&vars, "character_set_client",
164
 
                         &SV::character_set_client,
165
 
                         &default_charset_info,
166
 
                         sys_var::SESSION_VARIABLE_IN_BINLOG);
167
 
static sys_var_character_set_sv
168
 
sys_character_set_connection(&vars, "character_set_connection",
169
 
                             &SV::collation_connection,
170
 
                             &default_charset_info, 0,
171
 
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
172
 
static sys_var_character_set_sv sys_character_set_results(&vars, "character_set_results",
173
 
                                        &SV::character_set_results,
174
 
                                        &default_charset_info, true);
175
 
static sys_var_character_set_sv sys_character_set_filesystem(&vars, "character_set_filesystem",
176
 
                                        &SV::character_set_filesystem,
177
 
                                        &character_set_filesystem);
178
 
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
 
155
static sys_var_session_ulong    sys_completion_type(&vars, "completion_type",
179
156
                                         &SV::completion_type,
180
157
                                         check_completion_type,
181
158
                                         fix_completion_type);
208
185
sys_var_str             sys_init_slave(&vars, "init_slave", 0,
209
186
                                       sys_update_init_slave,
210
187
                                       sys_default_init_slave,0);
211
 
static sys_var_thd_ulong        sys_interactive_timeout(&vars, "interactive_timeout",
 
188
static sys_var_session_ulong    sys_interactive_timeout(&vars, "interactive_timeout",
212
189
                                                &SV::net_interactive_timeout);
213
 
static sys_var_thd_ulong        sys_join_buffer_size(&vars, "join_buffer_size",
 
190
static sys_var_session_ulong    sys_join_buffer_size(&vars, "join_buffer_size",
214
191
                                             &SV::join_buff_size);
215
192
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
216
193
static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
224
201
                                                              param_age_threshold));
225
202
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
226
203
                                         &opt_local_infile);
227
 
static sys_var_bool_ptr
228
 
  sys_log_queries_not_using_indexes(&vars, "log_queries_not_using_indexes",
229
 
                                    &opt_log_queries_not_using_indexes);
230
 
static sys_var_thd_ulong        sys_log_warnings(&vars, "log_warnings", &SV::log_warnings);
231
 
static sys_var_microseconds     sys_var_long_query_time(&vars, "long_query_time",
232
 
                                                        &SV::long_query_time);
233
 
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
 
204
static sys_var_session_bool     sys_low_priority_updates(&vars, "low_priority_updates",
234
205
                                                 &SV::low_priority_updates,
235
206
                                                 fix_low_priority_updates);
236
207
#ifndef TO_BE_DELETED   /* Alias for the low_priority_updates */
237
 
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
 
208
static sys_var_session_bool     sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
238
209
                                                     &SV::low_priority_updates,
239
210
                                                     fix_low_priority_updates);
240
211
#endif
241
 
static sys_var_thd_ulong        sys_max_allowed_packet(&vars, "max_allowed_packet",
 
212
static sys_var_session_ulong    sys_max_allowed_packet(&vars, "max_allowed_packet",
242
213
                                               &SV::max_allowed_packet);
243
214
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
244
215
                                                  &max_binlog_cache_size);
250
221
                                            fix_max_connections);
251
222
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
252
223
                                               &max_connect_errors);
253
 
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
 
224
static sys_var_session_ulong    sys_max_error_count(&vars, "max_error_count",
254
225
                                            &SV::max_error_count);
255
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
 
226
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
256
227
                                                &SV::max_heap_table_size);
257
 
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 
228
static sys_var_session_uint64_t sys_pseudo_thread_id(&vars, "pseudo_thread_id",
258
229
                                              &SV::pseudo_thread_id,
259
 
                                              check_pseudo_thread_id, 0,
 
230
                                              0, check_pseudo_thread_id,
260
231
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
261
 
static sys_var_thd_ha_rows      sys_max_join_size(&vars, "max_join_size",
 
232
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
262
233
                                          &SV::max_join_size,
263
234
                                          fix_max_join_size);
264
 
static sys_var_thd_ulong        sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
235
static sys_var_session_ulong    sys_max_seeks_for_key(&vars, "max_seeks_for_key",
265
236
                                              &SV::max_seeks_for_key);
266
 
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
237
static sys_var_session_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
267
238
                                                 &SV::max_length_for_sort_data);
268
239
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
269
240
                                               &max_relay_log_size,
270
241
                                               fix_max_relay_log_size);
271
 
static sys_var_thd_ulong        sys_max_sort_length(&vars, "max_sort_length",
 
242
static sys_var_session_ulong    sys_max_sort_length(&vars, "max_sort_length",
272
243
                                            &SV::max_sort_length);
273
244
static sys_var_max_user_conn   sys_max_user_connections(&vars, "max_user_connections");
274
 
static sys_var_thd_ulong        sys_max_tmp_tables(&vars, "max_tmp_tables",
 
245
static sys_var_session_ulong    sys_max_tmp_tables(&vars, "max_tmp_tables",
275
246
                                           &SV::max_tmp_tables);
276
247
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
277
248
                                                 &max_write_lock_count);
278
 
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
249
static sys_var_session_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
279
250
                                                          &SV::min_examined_row_limit);
280
 
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);
281
 
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
282
 
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
 
251
static sys_var_session_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);
 
252
static sys_var_session_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
 
253
static sys_var_session_ulong    sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
283
254
 
284
 
static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
255
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
285
256
                                                &SV::myisam_stats_method,
286
257
                                                &myisam_stats_method_typelib,
287
258
                                                NULL);
288
 
static sys_var_thd_ulong        sys_net_buffer_length(&vars, "net_buffer_length",
 
259
static sys_var_session_ulong    sys_net_buffer_length(&vars, "net_buffer_length",
289
260
                                              &SV::net_buffer_length);
290
 
static sys_var_thd_ulong        sys_net_read_timeout(&vars, "net_read_timeout",
 
261
static sys_var_session_ulong    sys_net_read_timeout(&vars, "net_read_timeout",
291
262
                                             &SV::net_read_timeout,
292
263
                                             0, fix_net_read_timeout);
293
 
static sys_var_thd_ulong        sys_net_write_timeout(&vars, "net_write_timeout",
 
264
static sys_var_session_ulong    sys_net_write_timeout(&vars, "net_write_timeout",
294
265
                                              &SV::net_write_timeout,
295
266
                                              0, fix_net_write_timeout);
296
 
static sys_var_thd_ulong        sys_net_retry_count(&vars, "net_retry_count",
 
267
static sys_var_session_ulong    sys_net_retry_count(&vars, "net_retry_count",
297
268
                                            &SV::net_retry_count,
298
269
                                            0, fix_net_retry_count);
299
 
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
 
270
static sys_var_session_bool     sys_new_mode(&vars, "new", &SV::new_mode);
300
271
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
301
272
                                       &global_system_variables.old_mode);
302
273
/* these two cannot be static */
303
 
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
 
274
sys_var_session_bool                sys_old_alter_table(&vars, "old_alter_table",
304
275
                                            &SV::old_alter_table);
305
 
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
276
static sys_var_session_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
306
277
                                                  &SV::optimizer_prune_level);
307
 
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
278
static sys_var_session_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
308
279
                                                   &SV::optimizer_search_depth);
309
280
 
310
 
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NullS};
 
281
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
311
282
TYPELIB optimizer_use_mrr_typelib= {
312
283
  array_elements(optimizer_use_mrr_names) - 1, "",
313
284
  optimizer_use_mrr_names, NULL
314
285
};
315
286
 
316
 
static sys_var_thd_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
287
static sys_var_session_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
317
288
                                              &SV::optimizer_use_mrr,
318
289
                                              &optimizer_use_mrr_typelib,
319
290
                                              NULL);
320
291
 
321
 
static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
 
292
static sys_var_session_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
322
293
                                              &SV::preload_buff_size);
323
 
static sys_var_thd_ulong        sys_read_buff_size(&vars, "read_buffer_size",
 
294
static sys_var_session_ulong    sys_read_buff_size(&vars, "read_buffer_size",
324
295
                                           &SV::read_buff_size);
325
296
static sys_var_opt_readonly     sys_readonly(&vars, "read_only", &opt_readonly);
326
 
static sys_var_thd_ulong        sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 
297
static sys_var_session_ulong    sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
327
298
                                               &SV::read_rnd_buff_size);
328
 
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
 
299
static sys_var_session_ulong    sys_div_precincrement(&vars, "div_precision_increment",
329
300
                                              &SV::div_precincrement);
330
 
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
331
 
                                              &rpl_recovery_rank);
332
301
 
333
 
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
302
static sys_var_session_ulong    sys_range_alloc_block_size(&vars, "range_alloc_block_size",
334
303
                                                   &SV::range_alloc_block_size);
335
 
static sys_var_thd_ulong        sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
304
static sys_var_session_ulong    sys_query_alloc_block_size(&vars, "query_alloc_block_size",
336
305
                                                   &SV::query_alloc_block_size,
337
 
                                                   0, fix_thd_mem_root);
338
 
static sys_var_thd_ulong        sys_query_prealloc_size(&vars, "query_prealloc_size",
 
306
                                                   0, fix_session_mem_root);
 
307
static sys_var_session_ulong    sys_query_prealloc_size(&vars, "query_prealloc_size",
339
308
                                                &SV::query_prealloc_size,
340
 
                                                0, fix_thd_mem_root);
 
309
                                                0, fix_session_mem_root);
341
310
static sys_var_readonly        sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
342
 
static sys_var_thd_ulong        sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
311
static sys_var_session_ulong    sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
343
312
                                                   &SV::trans_alloc_block_size,
344
313
                                                   0, fix_trans_mem_root);
345
 
static sys_var_thd_ulong        sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
314
static sys_var_session_ulong    sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
346
315
                                                &SV::trans_prealloc_size,
347
316
                                                0, fix_trans_mem_root);
348
317
 
349
 
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
350
318
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
351
319
                                             &opt_secure_file_priv);
352
 
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
 
320
static sys_var_uint32_t_ptr  sys_server_id(&vars, "server_id", &server_id,
 
321
                                           fix_server_id);
 
322
 
353
323
static sys_var_bool_ptr sys_slave_compressed_protocol(&vars, "slave_compressed_protocol",
354
324
                                                      &opt_slave_compressed_protocol);
355
 
#ifdef HAVE_REPLICATION
356
325
static sys_var_bool_ptr         sys_slave_allow_batching(&vars, "slave_allow_batching",
357
326
                                                         &slave_allow_batching);
358
327
static sys_var_set_slave_mode slave_exec_mode(&vars,
360
329
                                              &slave_exec_mode_options,
361
330
                                              &slave_exec_mode_typelib,
362
331
                                              0);
363
 
#endif
364
332
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
365
333
                                             &slow_launch_time);
366
 
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
 
334
static sys_var_session_ulong    sys_sort_buffer(&vars, "sort_buffer_size",
367
335
                                        &SV::sortbuff_size);
368
336
/*
369
337
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
371
339
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
372
340
  master's (see log_event.cc: Query_log_event::do_apply_event()).
373
341
*/
374
 
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
342
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
375
343
                                     &SV::optimizer_switch);
376
344
 
377
 
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
 
345
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
378
346
                                       &SV::table_plugin);
379
347
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
380
348
                                             system_time_zone);
388
356
                                              &thread_cache_size);
389
357
sys_var_long_ptr        sys_thread_pool_size(&vars, "thread_pool_size",
390
358
                                              &thread_pool_size);
391
 
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
 
359
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
392
360
                                         &SV::tx_isolation,
393
361
                                         &tx_isolation_typelib,
394
362
                                         fix_tx_isolation,
395
363
                                         check_tx_isolation);
396
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
364
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
397
365
                                           &SV::tmp_table_size);
398
366
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
399
367
static sys_var_const_str        sys_version(&vars, "version", server_version);
400
368
static sys_var_const_str        sys_version_comment(&vars, "version_comment",
401
 
                                            DRIZZLE_COMPILATION_COMMENT);
 
369
                                            COMPILATION_COMMENT);
402
370
static sys_var_const_str        sys_version_compile_machine(&vars, "version_compile_machine",
403
371
                                                    MACHINE_TYPE);
404
372
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
405
373
                                               SYSTEM_TYPE);
406
 
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
 
374
static sys_var_session_ulong    sys_net_wait_timeout(&vars, "wait_timeout",
407
375
                                             &SV::net_wait_timeout);
408
376
 
409
377
/* Condition pushdown to storage engine */
410
 
static sys_var_thd_bool
 
378
static sys_var_session_bool
411
379
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
412
380
                              &SV::engine_condition_pushdown);
413
381
 
414
382
/* Time/date/datetime formats */
415
383
 
416
 
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
 
384
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
417
385
                                             &SV::time_format,
418
386
                                             DRIZZLE_TIMESTAMP_TIME);
419
 
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
 
387
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
420
388
                                             &SV::date_format,
421
389
                                             DRIZZLE_TIMESTAMP_DATE);
422
 
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
 
390
static sys_var_session_date_time_format sys_datetime_format(&vars, "datetime_format",
423
391
                                                 &SV::datetime_format,
424
392
                                                 DRIZZLE_TIMESTAMP_DATETIME);
425
393
 
426
 
/* Variables that are bits in THD */
 
394
/* Variables that are bits in Session */
427
395
 
428
 
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
 
396
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
429
397
                               set_option_autocommit,
430
398
                               OPTION_NOT_AUTOCOMMIT,
431
399
                               1);
432
 
static sys_var_thd_bit  sys_big_tables(&vars, "big_tables", 0,
433
 
                                       set_option_bit,
434
 
                                       OPTION_BIG_TABLES);
435
 
#ifndef TO_BE_DELETED   /* Alias for big_tables */
436
 
static sys_var_thd_bit  sys_sql_big_tables(&vars, "sql_big_tables", 0,
437
 
                                           set_option_bit,
438
 
                                           OPTION_BIG_TABLES);
439
 
#endif
440
 
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
 
400
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
441
401
                                        set_option_bit,
442
402
                                        OPTION_BIG_SELECTS);
443
 
static sys_var_thd_bit  sys_log_off(&vars, "sql_log_off",
444
 
                                    check_log_update,
445
 
                                    set_option_bit,
446
 
                                    OPTION_LOG_OFF);
447
 
static sys_var_thd_bit  sys_log_update(&vars, "sql_log_update",
448
 
                                       check_log_update,
449
 
                                       set_log_update,
450
 
                                       OPTION_BIN_LOG);
451
 
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
 
403
static sys_var_session_bit      sys_log_binlog(&vars, "sql_log_bin",
452
404
                                       check_log_update,
453
405
                                       set_option_bit,
454
406
                                       OPTION_BIN_LOG);
455
 
static sys_var_thd_bit  sys_sql_warnings(&vars, "sql_warnings", 0,
 
407
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
456
408
                                         set_option_bit,
457
409
                                         OPTION_WARNINGS);
458
 
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
 
410
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
459
411
                                         set_option_bit,
460
412
                                         OPTION_SQL_NOTES);
461
 
static sys_var_thd_bit  sys_auto_is_null(&vars, "sql_auto_is_null", 0,
462
 
                                         set_option_bit,
463
 
                                         OPTION_AUTO_IS_NULL, 0,
464
 
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
465
 
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
 
413
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
466
414
                                         set_option_bit,
467
415
                                         OPTION_SAFE_UPDATES);
468
 
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
 
416
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
469
417
                                           set_option_bit,
470
418
                                           OPTION_BUFFER_RESULT);
471
 
static sys_var_thd_bit  sys_quote_show_create(&vars, "sql_quote_show_create", 0,
 
419
static sys_var_session_bit      sys_quote_show_create(&vars, "sql_quote_show_create", 0,
472
420
                                              set_option_bit,
473
421
                                              OPTION_QUOTE_SHOW_CREATE);
474
 
static sys_var_thd_bit  sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
422
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
475
423
                                               set_option_bit,
476
424
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
477
425
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
478
 
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
 
426
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
479
427
                                          set_option_bit,
480
428
                                          OPTION_RELAXED_UNIQUE_CHECKS,
481
429
                                          1,
482
430
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
483
431
/* Local state variables */
484
432
 
485
 
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
 
433
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
486
434
                                                 &SV::select_limit);
487
435
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
488
436
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
496
444
static sys_var_last_insert_id
497
445
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
498
446
 
499
 
static sys_var_thd_lc_time_names
 
447
static sys_var_session_lc_time_names
500
448
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
501
449
 
502
450
/*
533
481
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
534
482
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
535
483
 
536
 
static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
 
484
static sys_var_session_ulong        sys_default_week_format(&vars, "default_week_format",
537
485
                                                        &SV::default_week_format);
538
486
 
539
 
sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
 
487
sys_var_session_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
540
488
                                                         &SV::group_concat_max_len);
541
489
 
542
 
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
 
490
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
543
491
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
544
492
 
545
493
/* Global read-only variable containing hostname */
546
494
static sys_var_const_str        sys_hostname(&vars, "hostname", glob_hostname);
547
495
 
548
496
static sys_var_const_str_ptr    sys_repl_report_host(&vars, "report_host", &report_host);
549
 
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
550
 
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
551
 
 
552
 
static uchar *slave_get_report_port(THD *thd)
553
 
{
554
 
  thd->sys_var_tmp.long_value= report_port;
555
 
  return (uchar*) &thd->sys_var_tmp.long_value;
556
 
}
557
 
 
558
 
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
559
 
 
560
 
sys_var_thd_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
 
497
 
 
498
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
561
499
                                           &SV::keep_files_on_create);
562
500
/* Read only variables */
563
501
 
564
502
static sys_var_have_variable sys_have_compress(&vars, "have_compress", &have_compress);
565
503
static sys_var_have_variable sys_have_symlink(&vars, "have_symlink", &have_symlink);
566
 
/* Global variables which enable|disable logging */
567
 
static sys_var_log_state sys_var_general_log(&vars, "general_log", &opt_log,
568
 
                                      QUERY_LOG_GENERAL);
569
 
/* Synonym of "general_log" for consistency with SHOW VARIABLES output */
570
 
static sys_var_log_state sys_var_log(&vars, "log", &opt_log, QUERY_LOG_GENERAL);
571
 
static sys_var_log_state sys_var_slow_query_log(&vars, "slow_query_log", &opt_slow_log,
572
 
                                         QUERY_LOG_SLOW);
573
 
/* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
574
 
static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
575
 
                                          &opt_slow_log, QUERY_LOG_SLOW);
576
 
sys_var_str sys_var_general_log_path(&vars, "general_log_file", sys_check_log_path,
577
 
                                     sys_update_general_log_path,
578
 
                                     sys_default_general_log_path,
579
 
                                     opt_logname);
580
 
sys_var_str sys_var_slow_log_path(&vars, "slow_query_log_file", sys_check_log_path,
581
 
                                  sys_update_slow_log_path, 
582
 
                                  sys_default_slow_log_path,
583
 
                                  opt_slow_logname);
584
 
static sys_var_log_output sys_var_log_output_state(&vars, "log_output", &log_output_options,
585
 
                                            &log_output_typelib, 0);
586
 
 
587
 
 
588
504
/*
589
505
  Additional variables (not derived from sys_var class, not accessible as
590
506
  @@varname in SELECT or SET). Sorted in alphabetical order to facilitate
606
522
  {"open_files_limit",        (char*) &open_files_limit,            SHOW_LONG},
607
523
  {"pid_file",                (char*) pidfile_name,                 SHOW_CHAR},
608
524
  {"plugin_dir",              (char*) opt_plugin_dir,               SHOW_CHAR},
609
 
  {"port",                    (char*) &mysqld_port,                 SHOW_INT},
 
525
  {"port",                    (char*) &drizzled_port,               SHOW_INT},
610
526
  {"protocol_version",        (char*) &protocol_version,            SHOW_INT},
611
527
  {"thread_stack",            (char*) &my_thread_stack_size,        SHOW_LONG},
612
528
};
613
529
 
614
530
 
615
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
531
bool sys_var::check(Session *, set_var *var)
616
532
{
617
533
  var->save_result.uint64_t_value= var->value->val_int();
618
534
  return 0;
619
535
}
620
536
 
621
 
bool sys_var_str::check(THD *thd, set_var *var)
 
537
bool sys_var_str::check(Session *session, set_var *var)
622
538
{
623
539
  int res;
624
540
  if (!check_func)
625
541
    return 0;
626
542
 
627
 
  if ((res=(*check_func)(thd, var)) < 0)
 
543
  if ((res=(*check_func)(session, var)) < 0)
628
544
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
629
545
             name, var->value->str_value.ptr());
630
546
  return res;
647
563
                        set_var *var)
648
564
{
649
565
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
650
 
  uint new_length= (var ? var->value->str_value.length() : 0);
 
566
  uint32_t new_length= (var ? var->value->str_value.length() : 0);
651
567
  if (!old_value)
652
568
    old_value= (char*) "";
653
569
  if (!(res= my_strndup(old_value, new_length, MYF(0))))
661
577
  var_str->value= res;
662
578
  var_str->value_length= new_length;
663
579
  rw_unlock(var_mutex);
664
 
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
 
580
  free(old_value);
665
581
  return 0;
666
582
}
667
583
 
668
584
 
669
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
 
585
static bool sys_update_init_connect(Session *, set_var *var)
670
586
{
671
587
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
672
588
}
673
589
 
674
590
 
675
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
676
 
                                     enum_var_type type __attribute__((unused)))
 
591
static void sys_default_init_connect(Session *, enum_var_type)
677
592
{
678
593
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
679
594
}
680
595
 
681
596
 
682
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
683
 
                                  set_var *var)
 
597
static bool sys_update_init_slave(Session *, set_var *var)
684
598
{
685
599
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
686
600
}
687
601
 
688
602
 
689
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
690
 
                                   enum_var_type type __attribute__((unused)))
 
603
static void sys_default_init_slave(Session *, enum_var_type)
691
604
{
692
605
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
693
606
}
698
611
  used lock type.
699
612
*/
700
613
 
701
 
static void fix_low_priority_updates(THD *thd, enum_var_type type)
 
614
static void fix_low_priority_updates(Session *session, enum_var_type type)
702
615
{
703
616
  if (type == OPT_GLOBAL)
704
617
    thr_upgraded_concurrent_insert_lock= 
705
618
      (global_system_variables.low_priority_updates ?
706
619
       TL_WRITE_LOW_PRIORITY : TL_WRITE);
707
620
  else
708
 
    thd->update_lock_default= (thd->variables.low_priority_updates ?
 
621
    session->update_lock_default= (session->variables.low_priority_updates ?
709
622
                               TL_WRITE_LOW_PRIORITY : TL_WRITE);
710
623
}
711
624
 
712
625
 
713
626
static void
714
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
715
 
                              enum_var_type type __attribute__((unused)))
 
627
fix_myisam_max_sort_file_size(Session *, enum_var_type)
716
628
{
717
629
  myisam_max_temp_length=
718
630
    (my_off_t) global_system_variables.myisam_max_sort_file_size;
722
634
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
723
635
*/
724
636
 
725
 
static void fix_max_join_size(THD *thd, enum_var_type type)
 
637
static void fix_max_join_size(Session *session, enum_var_type type)
726
638
{
727
639
  if (type != OPT_GLOBAL)
728
640
  {
729
 
    if (thd->variables.max_join_size == HA_POS_ERROR)
730
 
      thd->options|= OPTION_BIG_SELECTS;
 
641
    if (session->variables.max_join_size == HA_POS_ERROR)
 
642
      session->options|= OPTION_BIG_SELECTS;
731
643
    else
732
 
      thd->options&= ~OPTION_BIG_SELECTS;
 
644
      session->options&= ~OPTION_BIG_SELECTS;
733
645
  }
734
646
}
735
647
 
738
650
  Can't change the 'next' tx_isolation while we are already in
739
651
  a transaction
740
652
*/
741
 
static int check_tx_isolation(THD *thd, set_var *var)
 
653
static int check_tx_isolation(Session *session, set_var *var)
742
654
{
743
 
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
 
655
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
744
656
  {
745
657
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
746
658
    return 1;
752
664
  If one doesn't use the SESSION modifier, the isolation level
753
665
  is only active for the next command.
754
666
*/
755
 
static void fix_tx_isolation(THD *thd, enum_var_type type)
 
667
static void fix_tx_isolation(Session *session, enum_var_type type)
756
668
{
757
669
  if (type == OPT_SESSION)
758
 
    thd->session_tx_isolation= ((enum_tx_isolation)
759
 
                                thd->variables.tx_isolation);
 
670
    session->session_tx_isolation= ((enum_tx_isolation)
 
671
                                    session->variables.tx_isolation);
760
672
}
761
673
 
762
 
static void fix_completion_type(THD *thd __attribute__((unused)),
763
 
                                enum_var_type type __attribute__((unused))) {}
 
674
static void fix_completion_type(Session *, enum_var_type) {}
764
675
 
765
 
static int check_completion_type(THD *thd __attribute__((unused)),
766
 
                                 set_var *var)
 
676
static int check_completion_type(Session *, set_var *var)
767
677
{
768
678
  int64_t val= var->value->val_int();
769
679
  if (val < 0 || val > 2)
780
690
  If we are changing the thread variable, we have to copy it to NET too
781
691
*/
782
692
 
783
 
#ifdef HAVE_REPLICATION
784
 
static void fix_net_read_timeout(THD *thd, enum_var_type type)
785
 
{
786
 
  if (type != OPT_GLOBAL)
787
 
    my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
788
 
}
789
 
 
790
 
 
791
 
static void fix_net_write_timeout(THD *thd, enum_var_type type)
792
 
{
793
 
  if (type != OPT_GLOBAL)
794
 
    my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
795
 
}
796
 
 
797
 
static void fix_net_retry_count(THD *thd, enum_var_type type)
798
 
{
799
 
  if (type != OPT_GLOBAL)
800
 
    thd->net.retry_count=thd->variables.net_retry_count;
801
 
}
802
 
#else /* HAVE_REPLICATION */
803
 
static void fix_net_read_timeout(THD *thd __attribute__((unused)),
804
 
                                 enum_var_type type __attribute__((unused)))
805
 
{}
806
 
static void fix_net_write_timeout(THD *thd __attribute__((unused)),
807
 
                                  enum_var_type type __attribute__((unused)))
808
 
{}
809
 
static void fix_net_retry_count(THD *thd __attribute__((unused)),
810
 
                                enum_var_type type __attribute__((unused)))
811
 
{}
812
 
#endif /* HAVE_REPLICATION */
813
 
 
814
 
 
815
 
extern void fix_delay_key_write(THD *thd __attribute__((unused)),
816
 
                                enum_var_type type __attribute__((unused)))
 
693
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
694
{
 
695
  if (type != OPT_GLOBAL)
 
696
    my_net_set_read_timeout(&session->net, session->variables.net_read_timeout);
 
697
}
 
698
 
 
699
 
 
700
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
701
{
 
702
  if (type != OPT_GLOBAL)
 
703
    my_net_set_write_timeout(&session->net, session->variables.net_write_timeout);
 
704
}
 
705
 
 
706
static void fix_net_retry_count(Session *session, enum_var_type type)
 
707
{
 
708
  if (type != OPT_GLOBAL)
 
709
    session->net.retry_count=session->variables.net_retry_count;
 
710
}
 
711
 
 
712
 
 
713
extern void fix_delay_key_write(Session *, enum_var_type)
817
714
{
818
715
  switch ((enum_delay_key_write) delay_key_write_options) {
819
716
  case DELAY_KEY_WRITE_NONE:
829
726
  }
830
727
}
831
728
 
832
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
833
 
                         set_var *var)
 
729
bool sys_var_set::update(Session *, set_var *var)
834
730
{
835
 
  *value= var->save_result.ulong_value;
 
731
  *value= var->save_result.uint32_t_value;
836
732
  return 0;
837
733
}
838
734
 
839
 
uchar *sys_var_set::value_ptr(THD *thd,
840
 
                              enum_var_type type __attribute__((unused)),
841
 
                              LEX_STRING *base __attribute__((unused)))
 
735
unsigned char *sys_var_set::value_ptr(Session *session,
 
736
                              enum_var_type,
 
737
                              LEX_STRING *)
842
738
{
843
739
  char buff[256];
844
740
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
846
742
  ulong val= *value;
847
743
 
848
744
  tmp.length(0);
849
 
  for (uint i= 0; val; val>>= 1, i++)
 
745
  for (uint32_t i= 0; val; val>>= 1, i++)
850
746
  {
851
747
    if (val & 1)
852
748
    {
858
754
 
859
755
  if ((length= tmp.length()))
860
756
    length--;
861
 
  return (uchar*) thd->strmake(tmp.ptr(), length);
 
757
  return (unsigned char*) session->strmake(tmp.ptr(), length);
862
758
}
863
759
 
864
 
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
865
 
                                         enum_var_type type __attribute__((unused)))
 
760
void sys_var_set_slave_mode::set_default(Session *, enum_var_type)
866
761
{
867
762
  slave_exec_mode_options= 0;
868
763
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
869
764
}
870
765
 
871
 
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
 
766
bool sys_var_set_slave_mode::check(Session *session, set_var *var)
872
767
{
873
 
  bool rc=  sys_var_set::check(thd, var);
 
768
  bool rc=  sys_var_set::check(session, var);
874
769
  if (!rc &&
875
 
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
876
 
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
 
770
      bit_is_set(var->save_result.uint32_t_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
 
771
      bit_is_set(var->save_result.uint32_t_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
877
772
  {
878
773
    rc= true;
879
774
    my_error(ER_SLAVE_AMBIGOUS_EXEC_MODE, MYF(0), "");
881
776
  return rc;
882
777
}
883
778
 
884
 
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
 
779
bool sys_var_set_slave_mode::update(Session *session, set_var *var)
885
780
{
886
781
  bool rc;
887
782
  pthread_mutex_lock(&LOCK_global_system_variables);
888
 
  rc= sys_var_set::update(thd, var);
 
783
  rc= sys_var_set::update(session, var);
889
784
  pthread_mutex_unlock(&LOCK_global_system_variables);
890
785
  return rc;
891
786
}
892
787
 
893
 
void fix_slave_exec_mode(enum_var_type type __attribute__((unused)))
 
788
void fix_slave_exec_mode(enum_var_type)
894
789
{
895
790
  if (bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT) == 1 &&
896
791
      bit_is_set(slave_exec_mode_options, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
903
798
    bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
904
799
}
905
800
 
906
 
bool sys_var_thd_binlog_format::is_readonly() const
 
801
bool sys_var_session_binlog_format::is_readonly() const
907
802
{
908
803
  /*
909
804
    Under certain circumstances, the variable is read-only (unchangeable):
910
805
  */
911
 
  THD *thd= current_thd;
 
806
  Session *session= current_session;
912
807
  /*
913
808
    If RBR and open temporary tables, their CREATE TABLE may not be in the
914
809
    binlog, so we can't toggle to SBR in this connection.
920
815
    If we don't have row-based replication compiled in, the variable
921
816
    is always read-only.
922
817
  */
923
 
  if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
924
 
      thd->temporary_tables)
 
818
  if ((session->variables.binlog_format == BINLOG_FORMAT_ROW) &&
 
819
      session->temporary_tables)
925
820
  {
926
821
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
927
822
    return 1;
928
823
  }
929
 
  /*
930
 
    if in a stored function/trigger, it's too late to change mode
931
 
  */
932
 
  if (thd->in_sub_stmt)
933
 
  {
934
 
    my_error(ER_STORED_FUNCTION_PREVENTS_SWITCH_BINLOG_FORMAT, MYF(0));
935
 
    return 1;    
936
 
  }
937
 
  return sys_var_thd_enum::is_readonly();
 
824
  
 
825
  return sys_var_session_enum::is_readonly();
938
826
}
939
827
 
940
828
 
941
 
void fix_binlog_format_after_update(THD *thd,
942
 
                                    enum_var_type type __attribute__((unused)))
 
829
void fix_binlog_format_after_update(Session *session, enum_var_type)
943
830
{
944
 
  thd->reset_current_stmt_binlog_row_based();
 
831
  session->reset_current_stmt_binlog_row_based();
945
832
}
946
833
 
947
834
 
948
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
949
 
                                enum_var_type type __attribute__((unused)))
 
835
static void fix_max_binlog_size(Session *, enum_var_type)
950
836
{
951
837
  mysql_bin_log.set_max_size(max_binlog_size);
952
 
#ifdef HAVE_REPLICATION
953
838
  if (!max_relay_log_size)
954
839
    active_mi->rli.relay_log.set_max_size(max_binlog_size);
955
 
#endif
956
840
  return;
957
841
}
958
842
 
959
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
960
 
                                   enum_var_type type __attribute__((unused)))
 
843
static void fix_max_relay_log_size(Session *, enum_var_type)
961
844
{
962
 
#ifdef HAVE_REPLICATION
963
845
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
964
846
                                        max_relay_log_size: max_binlog_size);
965
 
#endif
966
847
  return;
967
848
}
968
849
 
969
 
static void fix_max_connections(THD *thd __attribute__((unused)),
970
 
                                enum_var_type type __attribute__((unused)))
 
850
static void fix_max_connections(Session *, enum_var_type)
971
851
{
972
852
  resize_thr_alarm(max_connections +  10);
973
853
}
974
854
 
975
855
 
976
 
static void fix_thd_mem_root(THD *thd, enum_var_type type)
977
 
{
978
 
  if (type != OPT_GLOBAL)
979
 
    reset_root_defaults(thd->mem_root,
980
 
                        thd->variables.query_alloc_block_size,
981
 
                        thd->variables.query_prealloc_size);
982
 
}
983
 
 
984
 
 
985
 
static void fix_trans_mem_root(THD *thd, enum_var_type type)
986
 
{
987
 
  if (type != OPT_GLOBAL)
988
 
    reset_root_defaults(&thd->transaction.mem_root,
989
 
                        thd->variables.trans_alloc_block_size,
990
 
                        thd->variables.trans_prealloc_size);
991
 
}
992
 
 
993
 
 
994
 
static void fix_server_id(THD *thd __attribute__((unused)),
995
 
                          enum_var_type type __attribute__((unused)))
 
856
static void fix_session_mem_root(Session *session, enum_var_type type)
 
857
{
 
858
  if (type != OPT_GLOBAL)
 
859
    reset_root_defaults(session->mem_root,
 
860
                        session->variables.query_alloc_block_size,
 
861
                        session->variables.query_prealloc_size);
 
862
}
 
863
 
 
864
 
 
865
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
866
{
 
867
  if (type != OPT_GLOBAL)
 
868
    reset_root_defaults(&session->transaction.mem_root,
 
869
                        session->variables.trans_alloc_block_size,
 
870
                        session->variables.trans_prealloc_size);
 
871
}
 
872
 
 
873
 
 
874
static void fix_server_id(Session *session, enum_var_type)
996
875
{
997
876
  server_id_supplied = 1;
998
 
  thd->server_id= server_id;
 
877
  session->server_id= server_id;
999
878
}
1000
879
 
1001
880
 
1002
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
881
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
1003
882
                          const char *name, int64_t val)
1004
883
{
1005
884
  if (fixed)
1011
890
    else
1012
891
      llstr(val, buf);
1013
892
 
1014
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
893
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1015
894
                        ER_TRUNCATED_WRONG_VALUE,
1016
895
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
1017
896
  }
1018
897
  return false;
1019
898
}
1020
899
 
1021
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
900
static uint64_t fix_unsigned(Session *session, uint64_t num,
1022
901
                              const struct my_option *option_limits)
1023
902
{
1024
903
  bool fixed= false;
1025
904
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
1026
905
 
1027
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
 
906
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
1028
907
  return out;
1029
908
}
1030
909
 
1031
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
 
910
static bool get_unsigned(Session *, set_var *var)
1032
911
{
1033
912
  if (var->value->unsigned_flag)
1034
913
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
1049
928
{}
1050
929
 
1051
930
 
1052
 
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
 
931
bool sys_var_long_ptr_global::check(Session *session, set_var *var)
1053
932
{
1054
 
  return get_unsigned(thd, var);
 
933
  return get_unsigned(session, var);
1055
934
}
1056
935
 
1057
 
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
 
936
bool sys_var_long_ptr_global::update(Session *session, set_var *var)
1058
937
{
1059
938
  uint64_t tmp= var->save_result.uint64_t_value;
1060
939
  pthread_mutex_lock(guard);
1061
940
  if (option_limits)
1062
 
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
 
941
    *value= (ulong) fix_unsigned(session, tmp, option_limits);
1063
942
  else
1064
943
  {
1065
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1066
 
    /* Avoid overflows on 32 bit systems */
1067
 
    if (tmp > ULONG_MAX)
 
944
    if (tmp > UINT32_MAX)
1068
945
    {
1069
 
      tmp= ULONG_MAX;
1070
 
      throw_bounds_warning(thd, true, true, name,
 
946
      tmp= UINT32_MAX;
 
947
      throw_bounds_warning(session, true, true, name,
1071
948
                           (int64_t) var->save_result.uint64_t_value);
1072
949
    }
1073
 
#endif
1074
950
    *value= (ulong) tmp;
1075
951
  }
1076
952
 
1079
955
}
1080
956
 
1081
957
 
1082
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
958
void sys_var_long_ptr_global::set_default(Session *, enum_var_type)
1083
959
{
1084
960
  bool not_used;
1085
961
  pthread_mutex_lock(guard);
1088
964
  pthread_mutex_unlock(guard);
1089
965
}
1090
966
 
1091
 
 
1092
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
967
bool sys_var_uint32_t_ptr::update(Session *session, set_var *var)
 
968
{
 
969
  uint32_t tmp= var->save_result.uint32_t_value;
 
970
  pthread_mutex_lock(&LOCK_global_system_variables);
 
971
  if (option_limits)
 
972
    *value= (uint32_t) fix_unsigned(session, tmp, option_limits);
 
973
  else
 
974
    *value= (uint32_t) tmp;
 
975
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
976
  return 0;
 
977
}
 
978
 
 
979
 
 
980
void sys_var_uint32_t_ptr::set_default(Session *, enum_var_type)
 
981
{
 
982
  bool not_used;
 
983
  pthread_mutex_lock(&LOCK_global_system_variables);
 
984
  *value= getopt_ull_limit_value((uint32_t) option_limits->def_value,
 
985
                                 option_limits, &not_used);
 
986
  pthread_mutex_unlock(&LOCK_global_system_variables);
 
987
}
 
988
 
 
989
 
 
990
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1093
991
{
1094
992
  uint64_t tmp= var->save_result.uint64_t_value;
1095
993
  pthread_mutex_lock(&LOCK_global_system_variables);
1096
994
  if (option_limits)
1097
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
995
    *value= (uint64_t) fix_unsigned(session, tmp, option_limits);
1098
996
  else
1099
997
    *value= (uint64_t) tmp;
1100
998
  pthread_mutex_unlock(&LOCK_global_system_variables);
1102
1000
}
1103
1001
 
1104
1002
 
1105
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
1106
 
                                        enum_var_type type __attribute__((unused)))
 
1003
void sys_var_uint64_t_ptr::set_default(Session *, enum_var_type)
1107
1004
{
1108
1005
  bool not_used;
1109
1006
  pthread_mutex_lock(&LOCK_global_system_variables);
1113
1010
}
1114
1011
 
1115
1012
 
1116
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
 
1013
bool sys_var_bool_ptr::update(Session *, set_var *var)
1117
1014
{
1118
 
  *value= (bool) var->save_result.ulong_value;
 
1015
  *value= (bool) var->save_result.uint32_t_value;
1119
1016
  return 0;
1120
1017
}
1121
1018
 
1122
1019
 
1123
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1020
void sys_var_bool_ptr::set_default(Session *, enum_var_type)
1124
1021
{
1125
1022
  *value= (bool) option_limits->def_value;
1126
1023
}
1127
1024
 
1128
1025
 
1129
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
1026
bool sys_var_enum::update(Session *, set_var *var)
1130
1027
{
1131
 
  *value= (uint) var->save_result.ulong_value;
 
1028
  *value= (uint) var->save_result.uint32_t_value;
1132
1029
  return 0;
1133
1030
}
1134
1031
 
1135
1032
 
1136
 
uchar *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
1137
 
                               enum_var_type type __attribute__((unused)),
1138
 
                               LEX_STRING *base __attribute__((unused)))
1139
 
{
1140
 
  return (uchar*) enum_names->type_names[*value];
1141
 
}
1142
 
 
1143
 
 
1144
 
uchar *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
1145
 
                                     enum_var_type type __attribute__((unused)),
1146
 
                                     LEX_STRING *base __attribute__((unused)))
1147
 
{
1148
 
  return (uchar*) enum_names->type_names[global_system_variables.*offset];
1149
 
}
1150
 
 
1151
 
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
1152
 
{
1153
 
  return (get_unsigned(thd, var) ||
1154
 
          (check_func && (*check_func)(thd, var)));
1155
 
}
1156
 
 
1157
 
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
 
1033
unsigned char *sys_var_enum::value_ptr(Session *, enum_var_type, LEX_STRING *)
 
1034
{
 
1035
  return (unsigned char*) enum_names->type_names[*value];
 
1036
}
 
1037
 
 
1038
 
 
1039
unsigned char *sys_var_enum_const::value_ptr(Session *, enum_var_type,
 
1040
                                             LEX_STRING *)
 
1041
{
 
1042
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
 
1043
}
 
1044
 
 
1045
bool sys_var_session_ulong::check(Session *session, set_var *var)
 
1046
{
 
1047
  return (get_unsigned(session, var) ||
 
1048
          (check_func && (*check_func)(session, var)));
 
1049
}
 
1050
 
 
1051
bool sys_var_session_ulong::update(Session *session, set_var *var)
1158
1052
{
1159
1053
  uint64_t tmp= var->save_result.uint64_t_value;
1160
1054
  
1161
1055
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1162
1056
  if ((ulong) tmp > max_system_variables.*offset)
1163
1057
  {
1164
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
1058
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
1165
1059
    tmp= max_system_variables.*offset;
1166
1060
  }
1167
1061
  
1168
1062
  if (option_limits)
1169
 
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1170
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1171
 
  else if (tmp > ULONG_MAX)
 
1063
    tmp= (ulong) fix_unsigned(session, tmp, option_limits);
 
1064
  else if (tmp > UINT32_MAX)
1172
1065
  {
1173
 
    tmp= ULONG_MAX;
1174
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1066
    tmp= UINT32_MAX;
 
1067
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
1175
1068
  }
1176
 
#endif
1177
1069
  
1178
1070
  if (var->type == OPT_GLOBAL)
1179
1071
     global_system_variables.*offset= (ulong) tmp;
1180
1072
   else
1181
 
     thd->variables.*offset= (ulong) tmp;
 
1073
     session->variables.*offset= (ulong) tmp;
1182
1074
 
1183
1075
   return 0;
1184
1076
 }
1185
1077
 
1186
1078
 
1187
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
1079
 void sys_var_session_ulong::set_default(Session *session, enum_var_type type)
1188
1080
 {
1189
1081
   if (type == OPT_GLOBAL)
1190
1082
   {
1195
1087
                                      option_limits, &not_used);
1196
1088
   }
1197
1089
   else
1198
 
     thd->variables.*offset= global_system_variables.*offset;
 
1090
     session->variables.*offset= global_system_variables.*offset;
1199
1091
 }
1200
1092
 
1201
1093
 
1202
 
uchar *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
1203
 
                                    LEX_STRING *base __attribute__((unused)))
 
1094
unsigned char *sys_var_session_ulong::value_ptr(Session *session,
 
1095
                                                enum_var_type type,
 
1096
                                                LEX_STRING *)
1204
1097
{
1205
1098
  if (type == OPT_GLOBAL)
1206
 
    return (uchar*) &(global_system_variables.*offset);
1207
 
  return (uchar*) &(thd->variables.*offset);
 
1099
    return (unsigned char*) &(global_system_variables.*offset);
 
1100
  return (unsigned char*) &(session->variables.*offset);
1208
1101
}
1209
1102
 
1210
1103
 
1211
 
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
 
1104
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1212
1105
{
1213
1106
  uint64_t tmp= var->save_result.uint64_t_value;
1214
1107
 
1217
1110
    tmp= max_system_variables.*offset;
1218
1111
 
1219
1112
  if (option_limits)
1220
 
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
 
1113
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1221
1114
  if (var->type == OPT_GLOBAL)
1222
1115
  {
1223
1116
    /* Lock is needed to make things safe on 32 bit systems */
1226
1119
    pthread_mutex_unlock(&LOCK_global_system_variables);
1227
1120
  }
1228
1121
  else
1229
 
    thd->variables.*offset= (ha_rows) tmp;
 
1122
    session->variables.*offset= (ha_rows) tmp;
1230
1123
  return 0;
1231
1124
}
1232
1125
 
1233
1126
 
1234
 
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
 
1127
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1235
1128
{
1236
1129
  if (type == OPT_GLOBAL)
1237
1130
  {
1244
1137
    pthread_mutex_unlock(&LOCK_global_system_variables);
1245
1138
  }
1246
1139
  else
1247
 
    thd->variables.*offset= global_system_variables.*offset;
 
1140
    session->variables.*offset= global_system_variables.*offset;
1248
1141
}
1249
1142
 
1250
1143
 
1251
 
uchar *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
1252
 
                                      LEX_STRING *base __attribute__((unused)))
 
1144
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session,
 
1145
                                                  enum_var_type type,
 
1146
                                                  LEX_STRING *)
1253
1147
{
1254
1148
  if (type == OPT_GLOBAL)
1255
 
    return (uchar*) &(global_system_variables.*offset);
1256
 
  return (uchar*) &(thd->variables.*offset);
 
1149
    return (unsigned char*) &(global_system_variables.*offset);
 
1150
  return (unsigned char*) &(session->variables.*offset);
1257
1151
}
1258
1152
 
1259
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
1153
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1260
1154
{
1261
 
  return get_unsigned(thd, var);
 
1155
  return (get_unsigned(session, var) ||
 
1156
          (check_func && (*check_func)(session, var)));
1262
1157
}
1263
1158
 
1264
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
1159
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1265
1160
{
1266
1161
  uint64_t tmp= var->save_result.uint64_t_value;
1267
1162
 
1269
1164
    tmp= max_system_variables.*offset;
1270
1165
 
1271
1166
  if (option_limits)
1272
 
    tmp= fix_unsigned(thd, tmp, option_limits);
 
1167
    tmp= fix_unsigned(session, tmp, option_limits);
1273
1168
  if (var->type == OPT_GLOBAL)
1274
1169
  {
1275
1170
    /* Lock is needed to make things safe on 32 bit systems */
1278
1173
    pthread_mutex_unlock(&LOCK_global_system_variables);
1279
1174
  }
1280
1175
  else
1281
 
    thd->variables.*offset= (uint64_t) tmp;
 
1176
    session->variables.*offset= (uint64_t) tmp;
1282
1177
  return 0;
1283
1178
}
1284
1179
 
1285
1180
 
1286
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
1181
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1287
1182
{
1288
1183
  if (type == OPT_GLOBAL)
1289
1184
  {
1295
1190
    pthread_mutex_unlock(&LOCK_global_system_variables);
1296
1191
  }
1297
1192
  else
1298
 
    thd->variables.*offset= global_system_variables.*offset;
 
1193
    session->variables.*offset= global_system_variables.*offset;
1299
1194
}
1300
1195
 
1301
1196
 
1302
 
uchar *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
1303
 
                                        LEX_STRING *base __attribute__((unused)))
 
1197
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session,
 
1198
                                                   enum_var_type type,
 
1199
                                                   LEX_STRING *)
1304
1200
{
1305
1201
  if (type == OPT_GLOBAL)
1306
 
    return (uchar*) &(global_system_variables.*offset);
1307
 
  return (uchar*) &(thd->variables.*offset);
 
1202
    return (unsigned char*) &(global_system_variables.*offset);
 
1203
  return (unsigned char*) &(session->variables.*offset);
1308
1204
}
1309
1205
 
1310
1206
 
1311
 
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
 
1207
bool sys_var_session_bool::update(Session *session,  set_var *var)
1312
1208
{
1313
1209
  if (var->type == OPT_GLOBAL)
1314
 
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
 
1210
    global_system_variables.*offset= (bool) var->save_result.uint32_t_value;
1315
1211
  else
1316
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1212
    session->variables.*offset= (bool) var->save_result.uint32_t_value;
1317
1213
  return 0;
1318
1214
}
1319
1215
 
1320
1216
 
1321
 
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
 
1217
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1322
1218
{
1323
1219
  if (type == OPT_GLOBAL)
1324
1220
    global_system_variables.*offset= (bool) option_limits->def_value;
1325
1221
  else
1326
 
    thd->variables.*offset= global_system_variables.*offset;
 
1222
    session->variables.*offset= global_system_variables.*offset;
1327
1223
}
1328
1224
 
1329
1225
 
1330
 
uchar *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
1331
 
                                   LEX_STRING *base __attribute__((unused)))
 
1226
unsigned char *sys_var_session_bool::value_ptr(Session *session,
 
1227
                                               enum_var_type type,
 
1228
                                               LEX_STRING *)
1332
1229
{
1333
1230
  if (type == OPT_GLOBAL)
1334
 
    return (uchar*) &(global_system_variables.*offset);
1335
 
  return (uchar*) &(thd->variables.*offset);
 
1231
    return (unsigned char*) &(global_system_variables.*offset);
 
1232
  return (unsigned char*) &(session->variables.*offset);
1336
1233
}
1337
1234
 
1338
1235
 
1339
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
 
1236
bool sys_var::check_enum(Session *,
1340
1237
                         set_var *var, const TYPELIB *enum_names)
1341
1238
{
1342
1239
  char buff[STRING_BUFFER_USUAL_SIZE];
1345
1242
 
1346
1243
  if (var->value->result_type() == STRING_RESULT)
1347
1244
  {
1348
 
    if (!(res=var->value->val_str(&str)) ||
1349
 
        ((long) (var->save_result.ulong_value=
1350
 
                 (ulong) find_type(enum_names, res->ptr(),
1351
 
                                   res->length(),1)-1)) < 0)
 
1245
    if (!(res=var->value->val_str(&str)))
1352
1246
    {
1353
1247
      value= res ? res->c_ptr() : "NULL";
1354
1248
      goto err;
1363
1257
      value=buff;                               // Wrong value is here
1364
1258
      goto err;
1365
1259
    }
1366
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
1260
    var->save_result.uint32_t_value= (uint32_t) tmp;    // Save for update
1367
1261
  }
1368
1262
  return 0;
1369
1263
 
1373
1267
}
1374
1268
 
1375
1269
 
1376
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
1377
 
                        set_var *var, TYPELIB *enum_names)
 
1270
bool sys_var::check_set(Session *, set_var *var, TYPELIB *enum_names)
1378
1271
{
1379
1272
  bool not_used;
1380
1273
  char buff[STRING_BUFFER_USUAL_SIZE], *error= 0;
1381
 
  uint error_len= 0;
 
1274
  uint32_t error_len= 0;
1382
1275
  String str(buff, sizeof(buff), system_charset_info), *res;
1383
1276
 
1384
1277
  if (var->value->result_type() == STRING_RESULT)
1385
1278
  {
1386
1279
    if (!(res= var->value->val_str(&str)))
1387
1280
    {
1388
 
      stpcpy(buff, "NULL");
 
1281
      my_stpcpy(buff, "NULL");
1389
1282
      goto err;
1390
1283
    }
1391
1284
 
1396
1289
      goto err;
1397
1290
    }
1398
1291
 
1399
 
    var->save_result.ulong_value= ((ulong)
 
1292
    var->save_result.uint32_t_value= ((uint32_t)
1400
1293
                                   find_set(enum_names, res->c_ptr(),
1401
1294
                                            res->length(),
1402
1295
                                            NULL,
1404
1297
                                            &not_used));
1405
1298
    if (error_len)
1406
1299
    {
1407
 
      strmake(buff, error, min(sizeof(buff) - 1, (ulong)error_len));
 
1300
      strmake(buff, error, cmin(sizeof(buff) - 1, (ulong)error_len));
1408
1301
      goto err;
1409
1302
    }
1410
1303
  }
1424
1317
      For when the enum is made to contain 64 elements, as 1ULL<<64 is
1425
1318
      undefined, we guard with a "count<64" test.
1426
1319
    */
1427
 
    if (unlikely((tmp >= ((1ULL) << enum_names->count)) &&
 
1320
    if (unlikely((tmp >= ((1UL) << enum_names->count)) &&
1428
1321
                 (enum_names->count < 64)))
1429
1322
    {
1430
1323
      llstr(tmp, buff);
1431
1324
      goto err;
1432
1325
    }
1433
 
    var->save_result.ulong_value= (ulong) tmp;  // Save for update
 
1326
    var->save_result.uint32_t_value= (uint32_t) tmp;  // Save for update
1434
1327
  }
1435
1328
  return 0;
1436
1329
 
1448
1341
  If type is not given, return local value if exists, else global.
1449
1342
*/
1450
1343
 
1451
 
Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
 
1344
Item *sys_var::item(Session *session, enum_var_type var_type, LEX_STRING *base)
1452
1345
{
1453
1346
  if (check_type(var_type))
1454
1347
  {
1464
1357
  switch (show_type()) {
1465
1358
  case SHOW_INT:
1466
1359
  {
1467
 
    uint value;
 
1360
    uint32_t value;
1468
1361
    pthread_mutex_lock(&LOCK_global_system_variables);
1469
 
    value= *(uint*) value_ptr(thd, var_type, base);
 
1362
    value= *(uint*) value_ptr(session, var_type, base);
1470
1363
    pthread_mutex_unlock(&LOCK_global_system_variables);
1471
1364
    return new Item_uint((uint64_t) value);
1472
1365
  }
1473
1366
  case SHOW_LONG:
1474
1367
  {
1475
 
    ulong value;
 
1368
    uint32_t value;
1476
1369
    pthread_mutex_lock(&LOCK_global_system_variables);
1477
 
    value= *(ulong*) value_ptr(thd, var_type, base);
 
1370
    value= *(uint32_t*) value_ptr(session, var_type, base);
1478
1371
    pthread_mutex_unlock(&LOCK_global_system_variables);
1479
1372
    return new Item_uint((uint64_t) value);
1480
1373
  }
1482
1375
  {
1483
1376
    int64_t value;
1484
1377
    pthread_mutex_lock(&LOCK_global_system_variables);
1485
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1378
    value= *(int64_t*) value_ptr(session, var_type, base);
1486
1379
    pthread_mutex_unlock(&LOCK_global_system_variables);
1487
1380
    return new Item_int(value);
1488
1381
  }
1490
1383
  {
1491
1384
    double value;
1492
1385
    pthread_mutex_lock(&LOCK_global_system_variables);
1493
 
    value= *(double*) value_ptr(thd, var_type, base);
 
1386
    value= *(double*) value_ptr(session, var_type, base);
1494
1387
    pthread_mutex_unlock(&LOCK_global_system_variables);
1495
1388
    /* 6, as this is for now only used with microseconds */
1496
1389
    return new Item_float(value, 6);
1499
1392
  {
1500
1393
    ha_rows value;
1501
1394
    pthread_mutex_lock(&LOCK_global_system_variables);
1502
 
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1395
    value= *(ha_rows*) value_ptr(session, var_type, base);
1503
1396
    pthread_mutex_unlock(&LOCK_global_system_variables);
1504
1397
    return new Item_int((uint64_t) value);
1505
1398
  }
1507
1400
  {
1508
1401
    int32_t value;
1509
1402
    pthread_mutex_lock(&LOCK_global_system_variables);
1510
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1403
    value= *(bool*) value_ptr(session, var_type, base);
1511
1404
    pthread_mutex_unlock(&LOCK_global_system_variables);
1512
1405
    return new Item_int(value,1);
1513
1406
  }
1515
1408
  {
1516
1409
    Item *tmp;
1517
1410
    pthread_mutex_lock(&LOCK_global_system_variables);
1518
 
    char *str= *(char**) value_ptr(thd, var_type, base);
 
1411
    char *str= *(char**) value_ptr(session, var_type, base);
1519
1412
    if (str)
1520
1413
    {
1521
 
      uint length= strlen(str);
1522
 
      tmp= new Item_string(thd->strmake(str, length), length,
 
1414
      uint32_t length= strlen(str);
 
1415
      tmp= new Item_string(session->strmake(str, length), length,
1523
1416
                           system_charset_info, DERIVATION_SYSCONST);
1524
1417
    }
1525
1418
    else
1534
1427
  {
1535
1428
    Item *tmp;
1536
1429
    pthread_mutex_lock(&LOCK_global_system_variables);
1537
 
    char *str= (char*) value_ptr(thd, var_type, base);
 
1430
    char *str= (char*) value_ptr(session, var_type, base);
1538
1431
    if (str)
1539
1432
      tmp= new Item_string(str, strlen(str),
1540
1433
                           system_charset_info, DERIVATION_SYSCONST);
1553
1446
}
1554
1447
 
1555
1448
 
1556
 
bool sys_var_thd_enum::update(THD *thd, set_var *var)
 
1449
bool sys_var_session_enum::update(Session *session, set_var *var)
1557
1450
{
1558
1451
  if (var->type == OPT_GLOBAL)
1559
 
    global_system_variables.*offset= var->save_result.ulong_value;
 
1452
    global_system_variables.*offset= var->save_result.uint32_t_value;
1560
1453
  else
1561
 
    thd->variables.*offset= var->save_result.ulong_value;
 
1454
    session->variables.*offset= var->save_result.uint32_t_value;
1562
1455
  return 0;
1563
1456
}
1564
1457
 
1565
1458
 
1566
 
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
 
1459
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1567
1460
{
1568
1461
  if (type == OPT_GLOBAL)
1569
1462
    global_system_variables.*offset= (ulong) option_limits->def_value;
1570
1463
  else
1571
 
    thd->variables.*offset= global_system_variables.*offset;
 
1464
    session->variables.*offset= global_system_variables.*offset;
1572
1465
}
1573
1466
 
1574
1467
 
1575
 
uchar *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
1576
 
                                   LEX_STRING *base __attribute__((unused)))
 
1468
unsigned char *sys_var_session_enum::value_ptr(Session *session,
 
1469
                                               enum_var_type type,
 
1470
                                               LEX_STRING *)
1577
1471
{
1578
1472
  ulong tmp= ((type == OPT_GLOBAL) ?
1579
1473
              global_system_variables.*offset :
1580
 
              thd->variables.*offset);
1581
 
  return (uchar*) enum_names->type_names[tmp];
1582
 
}
1583
 
 
1584
 
bool sys_var_thd_bit::check(THD *thd, set_var *var)
1585
 
{
1586
 
  return (check_enum(thd, var, &bool_typelib) ||
1587
 
          (check_func && (*check_func)(thd, var)));
1588
 
}
1589
 
 
1590
 
bool sys_var_thd_bit::update(THD *thd, set_var *var)
1591
 
{
1592
 
  int res= (*update_func)(thd, var);
 
1474
              session->variables.*offset);
 
1475
  return (unsigned char*) enum_names->type_names[tmp];
 
1476
}
 
1477
 
 
1478
bool sys_var_session_bit::check(Session *session, set_var *var)
 
1479
{
 
1480
  return (check_enum(session, var, &bool_typelib) ||
 
1481
          (check_func && (*check_func)(session, var)));
 
1482
}
 
1483
 
 
1484
bool sys_var_session_bit::update(Session *session, set_var *var)
 
1485
{
 
1486
  int res= (*update_func)(session, var);
1593
1487
  return res;
1594
1488
}
1595
1489
 
1596
1490
 
1597
 
uchar *sys_var_thd_bit::value_ptr(THD *thd,
1598
 
                                  enum_var_type type __attribute__((unused)),
1599
 
                                  LEX_STRING *base __attribute__((unused)))
 
1491
unsigned char *sys_var_session_bit::value_ptr(Session *session, enum_var_type,
 
1492
                                              LEX_STRING *)
1600
1493
{
1601
1494
  /*
1602
1495
    If reverse is 0 (default) return 1 if bit is set.
1603
1496
    If reverse is 1, return 0 if bit is set
1604
1497
  */
1605
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1498
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1606
1499
                                   !reverse : reverse);
1607
 
  return (uchar*) &thd->sys_var_tmp.bool_value;
 
1500
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1608
1501
}
1609
1502
 
1610
1503
 
1611
1504
/** Update a date_time format variable based on given value. */
1612
1505
 
1613
 
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
 
1506
void sys_var_session_date_time_format::update2(Session *session, enum_var_type type,
1614
1507
                                           DATE_TIME_FORMAT *new_value)
1615
1508
{
1616
1509
  DATE_TIME_FORMAT *old;
1624
1517
  }
1625
1518
  else
1626
1519
  {
1627
 
    old= (thd->variables.*offset);
1628
 
    (thd->variables.*offset)= new_value;
 
1520
    old= (session->variables.*offset);
 
1521
    (session->variables.*offset)= new_value;
1629
1522
  }
1630
 
  my_free((char*) old, MYF(MY_ALLOW_ZERO_PTR));
 
1523
  free((char*) old);
1631
1524
  return;
1632
1525
}
1633
1526
 
1634
1527
 
1635
 
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
 
1528
bool sys_var_session_date_time_format::update(Session *session, set_var *var)
1636
1529
{
1637
1530
  DATE_TIME_FORMAT *new_value;
1638
1531
  /* We must make a copy of the last value to get it into normal memory */
1639
 
  new_value= date_time_format_copy((THD*) 0,
 
1532
  new_value= date_time_format_copy((Session*) 0,
1640
1533
                                   var->save_result.date_time_format);
1641
1534
  if (!new_value)
1642
1535
    return 1;                                   // Out of memory
1643
 
  update2(thd, var->type, new_value);           // Can't fail
 
1536
  update2(session, var->type, new_value);               // Can't fail
1644
1537
  return 0;
1645
1538
}
1646
1539
 
1647
1540
 
1648
 
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
 
1541
bool sys_var_session_date_time_format::check(Session *session, set_var *var)
1649
1542
{
1650
1543
  char buff[STRING_BUFFER_USUAL_SIZE];
1651
1544
  String str(buff,sizeof(buff), system_charset_info), *res;
1665
1558
    We must copy result to thread space to not get a memory leak if
1666
1559
    update is aborted
1667
1560
  */
1668
 
  var->save_result.date_time_format= date_time_format_copy(thd, format);
1669
 
  my_free((char*) format, MYF(0));
 
1561
  var->save_result.date_time_format= date_time_format_copy(session, format);
 
1562
  free((char*) format);
1670
1563
  return var->save_result.date_time_format == 0;
1671
1564
}
1672
1565
 
1673
1566
 
1674
 
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
 
1567
void sys_var_session_date_time_format::set_default(Session *session, enum_var_type type)
1675
1568
{
1676
1569
  DATE_TIME_FORMAT *res= 0;
1677
1570
 
1684
1577
  else
1685
1578
  {
1686
1579
    /* Make copy with malloc */
1687
 
    res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
 
1580
    res= date_time_format_copy((Session *) 0, global_system_variables.*offset);
1688
1581
  }
1689
1582
 
1690
1583
  if (res)                                      // Should always be true
1691
 
    update2(thd, type, res);
 
1584
    update2(session, type, res);
1692
1585
}
1693
1586
 
1694
1587
 
1695
 
uchar *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
1696
 
                                               LEX_STRING *base __attribute__((unused)))
 
1588
unsigned char *sys_var_session_date_time_format::value_ptr(Session *session,
 
1589
                                                           enum_var_type type,
 
1590
                                                           LEX_STRING *)
1697
1591
{
1698
1592
  if (type == OPT_GLOBAL)
1699
1593
  {
1703
1597
      is modifying the original string while the copy is accessed
1704
1598
      (Can't happen now in SQL SHOW, but this is a good safety for the future)
1705
1599
    */
1706
 
    res= thd->strmake((global_system_variables.*offset)->format.str,
 
1600
    res= session->strmake((global_system_variables.*offset)->format.str,
1707
1601
                      (global_system_variables.*offset)->format.length);
1708
 
    return (uchar*) res;
 
1602
    return (unsigned char*) res;
1709
1603
  }
1710
 
  return (uchar*) (thd->variables.*offset)->format.str;
 
1604
  return (unsigned char*) (session->variables.*offset)->format.str;
1711
1605
}
1712
1606
 
1713
1607
 
1717
1611
  const char *new_name;
1718
1612
} my_old_conv;
1719
1613
 
1720
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
1721
 
                              set_var *var)
 
1614
bool sys_var_collation::check(Session *, set_var *var)
1722
1615
{
1723
1616
  const CHARSET_INFO *tmp;
1724
1617
 
1752
1645
}
1753
1646
 
1754
1647
 
1755
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
1756
 
                                  set_var *var)
 
1648
bool sys_var_character_set::check(Session *, set_var *var)
1757
1649
{
1758
1650
  const CHARSET_INFO *tmp;
1759
1651
 
1791
1683
}
1792
1684
 
1793
1685
 
1794
 
bool sys_var_character_set::update(THD *thd, set_var *var)
1795
 
{
1796
 
  ci_ptr(thd,var->type)[0]= var->save_result.charset;
1797
 
  thd->update_charset();
1798
 
  return 0;
1799
 
}
1800
 
 
1801
 
 
1802
 
uchar *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
1803
 
                                        LEX_STRING *base __attribute__((unused)))
1804
 
{
1805
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
1806
 
  return cs ? (uchar*) cs->csname : (uchar*) NULL;
1807
 
}
1808
 
 
1809
 
 
1810
 
void sys_var_character_set_sv::set_default(THD *thd, enum_var_type type)
1811
 
{
1812
 
  if (type == OPT_GLOBAL)
1813
 
    global_system_variables.*offset= *global_default;
1814
 
  else
1815
 
  {
1816
 
    thd->variables.*offset= global_system_variables.*offset;
1817
 
    thd->update_charset();
1818
 
  }
1819
 
}
1820
 
const CHARSET_INFO **sys_var_character_set_sv::ci_ptr(THD *thd, enum_var_type type)
1821
 
{
1822
 
  if (type == OPT_GLOBAL)
1823
 
    return &(global_system_variables.*offset);
1824
 
  else
1825
 
    return &(thd->variables.*offset);
1826
 
}
1827
 
 
1828
 
 
1829
 
bool sys_var_character_set_client::check(THD *thd, set_var *var)
1830
 
{
1831
 
  if (sys_var_character_set_sv::check(thd, var))
1832
 
    return 1;
1833
 
  /* Currently, UCS-2 cannot be used as a client character set */
1834
 
  if (var->save_result.charset->mbminlen > 1)
1835
 
  {
1836
 
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), name, 
1837
 
             var->save_result.charset->csname);
1838
 
    return 1;
1839
 
  }
1840
 
  return 0;
1841
 
}
1842
 
 
1843
 
 
1844
 
const CHARSET_INFO ** sys_var_character_set_database::ci_ptr(THD *thd,
1845
 
                                                       enum_var_type type)
1846
 
{
1847
 
  if (type == OPT_GLOBAL)
1848
 
    return &global_system_variables.collation_database;
1849
 
  else
1850
 
    return &thd->variables.collation_database;
1851
 
}
1852
 
 
1853
 
 
1854
 
void sys_var_character_set_database::set_default(THD *thd, enum_var_type type)
1855
 
{
1856
 
 if (type == OPT_GLOBAL)
1857
 
    global_system_variables.collation_database= default_charset_info;
1858
 
  else
1859
 
  {
1860
 
    thd->variables.collation_database= thd->db_charset;
1861
 
    thd->update_charset();
1862
 
  }
1863
 
}
1864
 
 
1865
 
 
1866
 
bool sys_var_collation_sv::update(THD *thd, set_var *var)
 
1686
bool sys_var_character_set::update(Session *session, set_var *var)
 
1687
{
 
1688
  ci_ptr(session,var->type)[0]= var->save_result.charset;
 
1689
  session->update_charset();
 
1690
  return 0;
 
1691
}
 
1692
 
 
1693
 
 
1694
unsigned char *sys_var_character_set::value_ptr(Session *session,
 
1695
                                                enum_var_type type,
 
1696
                                                LEX_STRING *)
 
1697
{
 
1698
  const CHARSET_INFO * const cs= ci_ptr(session,type)[0];
 
1699
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
 
1700
}
 
1701
 
 
1702
 
 
1703
bool sys_var_collation_sv::update(Session *session, set_var *var)
1867
1704
{
1868
1705
  if (var->type == OPT_GLOBAL)
1869
1706
    global_system_variables.*offset= var->save_result.charset;
1870
1707
  else
1871
1708
  {
1872
 
    thd->variables.*offset= var->save_result.charset;
1873
 
    thd->update_charset();
 
1709
    session->variables.*offset= var->save_result.charset;
 
1710
    session->update_charset();
1874
1711
  }
1875
1712
  return 0;
1876
1713
}
1877
1714
 
1878
1715
 
1879
 
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
 
1716
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1880
1717
{
1881
1718
  if (type == OPT_GLOBAL)
1882
1719
    global_system_variables.*offset= *global_default;
1883
1720
  else
1884
1721
  {
1885
 
    thd->variables.*offset= global_system_variables.*offset;
1886
 
    thd->update_charset();
 
1722
    session->variables.*offset= global_system_variables.*offset;
 
1723
    session->update_charset();
1887
1724
  }
1888
1725
}
1889
1726
 
1890
1727
 
1891
 
uchar *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
1892
 
                                       LEX_STRING *base __attribute__((unused)))
 
1728
unsigned char *sys_var_collation_sv::value_ptr(Session *session,
 
1729
                                               enum_var_type type,
 
1730
                                               LEX_STRING *)
1893
1731
{
1894
1732
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1895
 
                     global_system_variables.*offset : thd->variables.*offset);
1896
 
  return cs ? (uchar*) cs->name : (uchar*) "NULL";
 
1733
                           global_system_variables.*offset :
 
1734
                           session->variables.*offset);
 
1735
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1897
1736
}
1898
1737
 
1899
1738
 
1911
1750
}
1912
1751
 
1913
1752
 
1914
 
uchar *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
1915
 
                                          enum_var_type type __attribute__((unused)),
1916
 
                                          LEX_STRING *base __attribute__((unused)))
 
1753
unsigned char *sys_var_key_cache_param::value_ptr(Session *, enum_var_type,
 
1754
                                                  LEX_STRING *base)
1917
1755
{
1918
1756
  KEY_CACHE *key_cache= get_key_cache(base);
1919
1757
  if (!key_cache)
1920
1758
    key_cache= &zero_key_cache;
1921
 
  return (uchar*) key_cache + offset ;
 
1759
  return (unsigned char*) key_cache + offset ;
1922
1760
}
1923
1761
 
1924
1762
 
1925
 
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
 
1763
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1926
1764
{
1927
1765
  uint64_t tmp= var->save_result.uint64_t_value;
1928
1766
  LEX_STRING *base_name= &var->base;
1960
1798
  {
1961
1799
    if (key_cache == dflt_key_cache)
1962
1800
    {
1963
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1801
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1964
1802
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1965
1803
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1966
1804
      goto end;                                 // Ignore default key cache
1977
1815
                                              base_name->length, &list);
1978
1816
      key_cache->in_init= 1;
1979
1817
      pthread_mutex_unlock(&LOCK_global_system_variables);
1980
 
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
 
1818
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1981
1819
      pthread_mutex_lock(&LOCK_global_system_variables);
1982
1820
      key_cache->in_init= 0;
1983
1821
    }
1989
1827
  }
1990
1828
 
1991
1829
  key_cache->param_buff_size=
1992
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1830
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1993
1831
 
1994
1832
  /* If key cache didn't existed initialize it, else resize it */
1995
1833
  key_cache->in_init= 1;
2015
1853
  This should be changed so that we wait until the previous
2016
1854
  assignment is done and then do the new assign
2017
1855
*/
2018
 
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
 
1856
bool sys_var_key_cache_long::update(Session *session, set_var *var)
2019
1857
{
2020
1858
  ulong tmp= (ulong) var->value->val_int();
2021
1859
  LEX_STRING *base_name= &var->base;
2043
1881
    goto end;
2044
1882
 
2045
1883
  *((ulong*) (((char*) key_cache) + offset))=
2046
 
    (ulong) fix_unsigned(thd, tmp, option_limits);
 
1884
    (ulong) fix_unsigned(session, tmp, option_limits);
2047
1885
 
2048
1886
  /*
2049
1887
    Don't create a new key cache if it didn't exist
2056
1894
  error= (bool) (ha_resize_key_cache(key_cache));
2057
1895
 
2058
1896
  pthread_mutex_lock(&LOCK_global_system_variables);
2059
 
  key_cache->in_init= 0;  
 
1897
  key_cache->in_init= 0;
2060
1898
 
2061
1899
end:
2062
1900
  pthread_mutex_unlock(&LOCK_global_system_variables);
2064
1902
}
2065
1903
 
2066
1904
 
2067
 
bool sys_var_log_state::update(THD *thd, set_var *var)
 
1905
bool sys_var_log_state::update(Session *, set_var *var)
2068
1906
{
2069
1907
  bool res;
2070
1908
  pthread_mutex_lock(&LOCK_global_system_variables);
2071
 
  if (!var->save_result.ulong_value)
2072
 
  {
2073
 
    logger.deactivate_log_handler(thd, log_type);
 
1909
  if (!var->save_result.uint32_t_value)
2074
1910
    res= false;
2075
 
  }
2076
1911
  else
2077
 
    res= logger.activate_log_handler(thd, log_type);
 
1912
    res= true;
2078
1913
  pthread_mutex_unlock(&LOCK_global_system_variables);
2079
1914
  return res;
2080
1915
}
2081
1916
 
2082
 
void sys_var_log_state::set_default(THD *thd,
2083
 
                                    enum_var_type type __attribute__((unused)))
2084
 
{
2085
 
  pthread_mutex_lock(&LOCK_global_system_variables);
2086
 
  logger.deactivate_log_handler(thd, log_type);
2087
 
  pthread_mutex_unlock(&LOCK_global_system_variables);
2088
 
}
2089
 
 
2090
 
 
2091
 
static int  sys_check_log_path(THD *thd __attribute__((unused)),
2092
 
                               set_var *var)
2093
 
{
2094
 
  char path[FN_REFLEN], buff[FN_REFLEN];
2095
 
  struct stat f_stat;
2096
 
  String str(buff, sizeof(buff), system_charset_info), *res;
2097
 
  const char *log_file_str;
2098
 
  size_t path_length;
2099
 
 
2100
 
  if (!(res= var->value->val_str(&str)))
2101
 
    goto err;
2102
 
 
2103
 
  log_file_str= res->c_ptr();
2104
 
  memset(&f_stat, 0, sizeof(struct stat));
2105
 
 
2106
 
  path_length= unpack_filename(path, log_file_str);
2107
 
 
2108
 
  if (!path_length)
2109
 
  {
2110
 
    /* File name is empty. */
2111
 
 
2112
 
    goto err;
2113
 
  }
2114
 
 
2115
 
  if (!stat(path, &f_stat))
2116
 
  {
2117
 
    /*
2118
 
      A file system object exists. Check if argument is a file and we have
2119
 
      'write' permission.
2120
 
    */
2121
 
 
2122
 
    if (!S_ISREG(f_stat.st_mode) ||
2123
 
        !(f_stat.st_mode & S_IWRITE))
2124
 
      goto err;
2125
 
 
2126
 
    return 0;
2127
 
  }
2128
 
 
2129
 
  /* Get dirname of the file path. */
2130
 
  (void) dirname_part(path, log_file_str, &path_length);
2131
 
 
2132
 
  /* Dirname is empty if file path is relative. */
2133
 
  if (!path_length)
2134
 
    return 0;
2135
 
 
2136
 
  /*
2137
 
    Check if directory exists and we have permission to create file and
2138
 
    write to file.
2139
 
  */
2140
 
  if (my_access(path, (F_OK|W_OK)))
2141
 
    goto err;
2142
 
 
2143
 
  return 0;
2144
 
 
2145
 
err:
2146
 
  my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), var->var->name, 
2147
 
           res ? log_file_str : "NULL");
2148
 
  return 1;
2149
 
}
2150
 
 
2151
 
 
2152
 
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
2153
 
                             sys_var_str *var_str,
 
1917
void sys_var_log_state::set_default(Session *, enum_var_type)
 
1918
{
 
1919
}
 
1920
 
 
1921
 
 
1922
bool update_sys_var_str_path(Session *, sys_var_str *var_str,
2154
1923
                             set_var *var, const char *log_ext,
2155
 
                             bool log_state, uint log_type)
 
1924
                             bool log_state, uint32_t log_type)
2156
1925
{
2157
 
  DRIZZLE_QUERY_LOG *file_log;
2158
1926
  char buff[FN_REFLEN];
2159
1927
  char *res= 0, *old_value=(char *)(var ? var->value->str_value.ptr() : 0);
2160
1928
  bool result= 0;
2161
 
  uint str_length= (var ? var->value->str_value.length() : 0);
 
1929
  uint32_t str_length= (var ? var->value->str_value.length() : 0);
2162
1930
 
2163
1931
  switch (log_type) {
2164
 
  case QUERY_LOG_SLOW:
2165
 
    file_log= logger.get_slow_log_file_handler();
2166
 
    break;
2167
 
  case QUERY_LOG_GENERAL:
2168
 
    file_log= logger.get_log_file_handler();
2169
 
    break;
2170
1932
  default:
2171
1933
    assert(0);                                  // Impossible
2172
1934
  }
2185
1947
  pthread_mutex_lock(&LOCK_global_system_variables);
2186
1948
  logger.lock_exclusive();
2187
1949
 
2188
 
  if (file_log && log_state)
2189
 
    file_log->close(0);
2190
1950
  old_value= var_str->value;
2191
1951
  var_str->value= res;
2192
1952
  var_str->value_length= str_length;
2193
 
  my_free(old_value, MYF(MY_ALLOW_ZERO_PTR));
2194
 
  if (file_log && log_state)
 
1953
  free(old_value);
 
1954
  if (log_state)
2195
1955
  {
2196
1956
    switch (log_type) {
2197
 
    case QUERY_LOG_SLOW:
2198
 
      file_log->open_slow_log(sys_var_slow_log_path.value);
2199
 
      break;
2200
 
    case QUERY_LOG_GENERAL:
2201
 
      file_log->open_query_log(sys_var_general_log_path.value);
2202
 
      break;
2203
1957
    default:
2204
1958
      assert(0);
2205
1959
    }
2213
1967
}
2214
1968
 
2215
1969
 
2216
 
static bool sys_update_general_log_path(THD *thd, set_var * var)
2217
 
{
2218
 
  return update_sys_var_str_path(thd, &sys_var_general_log_path,
2219
 
                                 var, ".log", opt_log, QUERY_LOG_GENERAL);
2220
 
}
2221
 
 
2222
 
 
2223
 
static void sys_default_general_log_path(THD *thd,
2224
 
                                         enum_var_type type __attribute__((unused)))
2225
 
{
2226
 
  (void) update_sys_var_str_path(thd, &sys_var_general_log_path,
2227
 
                                 0, ".log", opt_log, QUERY_LOG_GENERAL);
2228
 
}
2229
 
 
2230
 
 
2231
 
static bool sys_update_slow_log_path(THD *thd, set_var * var)
2232
 
{
2233
 
  return update_sys_var_str_path(thd, &sys_var_slow_log_path,
2234
 
                                 var, "-slow.log", opt_slow_log,
2235
 
                                 QUERY_LOG_SLOW);
2236
 
}
2237
 
 
2238
 
 
2239
 
static void sys_default_slow_log_path(THD *thd,
2240
 
                                      enum_var_type type __attribute__((unused)))
2241
 
{
2242
 
  (void) update_sys_var_str_path(thd, &sys_var_slow_log_path,
2243
 
                                 0, "-slow.log", opt_slow_log,
2244
 
                                 QUERY_LOG_SLOW);
2245
 
}
2246
 
 
2247
 
 
2248
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
2249
 
                                set_var *var)
 
1970
bool sys_var_log_output::update(Session *, set_var *var)
2250
1971
{
2251
1972
  pthread_mutex_lock(&LOCK_global_system_variables);
2252
1973
  logger.lock_exclusive();
2253
 
  logger.init_slow_log(var->save_result.ulong_value);
2254
 
  logger.init_general_log(var->save_result.ulong_value);
2255
 
  *value= var->save_result.ulong_value;
 
1974
  *value= var->save_result.uint32_t_value;
2256
1975
  logger.unlock();
2257
1976
  pthread_mutex_unlock(&LOCK_global_system_variables);
2258
1977
  return 0;
2259
1978
}
2260
1979
 
2261
1980
 
2262
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
2263
 
                                     enum_var_type type __attribute__((unused)))
 
1981
void sys_var_log_output::set_default(Session *, enum_var_type)
2264
1982
{
2265
1983
  pthread_mutex_lock(&LOCK_global_system_variables);
2266
1984
  logger.lock_exclusive();
2267
 
  logger.init_slow_log(LOG_FILE);
2268
 
  logger.init_general_log(LOG_FILE);
2269
1985
  *value= LOG_FILE;
2270
1986
  logger.unlock();
2271
1987
  pthread_mutex_unlock(&LOCK_global_system_variables);
2272
1988
}
2273
1989
 
2274
1990
 
2275
 
uchar *sys_var_log_output::value_ptr(THD *thd,
2276
 
                                     enum_var_type type __attribute__((unused)),
2277
 
                                     LEX_STRING *base __attribute__((unused)))
 
1991
unsigned char *sys_var_log_output::value_ptr(Session *session,
 
1992
                                             enum_var_type, LEX_STRING *)
2278
1993
{
2279
1994
  char buff[256];
2280
1995
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2282
1997
  ulong val= *value;
2283
1998
 
2284
1999
  tmp.length(0);
2285
 
  for (uint i= 0; val; val>>= 1, i++)
 
2000
  for (uint32_t i= 0; val; val>>= 1, i++)
2286
2001
  {
2287
2002
    if (val & 1)
2288
2003
    {
2294
2009
 
2295
2010
  if ((length= tmp.length()))
2296
2011
    length--;
2297
 
  return (uchar*) thd->strmake(tmp.ptr(), length);
 
2012
  return (unsigned char*) session->strmake(tmp.ptr(), length);
2298
2013
}
2299
2014
 
2300
2015
 
2302
2017
  Functions to handle SET NAMES and SET CHARACTER SET
2303
2018
*****************************************************************************/
2304
2019
 
2305
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
 
2020
int set_var_collation_client::check(Session *)
2306
2021
{
2307
2022
  /* Currently, UCS-2 cannot be used as a client character set */
2308
2023
  if (character_set_client->mbminlen > 1)
2314
2029
  return 0;
2315
2030
}
2316
2031
 
2317
 
int set_var_collation_client::update(THD *thd)
 
2032
int set_var_collation_client::update(Session *session)
2318
2033
{
2319
 
  thd->variables.character_set_client= character_set_client;
2320
 
  thd->variables.character_set_results= character_set_results;
2321
 
  thd->variables.collation_connection= collation_connection;
2322
 
  thd->update_charset();
2323
 
  thd->protocol_text.init(thd);
 
2034
  session->variables.character_set_client= character_set_client;
 
2035
  session->variables.character_set_results= character_set_results;
 
2036
  session->variables.collation_connection= collation_connection;
 
2037
  session->update_charset();
 
2038
  session->protocol_text.init(session);
2324
2039
  return 0;
2325
2040
}
2326
2041
 
2327
2042
/****************************************************************************/
2328
2043
 
2329
 
bool sys_var_timestamp::update(THD *thd,  set_var *var)
 
2044
bool sys_var_timestamp::update(Session *session,  set_var *var)
2330
2045
{
2331
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
2046
  session->set_time((time_t) var->save_result.uint64_t_value);
2332
2047
  return 0;
2333
2048
}
2334
2049
 
2335
2050
 
2336
 
void sys_var_timestamp::set_default(THD *thd,
2337
 
                                    enum_var_type type __attribute__((unused)))
2338
 
{
2339
 
  thd->user_time=0;
2340
 
}
2341
 
 
2342
 
 
2343
 
uchar *sys_var_timestamp::value_ptr(THD *thd,
2344
 
                                    enum_var_type type __attribute__((unused)),
2345
 
                                    LEX_STRING *base __attribute__((unused)))
2346
 
{
2347
 
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2348
 
  return (uchar*) &thd->sys_var_tmp.long_value;
2349
 
}
2350
 
 
2351
 
 
2352
 
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
2353
 
{
2354
 
  thd->first_successful_insert_id_in_prev_stmt=
 
2051
void sys_var_timestamp::set_default(Session *session, enum_var_type)
 
2052
{
 
2053
  session->user_time=0;
 
2054
}
 
2055
 
 
2056
 
 
2057
unsigned char *sys_var_timestamp::value_ptr(Session *session, enum_var_type,
 
2058
                                            LEX_STRING *)
 
2059
{
 
2060
  session->sys_var_tmp.long_value= (long) session->start_time;
 
2061
  return (unsigned char*) &session->sys_var_tmp.long_value;
 
2062
}
 
2063
 
 
2064
 
 
2065
bool sys_var_last_insert_id::update(Session *session, set_var *var)
 
2066
{
 
2067
  session->first_successful_insert_id_in_prev_stmt=
2355
2068
    var->save_result.uint64_t_value;
2356
2069
  return 0;
2357
2070
}
2358
2071
 
2359
2072
 
2360
 
uchar *sys_var_last_insert_id::value_ptr(THD *thd,
2361
 
                                         enum_var_type type __attribute__((unused)),
2362
 
                                         LEX_STRING *base __attribute__((unused)))
 
2073
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
 
2074
                                                 enum_var_type,
 
2075
                                                 LEX_STRING *)
2363
2076
{
2364
2077
  /*
2365
2078
    this tmp var makes it robust againt change of type of
2366
2079
    read_first_successful_insert_id_in_prev_stmt().
2367
2080
  */
2368
 
  thd->sys_var_tmp.uint64_t_value= 
2369
 
    thd->read_first_successful_insert_id_in_prev_stmt();
2370
 
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2371
 
}
2372
 
 
2373
 
 
2374
 
bool sys_var_insert_id::update(THD *thd, set_var *var)
2375
 
{
2376
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2377
 
  return 0;
2378
 
}
2379
 
 
2380
 
 
2381
 
uchar *sys_var_insert_id::value_ptr(THD *thd,
2382
 
                                    enum_var_type type __attribute__((unused)),
2383
 
                                    LEX_STRING *base __attribute__((unused)))
2384
 
{
2385
 
  thd->sys_var_tmp.uint64_t_value=
2386
 
    thd->auto_inc_intervals_forced.minimum();
2387
 
  return (uchar*) &thd->sys_var_tmp.uint64_t_value;
2388
 
}
2389
 
 
2390
 
 
2391
 
bool sys_var_rand_seed1::update(THD *thd, set_var *var)
2392
 
{
2393
 
  thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2394
 
  return 0;
2395
 
}
2396
 
 
2397
 
bool sys_var_rand_seed2::update(THD *thd, set_var *var)
2398
 
{
2399
 
  thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2400
 
  return 0;
2401
 
}
2402
 
 
2403
 
 
2404
 
bool sys_var_thd_time_zone::check(THD *thd, set_var *var)
 
2081
  session->sys_var_tmp.uint64_t_value=
 
2082
    session->read_first_successful_insert_id_in_prev_stmt();
 
2083
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
2084
}
 
2085
 
 
2086
 
 
2087
bool sys_var_insert_id::update(Session *session, set_var *var)
 
2088
{
 
2089
  session->force_one_auto_inc_interval(var->save_result.uint64_t_value);
 
2090
  return 0;
 
2091
}
 
2092
 
 
2093
 
 
2094
unsigned char *sys_var_insert_id::value_ptr(Session *session, enum_var_type,
 
2095
                                            LEX_STRING *)
 
2096
{
 
2097
  session->sys_var_tmp.uint64_t_value=
 
2098
    session->auto_inc_intervals_forced.minimum();
 
2099
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
2100
}
 
2101
 
 
2102
 
 
2103
bool sys_var_rand_seed1::update(Session *session, set_var *var)
 
2104
{
 
2105
  session->rand.seed1= (ulong) var->save_result.uint64_t_value;
 
2106
  return 0;
 
2107
}
 
2108
 
 
2109
bool sys_var_rand_seed2::update(Session *session, set_var *var)
 
2110
{
 
2111
  session->rand.seed2= (ulong) var->save_result.uint64_t_value;
 
2112
  return 0;
 
2113
}
 
2114
 
 
2115
 
 
2116
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2405
2117
{
2406
2118
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2407
2119
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2408
2120
  String *res= var->value->val_str(&str);
2409
2121
 
2410
 
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
 
2122
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
2411
2123
  {
2412
2124
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2413
2125
    return 1;
2416
2128
}
2417
2129
 
2418
2130
 
2419
 
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
 
2131
bool sys_var_session_time_zone::update(Session *session, set_var *var)
2420
2132
{
2421
2133
  /* We are using Time_zone object found during check() phase. */
2422
2134
  if (var->type == OPT_GLOBAL)
2426
2138
    pthread_mutex_unlock(&LOCK_global_system_variables);
2427
2139
  }
2428
2140
  else
2429
 
    thd->variables.time_zone= var->save_result.time_zone;
 
2141
    session->variables.time_zone= var->save_result.time_zone;
2430
2142
  return 0;
2431
2143
}
2432
2144
 
2433
2145
 
2434
 
uchar *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
2435
 
                                        LEX_STRING *base __attribute__((unused)))
 
2146
unsigned char *sys_var_session_time_zone::value_ptr(Session *session,
 
2147
                                                    enum_var_type type,
 
2148
                                                    LEX_STRING *)
2436
2149
{
2437
 
  /* 
 
2150
  /*
2438
2151
    We can use ptr() instead of c_ptr() here because String contaning
2439
2152
    time zone name is guaranteed to be zero ended.
2440
2153
  */
2441
2154
  if (type == OPT_GLOBAL)
2442
 
    return (uchar *)(global_system_variables.time_zone->get_name()->ptr());
 
2155
    return (unsigned char *)(global_system_variables.time_zone->get_name()->ptr());
2443
2156
  else
2444
2157
  {
2445
2158
    /*
2450
2163
      timezone). If it's the global value which was used we can't replicate
2451
2164
      (binlog code stores session value only).
2452
2165
    */
2453
 
    thd->time_zone_used= 1;
2454
 
    return (uchar *)(thd->variables.time_zone->get_name()->ptr());
 
2166
    session->time_zone_used= 1;
 
2167
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
2455
2168
  }
2456
2169
}
2457
2170
 
2458
2171
 
2459
 
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
 
2172
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
2460
2173
{
2461
2174
 pthread_mutex_lock(&LOCK_global_system_variables);
2462
2175
 if (type == OPT_GLOBAL)
2468
2181
       We are guaranteed to find this time zone since its existence
2469
2182
       is checked during start-up.
2470
2183
     */
2471
 
     global_system_variables.time_zone= my_tz_find(thd, &str);
 
2184
     global_system_variables.time_zone= my_tz_find(session, &str);
2472
2185
   }
2473
2186
   else
2474
2187
     global_system_variables.time_zone= my_tz_SYSTEM;
2475
2188
 }
2476
2189
 else
2477
 
   thd->variables.time_zone= global_system_variables.time_zone;
 
2190
   session->variables.time_zone= global_system_variables.time_zone;
2478
2191
 pthread_mutex_unlock(&LOCK_global_system_variables);
2479
2192
}
2480
2193
 
2481
2194
 
2482
 
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
 
2195
bool sys_var_max_user_conn::check(Session *session, set_var *var)
2483
2196
{
2484
2197
  if (var->type == OPT_GLOBAL)
2485
 
    return sys_var_thd::check(thd, var);
 
2198
    return sys_var_session::check(session, var);
2486
2199
  else
2487
2200
  {
2488
2201
    /*
2494
2207
  }
2495
2208
}
2496
2209
 
2497
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
2498
 
                                   set_var *var)
 
2210
bool sys_var_max_user_conn::update(Session *, set_var *var)
2499
2211
{
2500
2212
  assert(var->type == OPT_GLOBAL);
2501
2213
  pthread_mutex_lock(&LOCK_global_system_variables);
2505
2217
}
2506
2218
 
2507
2219
 
2508
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
2509
 
                                        enum_var_type type __attribute__((unused)))
 
2220
void sys_var_max_user_conn::set_default(Session *, enum_var_type type)
2510
2221
{
2511
2222
  assert(type == OPT_GLOBAL);
2512
2223
  pthread_mutex_lock(&LOCK_global_system_variables);
2515
2226
}
2516
2227
 
2517
2228
 
2518
 
uchar *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
2519
 
                                        LEX_STRING *base __attribute__((unused)))
 
2229
unsigned char *sys_var_max_user_conn::value_ptr(Session *session,
 
2230
                                                enum_var_type type,
 
2231
                                                LEX_STRING *)
2520
2232
{
2521
2233
  if (type != OPT_GLOBAL &&
2522
 
      thd->user_connect && thd->user_connect->user_resources.user_conn)
2523
 
    return (uchar*) &(thd->user_connect->user_resources.user_conn);
2524
 
  return (uchar*) &(max_user_connections);
 
2234
      session->user_connect && session->user_connect->user_resources.user_conn)
 
2235
    return (unsigned char*) &(session->user_connect->user_resources.user_conn);
 
2236
  return (unsigned char*) &(max_user_connections);
2525
2237
}
2526
2238
 
2527
2239
 
2528
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
2529
 
                                      set_var *var)
 
2240
bool sys_var_session_lc_time_names::check(Session *, set_var *var)
2530
2241
{
2531
2242
  MY_LOCALE *locale_match;
2532
2243
 
2563
2274
}
2564
2275
 
2565
2276
 
2566
 
bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var)
 
2277
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2567
2278
{
2568
2279
  if (var->type == OPT_GLOBAL)
2569
2280
    global_system_variables.lc_time_names= var->save_result.locale_value;
2570
2281
  else
2571
 
    thd->variables.lc_time_names= var->save_result.locale_value;
 
2282
    session->variables.lc_time_names= var->save_result.locale_value;
2572
2283
  return 0;
2573
2284
}
2574
2285
 
2575
2286
 
2576
 
uchar *sys_var_thd_lc_time_names::value_ptr(THD *thd,
2577
 
                                            enum_var_type type,
2578
 
                                            LEX_STRING *base __attribute__((unused)))
 
2287
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
 
2288
                                                        enum_var_type type,
 
2289
                                                        LEX_STRING *)
2579
2290
{
2580
2291
  return type == OPT_GLOBAL ?
2581
 
                 (uchar *) global_system_variables.lc_time_names->name :
2582
 
                 (uchar *) thd->variables.lc_time_names->name;
 
2292
                 (unsigned char *) global_system_variables.lc_time_names->name :
 
2293
                 (unsigned char *) session->variables.lc_time_names->name;
2583
2294
}
2584
2295
 
2585
2296
 
2586
 
void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type)
 
2297
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
2587
2298
{
2588
2299
  if (type == OPT_GLOBAL)
2589
2300
    global_system_variables.lc_time_names= my_default_lc_time_names;
2590
2301
  else
2591
 
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
 
2302
    session->variables.lc_time_names= global_system_variables.lc_time_names;
2592
2303
}
2593
2304
 
2594
2305
/*
2600
2311
    This is used for handling long_query_time
2601
2312
*/
2602
2313
 
2603
 
bool sys_var_microseconds::update(THD *thd, set_var *var)
 
2314
bool sys_var_microseconds::update(Session *session, set_var *var)
2604
2315
{
2605
2316
  double num= var->value->val_real();
2606
2317
  int64_t microseconds;
2616
2327
    pthread_mutex_unlock(&LOCK_global_system_variables);
2617
2328
  }
2618
2329
  else
2619
 
    thd->variables.*offset= microseconds;
 
2330
    session->variables.*offset= microseconds;
2620
2331
  return 0;
2621
2332
}
2622
2333
 
2623
2334
 
2624
 
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
 
2335
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
2625
2336
{
2626
2337
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
2627
2338
  if (type == OPT_GLOBAL)
2631
2342
    pthread_mutex_unlock(&LOCK_global_system_variables);
2632
2343
  }
2633
2344
  else
2634
 
    thd->variables.*offset= microseconds;
 
2345
    session->variables.*offset= microseconds;
2635
2346
}
2636
2347
 
2637
2348
 
2638
 
uchar *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
2639
 
                                          LEX_STRING *base __attribute__((unused)))
 
2349
unsigned char *sys_var_microseconds::value_ptr(Session *session,
 
2350
                                               enum_var_type type,
 
2351
                                               LEX_STRING *)
2640
2352
{
2641
 
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
2353
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2642
2354
                                   global_system_variables.*offset :
2643
 
                                   thd->variables.*offset) / 1000000.0;
2644
 
  return (uchar*) &thd->tmp_double_value;
 
2355
                                   session->variables.*offset) / 1000000.0;
 
2356
  return (unsigned char*) &session->tmp_double_value;
2645
2357
}
2646
2358
 
2647
2359
 
2648
2360
/*
2649
 
  Functions to update thd->options bits
 
2361
  Functions to update session->options bits
2650
2362
*/
2651
2363
 
2652
 
static bool set_option_bit(THD *thd, set_var *var)
 
2364
static bool set_option_bit(Session *session, set_var *var)
2653
2365
{
2654
 
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
2655
 
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2656
 
    thd->options&= ~sys_var->bit_flag;
 
2366
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
 
2367
  if ((var->save_result.uint32_t_value != 0) == sys_var->reverse)
 
2368
    session->options&= ~sys_var->bit_flag;
2657
2369
  else
2658
 
    thd->options|= sys_var->bit_flag;
 
2370
    session->options|= sys_var->bit_flag;
2659
2371
  return 0;
2660
2372
}
2661
2373
 
2662
2374
 
2663
 
static bool set_option_autocommit(THD *thd, set_var *var)
 
2375
static bool set_option_autocommit(Session *session, set_var *var)
2664
2376
{
2665
2377
  /* The test is negative as the flag we use is NOT autocommit */
2666
2378
 
2667
 
  uint64_t org_options= thd->options;
 
2379
  uint64_t org_options= session->options;
2668
2380
 
2669
 
  if (var->save_result.ulong_value != 0)
2670
 
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
 
2381
  if (var->save_result.uint32_t_value != 0)
 
2382
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2671
2383
  else
2672
 
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
 
2384
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2673
2385
 
2674
 
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
 
2386
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2675
2387
  {
2676
2388
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2677
2389
    {
2678
2390
      /* We changed to auto_commit mode */
2679
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2680
 
      thd->transaction.all.modified_non_trans_table= false;
2681
 
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2682
 
      if (ha_commit(thd))
 
2391
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2392
      session->transaction.all.modified_non_trans_table= false;
 
2393
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
2394
      if (ha_commit(session))
2683
2395
        return 1;
2684
2396
    }
2685
2397
    else
2686
2398
    {
2687
 
      thd->transaction.all.modified_non_trans_table= false;
2688
 
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
2399
      session->transaction.all.modified_non_trans_table= false;
 
2400
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2689
2401
    }
2690
2402
  }
2691
2403
  return 0;
2692
2404
}
2693
2405
 
2694
 
static int check_log_update(THD *thd __attribute__((unused)),
2695
 
                            set_var *var __attribute__((unused)))
2696
 
{
2697
 
  return 0;
2698
 
}
2699
 
 
2700
 
static bool set_log_update(THD *thd __attribute__((unused)),
2701
 
                           set_var *var __attribute__((unused)))
2702
 
{
2703
 
  /*
2704
 
    The update log is not supported anymore since 5.0.
2705
 
    See sql/mysqld.cc/, comments in function init_server_components() for an
2706
 
    explaination of the different warnings we send below
2707
 
  */
2708
 
 
2709
 
  if (opt_sql_bin_update)
2710
 
  {
2711
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2712
 
                 ER_UPDATE_LOG_DEPRECATED_TRANSLATED,
2713
 
                 ER(ER_UPDATE_LOG_DEPRECATED_TRANSLATED));
2714
 
  }
2715
 
  else
2716
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
2717
 
                 ER_UPDATE_LOG_DEPRECATED_IGNORED,
2718
 
                 ER(ER_UPDATE_LOG_DEPRECATED_IGNORED));
2719
 
  set_option_bit(thd, var);
2720
 
  return 0;
2721
 
}
2722
 
 
2723
 
 
2724
 
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
2725
 
                                  set_var *var)
 
2406
static int check_log_update(Session *, set_var *)
 
2407
{
 
2408
  return 0;
 
2409
}
 
2410
 
 
2411
 
 
2412
static int check_pseudo_thread_id(Session *, set_var *var)
2726
2413
{
2727
2414
  var->save_result.uint64_t_value= var->value->val_int();
2728
2415
  return 0;
2729
2416
}
2730
2417
 
2731
 
static uchar *get_warning_count(THD *thd)
 
2418
static unsigned char *get_warning_count(Session *session)
2732
2419
{
2733
 
  thd->sys_var_tmp.long_value=
2734
 
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2735
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2736
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2737
 
  return (uchar*) &thd->sys_var_tmp.long_value;
 
2420
  session->sys_var_tmp.long_value=
 
2421
    (session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
 
2422
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
 
2423
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
 
2424
  return (unsigned char*) &session->sys_var_tmp.long_value;
2738
2425
}
2739
2426
 
2740
 
static uchar *get_error_count(THD *thd)
 
2427
static unsigned char *get_error_count(Session *session)
2741
2428
{
2742
 
  thd->sys_var_tmp.long_value= 
2743
 
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2744
 
  return (uchar*) &thd->sys_var_tmp.long_value;
 
2429
  session->sys_var_tmp.long_value= 
 
2430
    session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
 
2431
  return (unsigned char*) &session->sys_var_tmp.long_value;
2745
2432
}
2746
2433
 
2747
2434
 
2754
2441
  that is actually a call to my_tmpdir() which cycles among possible
2755
2442
  temporary directories.
2756
2443
 
2757
 
  @param thd            thread handle
 
2444
  @param session                thread handle
2758
2445
 
2759
2446
  @retval
2760
2447
    ptr         pointer to NUL-terminated string
2761
2448
*/
2762
 
static uchar *get_tmpdir(THD *thd __attribute__((unused)))
 
2449
static unsigned char *get_tmpdir(Session *)
2763
2450
{
2764
2451
  if (opt_mysql_tmpdir)
2765
 
    return (uchar *)opt_mysql_tmpdir;
2766
 
  return (uchar*)mysql_tmpdir;
 
2452
    return (unsigned char *)opt_mysql_tmpdir;
 
2453
  return (unsigned char*)mysql_tmpdir;
2767
2454
}
2768
2455
 
2769
2456
/****************************************************************************
2788
2475
 
2789
2476
static struct my_option *find_option(struct my_option *opt, const char *name) 
2790
2477
{
2791
 
  uint length=strlen(name);
 
2478
  uint32_t length=strlen(name);
2792
2479
  for (; opt->name; opt++)
2793
2480
  {
2794
2481
    if (!getopt_compare_strings(opt->name, name, length) &&
2809
2496
  Return variable name and length for hashing of variables.
2810
2497
*/
2811
2498
 
2812
 
static uchar *get_sys_var_length(const sys_var *var, size_t *length,
2813
 
                                 bool first __attribute__((unused)))
 
2499
static unsigned char *get_sys_var_length(const sys_var *var, size_t *length,
 
2500
                                         bool)
2814
2501
{
2815
2502
  *length= var->name_length;
2816
 
  return (uchar*) var->name;
 
2503
  return (unsigned char*) var->name;
2817
2504
}
2818
2505
 
2819
2506
 
2841
2528
  {
2842
2529
    var->name_length= strlen(var->name);
2843
2530
    /* this fails if there is a conflicting variable name. see HASH_UNIQUE */
2844
 
    if (my_hash_insert(&system_variable_hash, (uchar*) var))
 
2531
    if (my_hash_insert(&system_variable_hash, (unsigned char*) var))
2845
2532
      goto error;
2846
2533
    if (long_options)
2847
2534
      var->option_limits= find_option(long_options, var->name);
2850
2537
 
2851
2538
error:
2852
2539
  for (; first != var; first= first->next)
2853
 
    hash_delete(&system_variable_hash, (uchar*) first);
 
2540
    hash_delete(&system_variable_hash, (unsigned char*) first);
2854
2541
  return 1;
2855
2542
}
2856
2543
 
2874
2561
  /* A write lock should be held on LOCK_system_variables_hash */
2875
2562
   
2876
2563
  for (sys_var *var= first; var; var= var->next)
2877
 
    result|= hash_delete(&system_variable_hash, (uchar*) var);
 
2564
    result|= hash_delete(&system_variable_hash, (unsigned char*) var);
2878
2565
 
2879
2566
  return result;
2880
2567
}
2891
2578
  
2892
2579
  SYNOPSIS
2893
2580
    enumerate_sys_vars()
2894
 
    thd         current thread
 
2581
    session         current thread
2895
2582
    sorted      If TRUE, the system variables should be sorted
2896
2583
  
2897
2584
  RETURN VALUES
2899
2586
    NULL        FAILURE
2900
2587
*/
2901
2588
 
2902
 
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
 
2589
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted)
2903
2590
{
2904
2591
  int count= system_variable_hash.records, i;
2905
2592
  int fixed_count= fixed_show_vars.elements;
2906
2593
  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2907
 
  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
 
2594
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2908
2595
 
2909
2596
  if (result)
2910
2597
  {
2945
2632
 
2946
2633
int set_var_init()
2947
2634
{
2948
 
  uint count= 0;
 
2635
  uint32_t count= 0;
2949
2636
  
2950
2637
  for (sys_var *var=vars.first; var; var= var->next, count++) {};
2951
2638
 
2991
2678
    0           SUCCESS
2992
2679
    otherwise   FAILURE
2993
2680
*/
2994
 
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint count)
 
2681
int mysql_append_static_vars(const SHOW_VAR *show_vars, uint32_t count)
2995
2682
{
2996
2683
  for (; count > 0; count--, show_vars++)
2997
 
    if (insert_dynamic(&fixed_show_vars, (uchar*) show_vars))
 
2684
    if (insert_dynamic(&fixed_show_vars, (unsigned char*) show_vars))
2998
2685
      return 1;
2999
2686
  return 0;
3000
2687
}
3014
2701
    0           Unknown variable (error message is given)
3015
2702
*/
3016
2703
 
3017
 
sys_var *intern_find_sys_var(const char *str, uint length, bool no_error)
 
2704
sys_var *intern_find_sys_var(const char *str, uint32_t length, bool no_error)
3018
2705
{
3019
2706
  sys_var *var;
3020
2707
 
3023
2710
    A lock on LOCK_system_variable_hash should be held
3024
2711
  */
3025
2712
  var= (sys_var*) hash_search(&system_variable_hash,
3026
 
                              (uchar*) str, length ? length : strlen(str));
 
2713
                              (unsigned char*) str, length ? length : strlen(str));
3027
2714
  if (!(var || no_error))
3028
2715
    my_error(ER_UNKNOWN_SYSTEM_VARIABLE, MYF(0), (char*) str);
3029
2716
 
3040
2727
  This should ensure that in all normal cases none all or variables are
3041
2728
  updated.
3042
2729
 
3043
 
  @param THD            Thread id
 
2730
  @param Session                Thread id
3044
2731
  @param var_list       List of variables to update
3045
2732
 
3046
2733
  @retval
3051
2738
    -1  ERROR, message not sent
3052
2739
*/
3053
2740
 
3054
 
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
 
2741
int sql_set_variables(Session *session, List<set_var_base> *var_list)
3055
2742
{
3056
2743
  int error;
3057
2744
  List_iterator_fast<set_var_base> it(*var_list);
3059
2746
  set_var_base *var;
3060
2747
  while ((var=it++))
3061
2748
  {
3062
 
    if ((error= var->check(thd)))
 
2749
    if ((error= var->check(session)))
3063
2750
      goto err;
3064
2751
  }
3065
 
  if (!(error= test(thd->is_error())))
 
2752
  if (!(error= test(session->is_error())))
3066
2753
  {
3067
2754
    it.rewind();
3068
2755
    while ((var= it++))
3069
 
      error|= var->update(thd);         // Returns 0, -1 or 1
 
2756
      error|= var->update(session);         // Returns 0, -1 or 1
3070
2757
  }
3071
2758
 
3072
2759
err:
3073
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
2760
  free_underlaid_joins(session, &session->lex->select_lex);
3074
2761
  return(error);
3075
2762
}
3076
2763
 
3108
2795
  Functions to handle SET mysql_internal_variable=const_expr
3109
2796
*****************************************************************************/
3110
2797
 
3111
 
int set_var::check(THD *thd)
 
2798
int set_var::check(Session *session)
3112
2799
{
3113
2800
  if (var->is_readonly())
3114
2801
  {
3133
2820
  }
3134
2821
 
3135
2822
  if ((!value->fixed &&
3136
 
       value->fix_fields(thd, &value)) || value->check_cols(1))
 
2823
       value->fix_fields(session, &value)) || value->check_cols(1))
3137
2824
    return -1;
3138
2825
  if (var->check_update_type(value->result_type()))
3139
2826
  {
3140
2827
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
3141
2828
    return -1;
3142
2829
  }
3143
 
  return var->check(thd, this) ? -1 : 0;
 
2830
  return var->check(session, this) ? -1 : 0;
3144
2831
}
3145
2832
 
3146
2833
/**
3147
2834
  Update variable
3148
2835
 
3149
 
  @param   thd    thread handler
 
2836
  @param   session    thread handler
3150
2837
  @returns 0|1    ok or ERROR
3151
2838
 
3152
2839
  @note ERROR can be only due to abnormal operations involving
3155
2842
  Consider set_var::check() method if there is a need to return
3156
2843
  an error due to logics.
3157
2844
*/
3158
 
int set_var::update(THD *thd)
 
2845
int set_var::update(Session *session)
3159
2846
{
3160
2847
  if (!value)
3161
 
    var->set_default(thd, type);
3162
 
  else if (var->update(thd, this))
 
2848
    var->set_default(session, type);
 
2849
  else if (var->update(session, this))
3163
2850
    return -1;                          // should never happen
3164
2851
  if (var->after_update)
3165
 
    (*var->after_update)(thd, type);
 
2852
    (*var->after_update)(session, type);
3166
2853
  return 0;
3167
2854
}
3168
2855
 
3171
2858
  Functions to handle SET @user_variable=const_expr
3172
2859
*****************************************************************************/
3173
2860
 
3174
 
int set_var_user::check(THD *thd)
 
2861
int set_var_user::check(Session *session)
3175
2862
{
3176
2863
  /*
3177
2864
    Item_func_set_user_var can't substitute something else on its place =>
3178
2865
    0 can be passed as last argument (reference on item)
3179
2866
  */
3180
 
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
 
2867
  return (user_var_item->fix_fields(session, (Item**) 0) ||
3181
2868
          user_var_item->check(0)) ? -1 : 0;
3182
2869
}
3183
2870
 
3184
2871
 
3185
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
2872
int set_var_user::update(Session *)
3186
2873
{
3187
2874
  if (user_var_item->update())
3188
2875
  {
3199
2886
 
3200
2887
/* Based upon sys_var::check_enum() */
3201
2888
 
3202
 
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
 
2889
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
3203
2890
{
3204
2891
  char buff[STRING_BUFFER_USUAL_SIZE];
3205
2892
  const char *value;
3213
2900
    if (!(res=var->value->val_str(&str)) ||
3214
2901
        !(engine_name.str= (char *)res->ptr()) ||
3215
2902
        !(engine_name.length= res->length()) ||
3216
 
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
3217
 
        !(hton= plugin_data(var->save_result.plugin, handlerton *)) ||
3218
 
        ha_checktype(thd, ha_legacy_type(hton), 1, 0) != hton)
 
2903
        !(var->save_result.plugin= ha_resolve_by_name(session, &engine_name)) ||
 
2904
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
3219
2905
    {
3220
2906
      value= res ? res->c_ptr() : "NULL";
3221
2907
      goto err;
3230
2916
}
3231
2917
 
3232
2918
 
3233
 
uchar *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
3234
 
                                             LEX_STRING *base __attribute__((unused)))
 
2919
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session,
 
2920
                                                         enum_var_type type,
 
2921
                                                         LEX_STRING *)
3235
2922
{
3236
 
  uchar* result;
 
2923
  unsigned char* result;
3237
2924
  handlerton *hton;
3238
2925
  LEX_STRING *engine_name;
3239
 
  plugin_ref plugin= thd->variables.*offset;
 
2926
  plugin_ref plugin= session->variables.*offset;
3240
2927
  if (type == OPT_GLOBAL)
3241
 
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
 
2928
    plugin= my_plugin_lock(session, &(global_system_variables.*offset));
3242
2929
  hton= plugin_data(plugin, handlerton*);
3243
2930
  engine_name= &hton2plugin[hton->slot]->name;
3244
 
  result= (uchar *) thd->strmake(engine_name->str, engine_name->length);
 
2931
  result= (unsigned char *) session->strmake(engine_name->str, engine_name->length);
3245
2932
  if (type == OPT_GLOBAL)
3246
 
    plugin_unlock(thd, plugin);
 
2933
    plugin_unlock(session, plugin);
3247
2934
  return result;
3248
2935
}
3249
2936
 
3250
2937
 
3251
 
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
 
2938
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
3252
2939
{
3253
2940
  plugin_ref old_value, new_value, *value;
3254
2941
  if (type == OPT_GLOBAL)
3258
2945
  }
3259
2946
  else
3260
2947
  {
3261
 
    value= &(thd->variables.*offset);
 
2948
    value= &(session->variables.*offset);
3262
2949
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
3263
2950
  }
3264
2951
  assert(new_value);
3268
2955
}
3269
2956
 
3270
2957
 
3271
 
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
 
2958
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3272
2959
{
3273
2960
  plugin_ref *value= &(global_system_variables.*offset), old_value;
3274
2961
   if (var->type != OPT_GLOBAL)
3275
 
     value= &(thd->variables.*offset);
 
2962
     value= &(session->variables.*offset);
3276
2963
  old_value= *value;
3277
2964
  if (old_value != var->save_result.plugin)
3278
2965
  {
3283
2970
}
3284
2971
 
3285
2972
bool
3286
 
sys_var_thd_optimizer_switch::
3287
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
2973
sys_var_session_optimizer_switch::
 
2974
symbolic_mode_representation(Session *session, uint64_t val, LEX_STRING *rep)
3288
2975
{
3289
2976
  char buff[STRING_BUFFER_USUAL_SIZE*8];
3290
2977
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
3291
2978
 
3292
2979
  tmp.length(0);
3293
2980
 
3294
 
  for (uint i= 0; val; val>>= 1, i++)
 
2981
  for (uint32_t i= 0; val; val>>= 1, i++)
3295
2982
  {
3296
2983
    if (val & 1)
3297
2984
    {
3304
2991
  if (tmp.length())
3305
2992
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
3306
2993
 
3307
 
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
 
2994
  rep->str= session->strmake(tmp.ptr(), tmp.length());
3308
2995
 
3309
2996
  rep->length= rep->str ? tmp.length() : 0;
3310
2997
 
3312
2999
}
3313
3000
 
3314
3001
 
3315
 
uchar *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
3316
 
                                               LEX_STRING *base __attribute__((unused)))
 
3002
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session,
 
3003
                                                           enum_var_type type,
 
3004
                                                           LEX_STRING *)
3317
3005
{
3318
3006
  LEX_STRING opts;
3319
3007
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3320
 
                  thd->variables.*offset);
3321
 
  (void) symbolic_mode_representation(thd, val, &opts);
3322
 
  return (uchar *) opts.str;
 
3008
                  session->variables.*offset);
 
3009
  (void) symbolic_mode_representation(session, val, &opts);
 
3010
  return (unsigned char *) opts.str;
3323
3011
}
3324
3012
 
3325
3013
 
3326
 
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
 
3014
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3327
3015
{
3328
3016
  if (type == OPT_GLOBAL)
3329
3017
    global_system_variables.*offset= 0;
3330
3018
  else
3331
 
    thd->variables.*offset= global_system_variables.*offset;
 
3019
    session->variables.*offset= global_system_variables.*offset;
3332
3020
}
3333
3021
 
3334
3022
 
3336
3024
  Named list handling
3337
3025
****************************************************************************/
3338
3026
 
3339
 
uchar* find_named(I_List<NAMED_LIST> *list, const char *name, uint length,
 
3027
unsigned char* find_named(I_List<NAMED_LIST> *list, const char *name, uint32_t length,
3340
3028
                NAMED_LIST **found)
3341
3029
{
3342
3030
  I_List_iterator<NAMED_LIST> it(*list);
3355
3043
 
3356
3044
 
3357
3045
void delete_elements(I_List<NAMED_LIST> *list,
3358
 
                     void (*free_element)(const char *name, uchar*))
 
3046
                     void (*free_element)(const char *name, unsigned char*))
3359
3047
{
3360
3048
  NAMED_LIST *element;
3361
3049
  while ((element= list->get()))
3369
3057
 
3370
3058
/* Key cache functions */
3371
3059
 
3372
 
static KEY_CACHE *create_key_cache(const char *name, uint length)
 
3060
static KEY_CACHE *create_key_cache(const char *name, uint32_t length)
3373
3061
{
3374
3062
  KEY_CACHE *key_cache;
3375
3063
  
3376
3064
  if ((key_cache= (KEY_CACHE*) my_malloc(sizeof(KEY_CACHE),
3377
3065
                                             MYF(MY_ZEROFILL | MY_WME))))
3378
3066
  {
3379
 
    if (!new NAMED_LIST(&key_caches, name, length, (uchar*) key_cache))
 
3067
    if (!new NAMED_LIST(&key_caches, name, length, (unsigned char*) key_cache))
3380
3068
    {
3381
 
      my_free((char*) key_cache, MYF(0));
 
3069
      free((char*) key_cache);
3382
3070
      key_cache= 0;
3383
3071
    }
3384
3072
    else
3398
3086
}
3399
3087
 
3400
3088
 
3401
 
KEY_CACHE *get_or_create_key_cache(const char *name, uint length)
 
3089
KEY_CACHE *get_or_create_key_cache(const char *name, uint32_t length)
3402
3090
{
3403
3091
  LEX_STRING key_cache_name;
3404
3092
  KEY_CACHE *key_cache;
3413
3101
}
3414
3102
 
3415
3103
 
3416
 
void free_key_cache(const char *name __attribute__((unused)),
3417
 
                    KEY_CACHE *key_cache)
 
3104
void free_key_cache(const char *, KEY_CACHE *key_cache)
3418
3105
{
3419
3106
  ha_end_key_cache(key_cache);
3420
 
  my_free((char*) key_cache, MYF(0));
 
3107
  free((char*) key_cache);
3421
3108
}
3422
3109
 
3423
3110
 
3435
3122
}
3436
3123
 
3437
3124
 
3438
 
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
 
3125
bool sys_var_opt_readonly::update(Session *session, set_var *var)
3439
3126
{
3440
3127
  bool result;
3441
3128
 
3442
3129
  /* Prevent self dead-lock */
3443
 
  if (thd->locked_tables || thd->active_transaction())
 
3130
  if (session->locked_tables || session->active_transaction())
3444
3131
  {
3445
3132
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3446
3133
    return(true);
3447
3134
  }
3448
3135
 
3449
 
  if (thd->global_read_lock)
 
3136
  if (session->global_read_lock)
3450
3137
  {
3451
3138
    /*
3452
3139
      This connection already holds the global read lock.
3454
3141
      - FLUSH TABLES WITH READ LOCK
3455
3142
      - SET GLOBAL READ_ONLY = 1
3456
3143
    */
3457
 
    result= sys_var_bool_ptr::update(thd, var);
 
3144
    result= sys_var_bool_ptr::update(session, var);
3458
3145
    return(result);
3459
3146
  }
3460
3147
 
3469
3156
    [3] prevents transactions from being committed.
3470
3157
  */
3471
3158
 
3472
 
  if (lock_global_read_lock(thd))
 
3159
  if (lock_global_read_lock(session))
3473
3160
    return(true);
3474
3161
 
3475
3162
  /*
3481
3168
    can cause to wait on a read lock, it's required for the client application
3482
3169
    to unlock everything, and acceptable for the server to wait on all locks.
3483
3170
  */
3484
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3171
  if ((result= close_cached_tables(session, NULL, false, true, true)) == true)
3485
3172
    goto end_with_read_lock;
3486
3173
 
3487
 
  if ((result= make_global_read_lock_block_commit(thd)) == true)
 
3174
  if ((result= make_global_read_lock_block_commit(session)) == true)
3488
3175
    goto end_with_read_lock;
3489
3176
 
3490
3177
  /* Change the opt_readonly system variable, safe because the lock is held */
3491
 
  result= sys_var_bool_ptr::update(thd, var);
 
3178
  result= sys_var_bool_ptr::update(session, var);
3492
3179
 
3493
3180
end_with_read_lock:
3494
3181
  /* Release the lock */
3495
 
  unlock_global_read_lock(thd);
 
3182
  unlock_global_read_lock(session);
3496
3183
  return(result);
3497
3184
}
3498
3185