~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

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