~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

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