~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Monty Taylor
  • Date: 2008-10-22 21:31:15 UTC
  • Revision ID: monty@inaugust.com-20081022213115-xuxc80r939tl88p1
Renamed drizzle_common again. Removed sql_common. (empty) 
Now all we need to do is merge/disect base.h, common.h, common_includes.h, server_includes.h and globa.h (good grief)

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#include <mysys/thr_alarm.h>
53
53
#include <storage/myisam/myisam.h>
54
54
#include <drizzled/drizzled_error_messages.h>
55
 
#include <libdrizzle/gettext.h>
 
55
#include <drizzled/gettext.h>
56
56
 
57
57
extern const CHARSET_INFO *character_set_filesystem;
58
58
 
83
83
  slave_exec_mode_names, (unsigned int *) slave_exec_mode_names_len
84
84
};
85
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,
 
86
static bool sys_update_init_connect(Session*, set_var*);
 
87
static void sys_default_init_connect(Session*, enum_var_type type);
 
88
static bool sys_update_init_slave(Session*, set_var*);
 
89
static void sys_default_init_slave(Session*, enum_var_type type);
 
90
static bool set_option_bit(Session *session, set_var *var);
 
91
static bool set_option_autocommit(Session *session, set_var *var);
 
92
static int  check_log_update(Session *session, set_var *var);
 
93
static int  check_pseudo_thread_id(Session *session, set_var *var);
 
94
static void fix_low_priority_updates(Session *session, enum_var_type type);
 
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_myisam_max_sort_file_size(Session *session, enum_var_type type);
 
104
static void fix_max_binlog_size(Session *session, enum_var_type type);
 
105
static void fix_max_relay_log_size(Session *session, enum_var_type type);
 
106
static void fix_max_connections(Session *session, enum_var_type type);
 
107
static void fix_session_mem_root(Session *session, enum_var_type type);
 
108
static void fix_trans_mem_root(Session *session, enum_var_type type);
 
109
static void fix_server_id(Session *session, enum_var_type type);
 
110
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
 
111
static bool get_unsigned(Session *session, set_var *var);
 
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
113
113
                          const char *name, int64_t val);
114
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
 
static unsigned char *get_error_count(THD *thd);
116
 
static unsigned char *get_warning_count(THD *thd);
117
 
static unsigned char *get_tmpdir(THD *thd);
 
115
static unsigned char *get_error_count(Session *session);
 
116
static unsigned char *get_warning_count(Session *session);
 
117
static unsigned char *get_tmpdir(Session *session);
118
118
 
119
119
/*
120
120
  Variable definition list
128
128
 
129
129
static sys_var_chain vars = { NULL, NULL };
130
130
 
131
 
static sys_var_thd_ulong
 
131
static sys_var_session_ulong
132
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
133
                             &SV::auto_increment_increment, NULL, NULL,
134
134
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
135
 
static sys_var_thd_ulong
 
135
static sys_var_session_ulong
136
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
137
137
                          &SV::auto_increment_offset, NULL, NULL,
138
138
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
140
140
static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
141
141
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
142
142
                                              &binlog_cache_size);
143
 
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
 
143
static sys_var_session_binlog_format sys_binlog_format(&vars, "binlog_format",
144
144
                                            &SV::binlog_format);
145
 
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
145
static sys_var_session_ulong    sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
146
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",
 
147
static sys_var_session_ulong    sys_completion_type(&vars, "completion_type",
173
148
                                         &SV::completion_type,
174
149
                                         check_completion_type,
175
150
                                         fix_completion_type);
202
177
sys_var_str             sys_init_slave(&vars, "init_slave", 0,
203
178
                                       sys_update_init_slave,
204
179
                                       sys_default_init_slave,0);
205
 
static sys_var_thd_ulong        sys_interactive_timeout(&vars, "interactive_timeout",
 
180
static sys_var_session_ulong    sys_interactive_timeout(&vars, "interactive_timeout",
206
181
                                                &SV::net_interactive_timeout);
207
 
static sys_var_thd_ulong        sys_join_buffer_size(&vars, "join_buffer_size",
 
182
static sys_var_session_ulong    sys_join_buffer_size(&vars, "join_buffer_size",
208
183
                                             &SV::join_buff_size);
209
184
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
210
185
static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
218
193
                                                              param_age_threshold));
219
194
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
220
195
                                         &opt_local_infile);
221
 
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
 
196
static sys_var_session_bool     sys_low_priority_updates(&vars, "low_priority_updates",
222
197
                                                 &SV::low_priority_updates,
223
198
                                                 fix_low_priority_updates);
224
199
#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",
 
200
static sys_var_session_bool     sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
226
201
                                                     &SV::low_priority_updates,
227
202
                                                     fix_low_priority_updates);
228
203
#endif
229
 
static sys_var_thd_ulong        sys_max_allowed_packet(&vars, "max_allowed_packet",
 
204
static sys_var_session_ulong    sys_max_allowed_packet(&vars, "max_allowed_packet",
230
205
                                               &SV::max_allowed_packet);
231
206
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
232
207
                                                  &max_binlog_cache_size);
238
213
                                            fix_max_connections);
239
214
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
240
215
                                               &max_connect_errors);
241
 
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
 
216
static sys_var_session_ulong    sys_max_error_count(&vars, "max_error_count",
242
217
                                            &SV::max_error_count);
243
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
 
218
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
244
219
                                                &SV::max_heap_table_size);
245
 
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 
220
static sys_var_session_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
246
221
                                              &SV::pseudo_thread_id,
247
222
                                              check_pseudo_thread_id, 0,
248
223
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
249
 
static sys_var_thd_ha_rows      sys_max_join_size(&vars, "max_join_size",
 
224
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
250
225
                                          &SV::max_join_size,
251
226
                                          fix_max_join_size);
252
 
static sys_var_thd_ulong        sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
227
static sys_var_session_ulong    sys_max_seeks_for_key(&vars, "max_seeks_for_key",
253
228
                                              &SV::max_seeks_for_key);
254
 
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
229
static sys_var_session_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
255
230
                                                 &SV::max_length_for_sort_data);
256
231
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
257
232
                                               &max_relay_log_size,
258
233
                                               fix_max_relay_log_size);
259
 
static sys_var_thd_ulong        sys_max_sort_length(&vars, "max_sort_length",
 
234
static sys_var_session_ulong    sys_max_sort_length(&vars, "max_sort_length",
260
235
                                            &SV::max_sort_length);
261
236
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",
 
237
static sys_var_session_ulong    sys_max_tmp_tables(&vars, "max_tmp_tables",
263
238
                                           &SV::max_tmp_tables);
264
239
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
265
240
                                                 &max_write_lock_count);
266
 
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
241
static sys_var_session_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
267
242
                                                          &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);
 
243
static sys_var_session_uint64_t sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
 
244
static sys_var_session_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
 
245
static sys_var_session_ulong    sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
271
246
 
272
 
static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
247
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
273
248
                                                &SV::myisam_stats_method,
274
249
                                                &myisam_stats_method_typelib,
275
250
                                                NULL);
276
 
static sys_var_thd_ulong        sys_net_buffer_length(&vars, "net_buffer_length",
 
251
static sys_var_session_ulong    sys_net_buffer_length(&vars, "net_buffer_length",
277
252
                                              &SV::net_buffer_length);
278
 
static sys_var_thd_ulong        sys_net_read_timeout(&vars, "net_read_timeout",
 
253
static sys_var_session_ulong    sys_net_read_timeout(&vars, "net_read_timeout",
279
254
                                             &SV::net_read_timeout,
280
255
                                             0, fix_net_read_timeout);
281
 
static sys_var_thd_ulong        sys_net_write_timeout(&vars, "net_write_timeout",
 
256
static sys_var_session_ulong    sys_net_write_timeout(&vars, "net_write_timeout",
282
257
                                              &SV::net_write_timeout,
283
258
                                              0, fix_net_write_timeout);
284
 
static sys_var_thd_ulong        sys_net_retry_count(&vars, "net_retry_count",
 
259
static sys_var_session_ulong    sys_net_retry_count(&vars, "net_retry_count",
285
260
                                            &SV::net_retry_count,
286
261
                                            0, fix_net_retry_count);
287
 
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
 
262
static sys_var_session_bool     sys_new_mode(&vars, "new", &SV::new_mode);
288
263
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
289
264
                                       &global_system_variables.old_mode);
290
265
/* these two cannot be static */
291
 
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
 
266
sys_var_session_bool                sys_old_alter_table(&vars, "old_alter_table",
292
267
                                            &SV::old_alter_table);
293
 
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
268
static sys_var_session_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
294
269
                                                  &SV::optimizer_prune_level);
295
 
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
270
static sys_var_session_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
296
271
                                                   &SV::optimizer_search_depth);
297
272
 
298
273
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
301
276
  optimizer_use_mrr_names, NULL
302
277
};
303
278
 
304
 
static sys_var_thd_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
279
static sys_var_session_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
305
280
                                              &SV::optimizer_use_mrr,
306
281
                                              &optimizer_use_mrr_typelib,
307
282
                                              NULL);
308
283
 
309
 
static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
 
284
static sys_var_session_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
310
285
                                              &SV::preload_buff_size);
311
 
static sys_var_thd_ulong        sys_read_buff_size(&vars, "read_buffer_size",
 
286
static sys_var_session_ulong    sys_read_buff_size(&vars, "read_buffer_size",
312
287
                                           &SV::read_buff_size);
313
288
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",
 
289
static sys_var_session_ulong    sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
315
290
                                               &SV::read_rnd_buff_size);
316
 
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
 
291
static sys_var_session_ulong    sys_div_precincrement(&vars, "div_precision_increment",
317
292
                                              &SV::div_precincrement);
318
 
static sys_var_long_ptr sys_rpl_recovery_rank(&vars, "rpl_recovery_rank",
319
 
                                              &rpl_recovery_rank);
320
293
 
321
 
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
294
static sys_var_session_ulong    sys_range_alloc_block_size(&vars, "range_alloc_block_size",
322
295
                                                   &SV::range_alloc_block_size);
323
 
static sys_var_thd_ulong        sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
296
static sys_var_session_ulong    sys_query_alloc_block_size(&vars, "query_alloc_block_size",
324
297
                                                   &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",
 
298
                                                   0, fix_session_mem_root);
 
299
static sys_var_session_ulong    sys_query_prealloc_size(&vars, "query_prealloc_size",
327
300
                                                &SV::query_prealloc_size,
328
 
                                                0, fix_thd_mem_root);
 
301
                                                0, fix_session_mem_root);
329
302
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",
 
303
static sys_var_session_ulong    sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
331
304
                                                   &SV::trans_alloc_block_size,
332
305
                                                   0, fix_trans_mem_root);
333
 
static sys_var_thd_ulong        sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
306
static sys_var_session_ulong    sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
334
307
                                                &SV::trans_prealloc_size,
335
308
                                                0, fix_trans_mem_root);
336
309
 
337
 
static sys_var_bool_ptr sys_secure_auth(&vars, "secure_auth", &opt_secure_auth);
338
310
static sys_var_const_str_ptr sys_secure_file_priv(&vars, "secure_file_priv",
339
311
                                             &opt_secure_file_priv);
340
312
static sys_var_long_ptr sys_server_id(&vars, "server_id", &server_id, fix_server_id);
349
321
                                              0);
350
322
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
351
323
                                             &slow_launch_time);
352
 
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
 
324
static sys_var_session_ulong    sys_sort_buffer(&vars, "sort_buffer_size",
353
325
                                        &SV::sortbuff_size);
354
326
/*
355
327
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
357
329
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
358
330
  master's (see log_event.cc: Query_log_event::do_apply_event()).
359
331
*/
360
 
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
332
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
361
333
                                     &SV::optimizer_switch);
362
334
 
363
 
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
 
335
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
364
336
                                       &SV::table_plugin);
365
337
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
366
338
                                             system_time_zone);
374
346
                                              &thread_cache_size);
375
347
sys_var_long_ptr        sys_thread_pool_size(&vars, "thread_pool_size",
376
348
                                              &thread_pool_size);
377
 
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
 
349
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
378
350
                                         &SV::tx_isolation,
379
351
                                         &tx_isolation_typelib,
380
352
                                         fix_tx_isolation,
381
353
                                         check_tx_isolation);
382
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
354
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
383
355
                                           &SV::tmp_table_size);
384
356
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
385
357
static sys_var_const_str        sys_version(&vars, "version", server_version);
389
361
                                                    MACHINE_TYPE);
390
362
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
391
363
                                               SYSTEM_TYPE);
392
 
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
 
364
static sys_var_session_ulong    sys_net_wait_timeout(&vars, "wait_timeout",
393
365
                                             &SV::net_wait_timeout);
394
366
 
395
367
/* Condition pushdown to storage engine */
396
 
static sys_var_thd_bool
 
368
static sys_var_session_bool
397
369
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
398
370
                              &SV::engine_condition_pushdown);
399
371
 
400
372
/* Time/date/datetime formats */
401
373
 
402
 
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
 
374
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
403
375
                                             &SV::time_format,
404
376
                                             DRIZZLE_TIMESTAMP_TIME);
405
 
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
 
377
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
406
378
                                             &SV::date_format,
407
379
                                             DRIZZLE_TIMESTAMP_DATE);
408
 
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
 
380
static sys_var_session_date_time_format sys_datetime_format(&vars, "datetime_format",
409
381
                                                 &SV::datetime_format,
410
382
                                                 DRIZZLE_TIMESTAMP_DATETIME);
411
383
 
412
 
/* Variables that are bits in THD */
 
384
/* Variables that are bits in Session */
413
385
 
414
 
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
 
386
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
415
387
                               set_option_autocommit,
416
388
                               OPTION_NOT_AUTOCOMMIT,
417
389
                               1);
418
 
static sys_var_thd_bit  sys_big_tables(&vars, "big_tables", 0,
419
 
                                       set_option_bit,
420
 
                                       OPTION_BIG_TABLES);
421
 
#ifndef TO_BE_DELETED   /* Alias for big_tables */
422
 
static sys_var_thd_bit  sys_sql_big_tables(&vars, "sql_big_tables", 0,
423
 
                                           set_option_bit,
424
 
                                           OPTION_BIG_TABLES);
425
 
#endif
426
 
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
 
390
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
427
391
                                        set_option_bit,
428
392
                                        OPTION_BIG_SELECTS);
429
 
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
 
393
static sys_var_session_bit      sys_log_binlog(&vars, "sql_log_bin",
430
394
                                       check_log_update,
431
395
                                       set_option_bit,
432
396
                                       OPTION_BIN_LOG);
433
 
static sys_var_thd_bit  sys_sql_warnings(&vars, "sql_warnings", 0,
 
397
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
434
398
                                         set_option_bit,
435
399
                                         OPTION_WARNINGS);
436
 
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
 
400
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
437
401
                                         set_option_bit,
438
402
                                         OPTION_SQL_NOTES);
439
 
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
 
403
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
440
404
                                         set_option_bit,
441
405
                                         OPTION_SAFE_UPDATES);
442
 
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
 
406
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
443
407
                                           set_option_bit,
444
408
                                           OPTION_BUFFER_RESULT);
445
 
static sys_var_thd_bit  sys_quote_show_create(&vars, "sql_quote_show_create", 0,
 
409
static sys_var_session_bit      sys_quote_show_create(&vars, "sql_quote_show_create", 0,
446
410
                                              set_option_bit,
447
411
                                              OPTION_QUOTE_SHOW_CREATE);
448
 
static sys_var_thd_bit  sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
412
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
449
413
                                               set_option_bit,
450
414
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
451
415
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
452
 
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
 
416
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
453
417
                                          set_option_bit,
454
418
                                          OPTION_RELAXED_UNIQUE_CHECKS,
455
419
                                          1,
456
420
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
457
421
/* Local state variables */
458
422
 
459
 
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
 
423
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
460
424
                                                 &SV::select_limit);
461
425
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
462
426
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
470
434
static sys_var_last_insert_id
471
435
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
472
436
 
473
 
static sys_var_thd_lc_time_names
 
437
static sys_var_session_lc_time_names
474
438
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
475
439
 
476
440
/*
507
471
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
508
472
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
509
473
 
510
 
static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
 
474
static sys_var_session_ulong        sys_default_week_format(&vars, "default_week_format",
511
475
                                                        &SV::default_week_format);
512
476
 
513
 
sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
 
477
sys_var_session_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
514
478
                                                         &SV::group_concat_max_len);
515
479
 
516
 
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
 
480
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
517
481
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
518
482
 
519
483
/* Global read-only variable containing hostname */
523
487
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
524
488
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
525
489
 
526
 
static unsigned char *slave_get_report_port(THD *thd)
 
490
static unsigned char *slave_get_report_port(Session *session)
527
491
{
528
 
  thd->sys_var_tmp.long_value= report_port;
529
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
492
  session->sys_var_tmp.long_value= report_port;
 
493
  return (unsigned char*) &session->sys_var_tmp.long_value;
530
494
}
531
495
 
532
496
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
533
497
 
534
 
sys_var_thd_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
 
498
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
535
499
                                           &SV::keep_files_on_create);
536
500
/* Read only variables */
537
501
 
564
528
};
565
529
 
566
530
 
567
 
bool sys_var::check(THD *thd __attribute__((unused)), set_var *var)
 
531
bool sys_var::check(Session *session __attribute__((unused)), set_var *var)
568
532
{
569
533
  var->save_result.uint64_t_value= var->value->val_int();
570
534
  return 0;
571
535
}
572
536
 
573
 
bool sys_var_str::check(THD *thd, set_var *var)
 
537
bool sys_var_str::check(Session *session, set_var *var)
574
538
{
575
539
  int res;
576
540
  if (!check_func)
577
541
    return 0;
578
542
 
579
 
  if ((res=(*check_func)(thd, var)) < 0)
 
543
  if ((res=(*check_func)(session, var)) < 0)
580
544
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
581
545
             name, var->value->str_value.ptr());
582
546
  return res;
618
582
}
619
583
 
620
584
 
621
 
static bool sys_update_init_connect(THD *thd __attribute__((unused)), set_var *var)
 
585
static bool sys_update_init_connect(Session *session __attribute__((unused)), set_var *var)
622
586
{
623
587
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
624
588
}
625
589
 
626
590
 
627
 
static void sys_default_init_connect(THD* thd __attribute__((unused)),
 
591
static void sys_default_init_connect(Session* session __attribute__((unused)),
628
592
                                     enum_var_type type __attribute__((unused)))
629
593
{
630
594
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
631
595
}
632
596
 
633
597
 
634
 
static bool sys_update_init_slave(THD *thd __attribute__((unused)),
 
598
static bool sys_update_init_slave(Session *session __attribute__((unused)),
635
599
                                  set_var *var)
636
600
{
637
601
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
638
602
}
639
603
 
640
604
 
641
 
static void sys_default_init_slave(THD* thd __attribute__((unused)),
 
605
static void sys_default_init_slave(Session* session __attribute__((unused)),
642
606
                                   enum_var_type type __attribute__((unused)))
643
607
{
644
608
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
650
614
  used lock type.
651
615
*/
652
616
 
653
 
static void fix_low_priority_updates(THD *thd, enum_var_type type)
 
617
static void fix_low_priority_updates(Session *session, enum_var_type type)
654
618
{
655
619
  if (type == OPT_GLOBAL)
656
620
    thr_upgraded_concurrent_insert_lock= 
657
621
      (global_system_variables.low_priority_updates ?
658
622
       TL_WRITE_LOW_PRIORITY : TL_WRITE);
659
623
  else
660
 
    thd->update_lock_default= (thd->variables.low_priority_updates ?
 
624
    session->update_lock_default= (session->variables.low_priority_updates ?
661
625
                               TL_WRITE_LOW_PRIORITY : TL_WRITE);
662
626
}
663
627
 
664
628
 
665
629
static void
666
 
fix_myisam_max_sort_file_size(THD *thd __attribute__((unused)),
 
630
fix_myisam_max_sort_file_size(Session *session __attribute__((unused)),
667
631
                              enum_var_type type __attribute__((unused)))
668
632
{
669
633
  myisam_max_temp_length=
674
638
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
675
639
*/
676
640
 
677
 
static void fix_max_join_size(THD *thd, enum_var_type type)
 
641
static void fix_max_join_size(Session *session, enum_var_type type)
678
642
{
679
643
  if (type != OPT_GLOBAL)
680
644
  {
681
 
    if (thd->variables.max_join_size == HA_POS_ERROR)
682
 
      thd->options|= OPTION_BIG_SELECTS;
 
645
    if (session->variables.max_join_size == HA_POS_ERROR)
 
646
      session->options|= OPTION_BIG_SELECTS;
683
647
    else
684
 
      thd->options&= ~OPTION_BIG_SELECTS;
 
648
      session->options&= ~OPTION_BIG_SELECTS;
685
649
  }
686
650
}
687
651
 
690
654
  Can't change the 'next' tx_isolation while we are already in
691
655
  a transaction
692
656
*/
693
 
static int check_tx_isolation(THD *thd, set_var *var)
 
657
static int check_tx_isolation(Session *session, set_var *var)
694
658
{
695
 
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
 
659
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
696
660
  {
697
661
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
698
662
    return 1;
704
668
  If one doesn't use the SESSION modifier, the isolation level
705
669
  is only active for the next command.
706
670
*/
707
 
static void fix_tx_isolation(THD *thd, enum_var_type type)
 
671
static void fix_tx_isolation(Session *session, enum_var_type type)
708
672
{
709
673
  if (type == OPT_SESSION)
710
 
    thd->session_tx_isolation= ((enum_tx_isolation)
711
 
                                thd->variables.tx_isolation);
 
674
    session->session_tx_isolation= ((enum_tx_isolation)
 
675
                                session->variables.tx_isolation);
712
676
}
713
677
 
714
 
static void fix_completion_type(THD *thd __attribute__((unused)),
 
678
static void fix_completion_type(Session *session __attribute__((unused)),
715
679
                                enum_var_type type __attribute__((unused))) {}
716
680
 
717
 
static int check_completion_type(THD *thd __attribute__((unused)),
 
681
static int check_completion_type(Session *session __attribute__((unused)),
718
682
                                 set_var *var)
719
683
{
720
684
  int64_t val= var->value->val_int();
732
696
  If we are changing the thread variable, we have to copy it to NET too
733
697
*/
734
698
 
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)),
 
699
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
700
{
 
701
  if (type != OPT_GLOBAL)
 
702
    my_net_set_read_timeout(&session->net, session->variables.net_read_timeout);
 
703
}
 
704
 
 
705
 
 
706
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
707
{
 
708
  if (type != OPT_GLOBAL)
 
709
    my_net_set_write_timeout(&session->net, session->variables.net_write_timeout);
 
710
}
 
711
 
 
712
static void fix_net_retry_count(Session *session, enum_var_type type)
 
713
{
 
714
  if (type != OPT_GLOBAL)
 
715
    session->net.retry_count=session->variables.net_retry_count;
 
716
}
 
717
 
 
718
 
 
719
extern void fix_delay_key_write(Session *session __attribute__((unused)),
756
720
                                enum_var_type type __attribute__((unused)))
757
721
{
758
722
  switch ((enum_delay_key_write) delay_key_write_options) {
769
733
  }
770
734
}
771
735
 
772
 
bool sys_var_set::update(THD *thd __attribute__((unused)),
 
736
bool sys_var_set::update(Session *session __attribute__((unused)),
773
737
                         set_var *var)
774
738
{
775
739
  *value= var->save_result.ulong_value;
776
740
  return 0;
777
741
}
778
742
 
779
 
unsigned char *sys_var_set::value_ptr(THD *thd,
 
743
unsigned char *sys_var_set::value_ptr(Session *session,
780
744
                              enum_var_type type __attribute__((unused)),
781
745
                              LEX_STRING *base __attribute__((unused)))
782
746
{
798
762
 
799
763
  if ((length= tmp.length()))
800
764
    length--;
801
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
765
  return (unsigned char*) session->strmake(tmp.ptr(), length);
802
766
}
803
767
 
804
 
void sys_var_set_slave_mode::set_default(THD *thd __attribute__((unused)),
 
768
void sys_var_set_slave_mode::set_default(Session *session __attribute__((unused)),
805
769
                                         enum_var_type type __attribute__((unused)))
806
770
{
807
771
  slave_exec_mode_options= 0;
808
772
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
809
773
}
810
774
 
811
 
bool sys_var_set_slave_mode::check(THD *thd, set_var *var)
 
775
bool sys_var_set_slave_mode::check(Session *session, set_var *var)
812
776
{
813
 
  bool rc=  sys_var_set::check(thd, var);
 
777
  bool rc=  sys_var_set::check(session, var);
814
778
  if (!rc &&
815
779
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
816
780
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
821
785
  return rc;
822
786
}
823
787
 
824
 
bool sys_var_set_slave_mode::update(THD *thd, set_var *var)
 
788
bool sys_var_set_slave_mode::update(Session *session, set_var *var)
825
789
{
826
790
  bool rc;
827
791
  pthread_mutex_lock(&LOCK_global_system_variables);
828
 
  rc= sys_var_set::update(thd, var);
 
792
  rc= sys_var_set::update(session, var);
829
793
  pthread_mutex_unlock(&LOCK_global_system_variables);
830
794
  return rc;
831
795
}
843
807
    bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
844
808
}
845
809
 
846
 
bool sys_var_thd_binlog_format::is_readonly() const
 
810
bool sys_var_session_binlog_format::is_readonly() const
847
811
{
848
812
  /*
849
813
    Under certain circumstances, the variable is read-only (unchangeable):
850
814
  */
851
 
  THD *thd= current_thd;
 
815
  Session *session= current_session;
852
816
  /*
853
817
    If RBR and open temporary tables, their CREATE TABLE may not be in the
854
818
    binlog, so we can't toggle to SBR in this connection.
860
824
    If we don't have row-based replication compiled in, the variable
861
825
    is always read-only.
862
826
  */
863
 
  if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
864
 
      thd->temporary_tables)
 
827
  if ((session->variables.binlog_format == BINLOG_FORMAT_ROW) &&
 
828
      session->temporary_tables)
865
829
  {
866
830
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
867
831
    return 1;
868
832
  }
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();
 
833
  
 
834
  return sys_var_session_enum::is_readonly();
878
835
}
879
836
 
880
837
 
881
 
void fix_binlog_format_after_update(THD *thd,
 
838
void fix_binlog_format_after_update(Session *session,
882
839
                                    enum_var_type type __attribute__((unused)))
883
840
{
884
 
  thd->reset_current_stmt_binlog_row_based();
 
841
  session->reset_current_stmt_binlog_row_based();
885
842
}
886
843
 
887
844
 
888
 
static void fix_max_binlog_size(THD *thd __attribute__((unused)),
 
845
static void fix_max_binlog_size(Session *session __attribute__((unused)),
889
846
                                enum_var_type type __attribute__((unused)))
890
847
{
891
848
  mysql_bin_log.set_max_size(max_binlog_size);
894
851
  return;
895
852
}
896
853
 
897
 
static void fix_max_relay_log_size(THD *thd __attribute__((unused)),
 
854
static void fix_max_relay_log_size(Session *session __attribute__((unused)),
898
855
                                   enum_var_type type __attribute__((unused)))
899
856
{
900
857
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
902
859
  return;
903
860
}
904
861
 
905
 
static void fix_max_connections(THD *thd __attribute__((unused)),
 
862
static void fix_max_connections(Session *session __attribute__((unused)),
906
863
                                enum_var_type type __attribute__((unused)))
907
864
{
908
865
  resize_thr_alarm(max_connections +  10);
909
866
}
910
867
 
911
868
 
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)),
 
869
static void fix_session_mem_root(Session *session, enum_var_type type)
 
870
{
 
871
  if (type != OPT_GLOBAL)
 
872
    reset_root_defaults(session->mem_root,
 
873
                        session->variables.query_alloc_block_size,
 
874
                        session->variables.query_prealloc_size);
 
875
}
 
876
 
 
877
 
 
878
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
879
{
 
880
  if (type != OPT_GLOBAL)
 
881
    reset_root_defaults(&session->transaction.mem_root,
 
882
                        session->variables.trans_alloc_block_size,
 
883
                        session->variables.trans_prealloc_size);
 
884
}
 
885
 
 
886
 
 
887
static void fix_server_id(Session *session __attribute__((unused)),
931
888
                          enum_var_type type __attribute__((unused)))
932
889
{
933
890
  server_id_supplied = 1;
934
 
  thd->server_id= server_id;
 
891
  session->server_id= server_id;
935
892
}
936
893
 
937
894
 
938
 
bool throw_bounds_warning(THD *thd, bool fixed, bool unsignd,
 
895
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
939
896
                          const char *name, int64_t val)
940
897
{
941
898
  if (fixed)
947
904
    else
948
905
      llstr(val, buf);
949
906
 
950
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
907
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
951
908
                        ER_TRUNCATED_WRONG_VALUE,
952
909
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
953
910
  }
954
911
  return false;
955
912
}
956
913
 
957
 
static uint64_t fix_unsigned(THD *thd, uint64_t num,
 
914
static uint64_t fix_unsigned(Session *session, uint64_t num,
958
915
                              const struct my_option *option_limits)
959
916
{
960
917
  bool fixed= false;
961
918
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
962
919
 
963
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
 
920
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
964
921
  return out;
965
922
}
966
923
 
967
 
static bool get_unsigned(THD *thd __attribute__((unused)), set_var *var)
 
924
static bool get_unsigned(Session *session __attribute__((unused)), set_var *var)
968
925
{
969
926
  if (var->value->unsigned_flag)
970
927
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
985
942
{}
986
943
 
987
944
 
988
 
bool sys_var_long_ptr_global::check(THD *thd, set_var *var)
 
945
bool sys_var_long_ptr_global::check(Session *session, set_var *var)
989
946
{
990
 
  return get_unsigned(thd, var);
 
947
  return get_unsigned(session, var);
991
948
}
992
949
 
993
 
bool sys_var_long_ptr_global::update(THD *thd, set_var *var)
 
950
bool sys_var_long_ptr_global::update(Session *session, set_var *var)
994
951
{
995
952
  uint64_t tmp= var->save_result.uint64_t_value;
996
953
  pthread_mutex_lock(guard);
997
954
  if (option_limits)
998
 
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
 
955
    *value= (ulong) fix_unsigned(session, tmp, option_limits);
999
956
  else
1000
957
  {
1001
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1002
 
    /* Avoid overflows on 32 bit systems */
1003
 
    if (tmp > ULONG_MAX)
 
958
    if (tmp > UINT32_MAX)
1004
959
    {
1005
 
      tmp= ULONG_MAX;
1006
 
      throw_bounds_warning(thd, true, true, name,
 
960
      tmp= UINT32_MAX;
 
961
      throw_bounds_warning(session, true, true, name,
1007
962
                           (int64_t) var->save_result.uint64_t_value);
1008
963
    }
1009
 
#endif
1010
964
    *value= (ulong) tmp;
1011
965
  }
1012
966
 
1015
969
}
1016
970
 
1017
971
 
1018
 
void sys_var_long_ptr_global::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
972
void sys_var_long_ptr_global::set_default(Session *session __attribute__((unused)), enum_var_type type __attribute__((unused)))
1019
973
{
1020
974
  bool not_used;
1021
975
  pthread_mutex_lock(guard);
1025
979
}
1026
980
 
1027
981
 
1028
 
bool sys_var_uint64_t_ptr::update(THD *thd, set_var *var)
 
982
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
1029
983
{
1030
984
  uint64_t tmp= var->save_result.uint64_t_value;
1031
985
  pthread_mutex_lock(&LOCK_global_system_variables);
1032
986
  if (option_limits)
1033
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
987
    *value= (uint64_t) fix_unsigned(session, tmp, option_limits);
1034
988
  else
1035
989
    *value= (uint64_t) tmp;
1036
990
  pthread_mutex_unlock(&LOCK_global_system_variables);
1038
992
}
1039
993
 
1040
994
 
1041
 
void sys_var_uint64_t_ptr::set_default(THD *thd __attribute__((unused)),
 
995
void sys_var_uint64_t_ptr::set_default(Session *session __attribute__((unused)),
1042
996
                                        enum_var_type type __attribute__((unused)))
1043
997
{
1044
998
  bool not_used;
1049
1003
}
1050
1004
 
1051
1005
 
1052
 
bool sys_var_bool_ptr::update(THD *thd __attribute__((unused)), set_var *var)
 
1006
bool sys_var_bool_ptr::update(Session *session __attribute__((unused)), set_var *var)
1053
1007
{
1054
1008
  *value= (bool) var->save_result.ulong_value;
1055
1009
  return 0;
1056
1010
}
1057
1011
 
1058
1012
 
1059
 
void sys_var_bool_ptr::set_default(THD *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1013
void sys_var_bool_ptr::set_default(Session *session __attribute__((unused)), enum_var_type type __attribute__((unused)))
1060
1014
{
1061
1015
  *value= (bool) option_limits->def_value;
1062
1016
}
1063
1017
 
1064
1018
 
1065
 
bool sys_var_enum::update(THD *thd __attribute__((unused)), set_var *var)
 
1019
bool sys_var_enum::update(Session *session __attribute__((unused)), set_var *var)
1066
1020
{
1067
1021
  *value= (uint) var->save_result.ulong_value;
1068
1022
  return 0;
1069
1023
}
1070
1024
 
1071
1025
 
1072
 
unsigned char *sys_var_enum::value_ptr(THD *thd __attribute__((unused)),
 
1026
unsigned char *sys_var_enum::value_ptr(Session *session __attribute__((unused)),
1073
1027
                               enum_var_type type __attribute__((unused)),
1074
1028
                               LEX_STRING *base __attribute__((unused)))
1075
1029
{
1077
1031
}
1078
1032
 
1079
1033
 
1080
 
unsigned char *sys_var_enum_const::value_ptr(THD *thd __attribute__((unused)),
 
1034
unsigned char *sys_var_enum_const::value_ptr(Session *session __attribute__((unused)),
1081
1035
                                     enum_var_type type __attribute__((unused)),
1082
1036
                                     LEX_STRING *base __attribute__((unused)))
1083
1037
{
1084
1038
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
1085
1039
}
1086
1040
 
1087
 
bool sys_var_thd_ulong::check(THD *thd, set_var *var)
 
1041
bool sys_var_session_ulong::check(Session *session, set_var *var)
1088
1042
{
1089
 
  return (get_unsigned(thd, var) ||
1090
 
          (check_func && (*check_func)(thd, var)));
 
1043
  return (get_unsigned(session, var) ||
 
1044
          (check_func && (*check_func)(session, var)));
1091
1045
}
1092
1046
 
1093
 
bool sys_var_thd_ulong::update(THD *thd, set_var *var)
 
1047
bool sys_var_session_ulong::update(Session *session, set_var *var)
1094
1048
{
1095
1049
  uint64_t tmp= var->save_result.uint64_t_value;
1096
1050
  
1097
1051
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1098
1052
  if ((ulong) tmp > max_system_variables.*offset)
1099
1053
  {
1100
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
1054
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
1101
1055
    tmp= max_system_variables.*offset;
1102
1056
  }
1103
1057
  
1104
1058
  if (option_limits)
1105
 
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
1106
 
#if SIZEOF_LONG < SIZEOF_LONG_LONG
1107
 
  else if (tmp > ULONG_MAX)
 
1059
    tmp= (ulong) fix_unsigned(session, tmp, option_limits);
 
1060
  else if (tmp > UINT32_MAX)
1108
1061
  {
1109
 
    tmp= ULONG_MAX;
1110
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1062
    tmp= UINT32_MAX;
 
1063
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
1111
1064
  }
1112
 
#endif
1113
1065
  
1114
1066
  if (var->type == OPT_GLOBAL)
1115
1067
     global_system_variables.*offset= (ulong) tmp;
1116
1068
   else
1117
 
     thd->variables.*offset= (ulong) tmp;
 
1069
     session->variables.*offset= (ulong) tmp;
1118
1070
 
1119
1071
   return 0;
1120
1072
 }
1121
1073
 
1122
1074
 
1123
 
 void sys_var_thd_ulong::set_default(THD *thd, enum_var_type type)
 
1075
 void sys_var_session_ulong::set_default(Session *session, enum_var_type type)
1124
1076
 {
1125
1077
   if (type == OPT_GLOBAL)
1126
1078
   {
1131
1083
                                      option_limits, &not_used);
1132
1084
   }
1133
1085
   else
1134
 
     thd->variables.*offset= global_system_variables.*offset;
 
1086
     session->variables.*offset= global_system_variables.*offset;
1135
1087
 }
1136
1088
 
1137
1089
 
1138
 
unsigned char *sys_var_thd_ulong::value_ptr(THD *thd, enum_var_type type,
 
1090
unsigned char *sys_var_session_ulong::value_ptr(Session *session, enum_var_type type,
1139
1091
                                    LEX_STRING *base __attribute__((unused)))
1140
1092
{
1141
1093
  if (type == OPT_GLOBAL)
1142
1094
    return (unsigned char*) &(global_system_variables.*offset);
1143
 
  return (unsigned char*) &(thd->variables.*offset);
 
1095
  return (unsigned char*) &(session->variables.*offset);
1144
1096
}
1145
1097
 
1146
1098
 
1147
 
bool sys_var_thd_ha_rows::update(THD *thd, set_var *var)
 
1099
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1148
1100
{
1149
1101
  uint64_t tmp= var->save_result.uint64_t_value;
1150
1102
 
1153
1105
    tmp= max_system_variables.*offset;
1154
1106
 
1155
1107
  if (option_limits)
1156
 
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
 
1108
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1157
1109
  if (var->type == OPT_GLOBAL)
1158
1110
  {
1159
1111
    /* Lock is needed to make things safe on 32 bit systems */
1162
1114
    pthread_mutex_unlock(&LOCK_global_system_variables);
1163
1115
  }
1164
1116
  else
1165
 
    thd->variables.*offset= (ha_rows) tmp;
 
1117
    session->variables.*offset= (ha_rows) tmp;
1166
1118
  return 0;
1167
1119
}
1168
1120
 
1169
1121
 
1170
 
void sys_var_thd_ha_rows::set_default(THD *thd, enum_var_type type)
 
1122
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1171
1123
{
1172
1124
  if (type == OPT_GLOBAL)
1173
1125
  {
1180
1132
    pthread_mutex_unlock(&LOCK_global_system_variables);
1181
1133
  }
1182
1134
  else
1183
 
    thd->variables.*offset= global_system_variables.*offset;
 
1135
    session->variables.*offset= global_system_variables.*offset;
1184
1136
}
1185
1137
 
1186
1138
 
1187
 
unsigned char *sys_var_thd_ha_rows::value_ptr(THD *thd, enum_var_type type,
 
1139
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session, enum_var_type type,
1188
1140
                                      LEX_STRING *base __attribute__((unused)))
1189
1141
{
1190
1142
  if (type == OPT_GLOBAL)
1191
1143
    return (unsigned char*) &(global_system_variables.*offset);
1192
 
  return (unsigned char*) &(thd->variables.*offset);
 
1144
  return (unsigned char*) &(session->variables.*offset);
1193
1145
}
1194
1146
 
1195
 
bool sys_var_thd_uint64_t::check(THD *thd, set_var *var)
 
1147
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1196
1148
{
1197
 
  return get_unsigned(thd, var);
 
1149
  return get_unsigned(session, var);
1198
1150
}
1199
1151
 
1200
 
bool sys_var_thd_uint64_t::update(THD *thd,  set_var *var)
 
1152
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1201
1153
{
1202
1154
  uint64_t tmp= var->save_result.uint64_t_value;
1203
1155
 
1205
1157
    tmp= max_system_variables.*offset;
1206
1158
 
1207
1159
  if (option_limits)
1208
 
    tmp= fix_unsigned(thd, tmp, option_limits);
 
1160
    tmp= fix_unsigned(session, tmp, option_limits);
1209
1161
  if (var->type == OPT_GLOBAL)
1210
1162
  {
1211
1163
    /* Lock is needed to make things safe on 32 bit systems */
1214
1166
    pthread_mutex_unlock(&LOCK_global_system_variables);
1215
1167
  }
1216
1168
  else
1217
 
    thd->variables.*offset= (uint64_t) tmp;
 
1169
    session->variables.*offset= (uint64_t) tmp;
1218
1170
  return 0;
1219
1171
}
1220
1172
 
1221
1173
 
1222
 
void sys_var_thd_uint64_t::set_default(THD *thd, enum_var_type type)
 
1174
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1223
1175
{
1224
1176
  if (type == OPT_GLOBAL)
1225
1177
  {
1231
1183
    pthread_mutex_unlock(&LOCK_global_system_variables);
1232
1184
  }
1233
1185
  else
1234
 
    thd->variables.*offset= global_system_variables.*offset;
 
1186
    session->variables.*offset= global_system_variables.*offset;
1235
1187
}
1236
1188
 
1237
1189
 
1238
 
unsigned char *sys_var_thd_uint64_t::value_ptr(THD *thd, enum_var_type type,
 
1190
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session, enum_var_type type,
1239
1191
                                        LEX_STRING *base __attribute__((unused)))
1240
1192
{
1241
1193
  if (type == OPT_GLOBAL)
1242
1194
    return (unsigned char*) &(global_system_variables.*offset);
1243
 
  return (unsigned char*) &(thd->variables.*offset);
 
1195
  return (unsigned char*) &(session->variables.*offset);
1244
1196
}
1245
1197
 
1246
1198
 
1247
 
bool sys_var_thd_bool::update(THD *thd,  set_var *var)
 
1199
bool sys_var_session_bool::update(Session *session,  set_var *var)
1248
1200
{
1249
1201
  if (var->type == OPT_GLOBAL)
1250
1202
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
1251
1203
  else
1252
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1204
    session->variables.*offset= (bool) var->save_result.ulong_value;
1253
1205
  return 0;
1254
1206
}
1255
1207
 
1256
1208
 
1257
 
void sys_var_thd_bool::set_default(THD *thd,  enum_var_type type)
 
1209
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1258
1210
{
1259
1211
  if (type == OPT_GLOBAL)
1260
1212
    global_system_variables.*offset= (bool) option_limits->def_value;
1261
1213
  else
1262
 
    thd->variables.*offset= global_system_variables.*offset;
 
1214
    session->variables.*offset= global_system_variables.*offset;
1263
1215
}
1264
1216
 
1265
1217
 
1266
 
unsigned char *sys_var_thd_bool::value_ptr(THD *thd, enum_var_type type,
 
1218
unsigned char *sys_var_session_bool::value_ptr(Session *session, enum_var_type type,
1267
1219
                                   LEX_STRING *base __attribute__((unused)))
1268
1220
{
1269
1221
  if (type == OPT_GLOBAL)
1270
1222
    return (unsigned char*) &(global_system_variables.*offset);
1271
 
  return (unsigned char*) &(thd->variables.*offset);
 
1223
  return (unsigned char*) &(session->variables.*offset);
1272
1224
}
1273
1225
 
1274
1226
 
1275
 
bool sys_var::check_enum(THD *thd __attribute__((unused)),
 
1227
bool sys_var::check_enum(Session *session __attribute__((unused)),
1276
1228
                         set_var *var, const TYPELIB *enum_names)
1277
1229
{
1278
1230
  char buff[STRING_BUFFER_USUAL_SIZE];
1309
1261
}
1310
1262
 
1311
1263
 
1312
 
bool sys_var::check_set(THD *thd __attribute__((unused)),
 
1264
bool sys_var::check_set(Session *session __attribute__((unused)),
1313
1265
                        set_var *var, TYPELIB *enum_names)
1314
1266
{
1315
1267
  bool not_used;
1384
1336
  If type is not given, return local value if exists, else global.
1385
1337
*/
1386
1338
 
1387
 
Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base)
 
1339
Item *sys_var::item(Session *session, enum_var_type var_type, LEX_STRING *base)
1388
1340
{
1389
1341
  if (check_type(var_type))
1390
1342
  {
1402
1354
  {
1403
1355
    uint32_t value;
1404
1356
    pthread_mutex_lock(&LOCK_global_system_variables);
1405
 
    value= *(uint*) value_ptr(thd, var_type, base);
 
1357
    value= *(uint*) value_ptr(session, var_type, base);
1406
1358
    pthread_mutex_unlock(&LOCK_global_system_variables);
1407
1359
    return new Item_uint((uint64_t) value);
1408
1360
  }
1410
1362
  {
1411
1363
    ulong value;
1412
1364
    pthread_mutex_lock(&LOCK_global_system_variables);
1413
 
    value= *(ulong*) value_ptr(thd, var_type, base);
 
1365
    value= *(ulong*) value_ptr(session, var_type, base);
1414
1366
    pthread_mutex_unlock(&LOCK_global_system_variables);
1415
1367
    return new Item_uint((uint64_t) value);
1416
1368
  }
1418
1370
  {
1419
1371
    int64_t value;
1420
1372
    pthread_mutex_lock(&LOCK_global_system_variables);
1421
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1373
    value= *(int64_t*) value_ptr(session, var_type, base);
1422
1374
    pthread_mutex_unlock(&LOCK_global_system_variables);
1423
1375
    return new Item_int(value);
1424
1376
  }
1426
1378
  {
1427
1379
    double value;
1428
1380
    pthread_mutex_lock(&LOCK_global_system_variables);
1429
 
    value= *(double*) value_ptr(thd, var_type, base);
 
1381
    value= *(double*) value_ptr(session, var_type, base);
1430
1382
    pthread_mutex_unlock(&LOCK_global_system_variables);
1431
1383
    /* 6, as this is for now only used with microseconds */
1432
1384
    return new Item_float(value, 6);
1435
1387
  {
1436
1388
    ha_rows value;
1437
1389
    pthread_mutex_lock(&LOCK_global_system_variables);
1438
 
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1390
    value= *(ha_rows*) value_ptr(session, var_type, base);
1439
1391
    pthread_mutex_unlock(&LOCK_global_system_variables);
1440
1392
    return new Item_int((uint64_t) value);
1441
1393
  }
1443
1395
  {
1444
1396
    int32_t value;
1445
1397
    pthread_mutex_lock(&LOCK_global_system_variables);
1446
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1398
    value= *(bool*) value_ptr(session, var_type, base);
1447
1399
    pthread_mutex_unlock(&LOCK_global_system_variables);
1448
1400
    return new Item_int(value,1);
1449
1401
  }
1451
1403
  {
1452
1404
    Item *tmp;
1453
1405
    pthread_mutex_lock(&LOCK_global_system_variables);
1454
 
    char *str= *(char**) value_ptr(thd, var_type, base);
 
1406
    char *str= *(char**) value_ptr(session, var_type, base);
1455
1407
    if (str)
1456
1408
    {
1457
1409
      uint32_t length= strlen(str);
1458
 
      tmp= new Item_string(thd->strmake(str, length), length,
 
1410
      tmp= new Item_string(session->strmake(str, length), length,
1459
1411
                           system_charset_info, DERIVATION_SYSCONST);
1460
1412
    }
1461
1413
    else
1470
1422
  {
1471
1423
    Item *tmp;
1472
1424
    pthread_mutex_lock(&LOCK_global_system_variables);
1473
 
    char *str= (char*) value_ptr(thd, var_type, base);
 
1425
    char *str= (char*) value_ptr(session, var_type, base);
1474
1426
    if (str)
1475
1427
      tmp= new Item_string(str, strlen(str),
1476
1428
                           system_charset_info, DERIVATION_SYSCONST);
1489
1441
}
1490
1442
 
1491
1443
 
1492
 
bool sys_var_thd_enum::update(THD *thd, set_var *var)
 
1444
bool sys_var_session_enum::update(Session *session, set_var *var)
1493
1445
{
1494
1446
  if (var->type == OPT_GLOBAL)
1495
1447
    global_system_variables.*offset= var->save_result.ulong_value;
1496
1448
  else
1497
 
    thd->variables.*offset= var->save_result.ulong_value;
 
1449
    session->variables.*offset= var->save_result.ulong_value;
1498
1450
  return 0;
1499
1451
}
1500
1452
 
1501
1453
 
1502
 
void sys_var_thd_enum::set_default(THD *thd, enum_var_type type)
 
1454
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1503
1455
{
1504
1456
  if (type == OPT_GLOBAL)
1505
1457
    global_system_variables.*offset= (ulong) option_limits->def_value;
1506
1458
  else
1507
 
    thd->variables.*offset= global_system_variables.*offset;
 
1459
    session->variables.*offset= global_system_variables.*offset;
1508
1460
}
1509
1461
 
1510
1462
 
1511
 
unsigned char *sys_var_thd_enum::value_ptr(THD *thd, enum_var_type type,
 
1463
unsigned char *sys_var_session_enum::value_ptr(Session *session, enum_var_type type,
1512
1464
                                   LEX_STRING *base __attribute__((unused)))
1513
1465
{
1514
1466
  ulong tmp= ((type == OPT_GLOBAL) ?
1515
1467
              global_system_variables.*offset :
1516
 
              thd->variables.*offset);
 
1468
              session->variables.*offset);
1517
1469
  return (unsigned char*) enum_names->type_names[tmp];
1518
1470
}
1519
1471
 
1520
 
bool sys_var_thd_bit::check(THD *thd, set_var *var)
 
1472
bool sys_var_session_bit::check(Session *session, set_var *var)
1521
1473
{
1522
 
  return (check_enum(thd, var, &bool_typelib) ||
1523
 
          (check_func && (*check_func)(thd, var)));
 
1474
  return (check_enum(session, var, &bool_typelib) ||
 
1475
          (check_func && (*check_func)(session, var)));
1524
1476
}
1525
1477
 
1526
 
bool sys_var_thd_bit::update(THD *thd, set_var *var)
 
1478
bool sys_var_session_bit::update(Session *session, set_var *var)
1527
1479
{
1528
 
  int res= (*update_func)(thd, var);
 
1480
  int res= (*update_func)(session, var);
1529
1481
  return res;
1530
1482
}
1531
1483
 
1532
1484
 
1533
 
unsigned char *sys_var_thd_bit::value_ptr(THD *thd,
 
1485
unsigned char *sys_var_session_bit::value_ptr(Session *session,
1534
1486
                                  enum_var_type type __attribute__((unused)),
1535
1487
                                  LEX_STRING *base __attribute__((unused)))
1536
1488
{
1538
1490
    If reverse is 0 (default) return 1 if bit is set.
1539
1491
    If reverse is 1, return 0 if bit is set
1540
1492
  */
1541
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1493
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1542
1494
                                   !reverse : reverse);
1543
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1495
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1544
1496
}
1545
1497
 
1546
1498
 
1547
1499
/** Update a date_time format variable based on given value. */
1548
1500
 
1549
 
void sys_var_thd_date_time_format::update2(THD *thd, enum_var_type type,
 
1501
void sys_var_session_date_time_format::update2(Session *session, enum_var_type type,
1550
1502
                                           DATE_TIME_FORMAT *new_value)
1551
1503
{
1552
1504
  DATE_TIME_FORMAT *old;
1560
1512
  }
1561
1513
  else
1562
1514
  {
1563
 
    old= (thd->variables.*offset);
1564
 
    (thd->variables.*offset)= new_value;
 
1515
    old= (session->variables.*offset);
 
1516
    (session->variables.*offset)= new_value;
1565
1517
  }
1566
1518
  free((char*) old);
1567
1519
  return;
1568
1520
}
1569
1521
 
1570
1522
 
1571
 
bool sys_var_thd_date_time_format::update(THD *thd, set_var *var)
 
1523
bool sys_var_session_date_time_format::update(Session *session, set_var *var)
1572
1524
{
1573
1525
  DATE_TIME_FORMAT *new_value;
1574
1526
  /* We must make a copy of the last value to get it into normal memory */
1575
 
  new_value= date_time_format_copy((THD*) 0,
 
1527
  new_value= date_time_format_copy((Session*) 0,
1576
1528
                                   var->save_result.date_time_format);
1577
1529
  if (!new_value)
1578
1530
    return 1;                                   // Out of memory
1579
 
  update2(thd, var->type, new_value);           // Can't fail
 
1531
  update2(session, var->type, new_value);               // Can't fail
1580
1532
  return 0;
1581
1533
}
1582
1534
 
1583
1535
 
1584
 
bool sys_var_thd_date_time_format::check(THD *thd, set_var *var)
 
1536
bool sys_var_session_date_time_format::check(Session *session, set_var *var)
1585
1537
{
1586
1538
  char buff[STRING_BUFFER_USUAL_SIZE];
1587
1539
  String str(buff,sizeof(buff), system_charset_info), *res;
1601
1553
    We must copy result to thread space to not get a memory leak if
1602
1554
    update is aborted
1603
1555
  */
1604
 
  var->save_result.date_time_format= date_time_format_copy(thd, format);
 
1556
  var->save_result.date_time_format= date_time_format_copy(session, format);
1605
1557
  free((char*) format);
1606
1558
  return var->save_result.date_time_format == 0;
1607
1559
}
1608
1560
 
1609
1561
 
1610
 
void sys_var_thd_date_time_format::set_default(THD *thd, enum_var_type type)
 
1562
void sys_var_session_date_time_format::set_default(Session *session, enum_var_type type)
1611
1563
{
1612
1564
  DATE_TIME_FORMAT *res= 0;
1613
1565
 
1620
1572
  else
1621
1573
  {
1622
1574
    /* Make copy with malloc */
1623
 
    res= date_time_format_copy((THD *) 0, global_system_variables.*offset);
 
1575
    res= date_time_format_copy((Session *) 0, global_system_variables.*offset);
1624
1576
  }
1625
1577
 
1626
1578
  if (res)                                      // Should always be true
1627
 
    update2(thd, type, res);
 
1579
    update2(session, type, res);
1628
1580
}
1629
1581
 
1630
1582
 
1631
 
unsigned char *sys_var_thd_date_time_format::value_ptr(THD *thd, enum_var_type type,
 
1583
unsigned char *sys_var_session_date_time_format::value_ptr(Session *session, enum_var_type type,
1632
1584
                                               LEX_STRING *base __attribute__((unused)))
1633
1585
{
1634
1586
  if (type == OPT_GLOBAL)
1639
1591
      is modifying the original string while the copy is accessed
1640
1592
      (Can't happen now in SQL SHOW, but this is a good safety for the future)
1641
1593
    */
1642
 
    res= thd->strmake((global_system_variables.*offset)->format.str,
 
1594
    res= session->strmake((global_system_variables.*offset)->format.str,
1643
1595
                      (global_system_variables.*offset)->format.length);
1644
1596
    return (unsigned char*) res;
1645
1597
  }
1646
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1598
  return (unsigned char*) (session->variables.*offset)->format.str;
1647
1599
}
1648
1600
 
1649
1601
 
1653
1605
  const char *new_name;
1654
1606
} my_old_conv;
1655
1607
 
1656
 
bool sys_var_collation::check(THD *thd __attribute__((unused)),
 
1608
bool sys_var_collation::check(Session *session __attribute__((unused)),
1657
1609
                              set_var *var)
1658
1610
{
1659
1611
  const CHARSET_INFO *tmp;
1688
1640
}
1689
1641
 
1690
1642
 
1691
 
bool sys_var_character_set::check(THD *thd __attribute__((unused)),
 
1643
bool sys_var_character_set::check(Session *session __attribute__((unused)),
1692
1644
                                  set_var *var)
1693
1645
{
1694
1646
  const CHARSET_INFO *tmp;
1727
1679
}
1728
1680
 
1729
1681
 
1730
 
bool sys_var_character_set::update(THD *thd, set_var *var)
 
1682
bool sys_var_character_set::update(Session *session, set_var *var)
1731
1683
{
1732
 
  ci_ptr(thd,var->type)[0]= var->save_result.charset;
1733
 
  thd->update_charset();
 
1684
  ci_ptr(session,var->type)[0]= var->save_result.charset;
 
1685
  session->update_charset();
1734
1686
  return 0;
1735
1687
}
1736
1688
 
1737
1689
 
1738
 
unsigned char *sys_var_character_set::value_ptr(THD *thd, enum_var_type type,
 
1690
unsigned char *sys_var_character_set::value_ptr(Session *session, enum_var_type type,
1739
1691
                                        LEX_STRING *base __attribute__((unused)))
1740
1692
{
1741
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
 
1693
  const CHARSET_INFO * const cs= ci_ptr(session,type)[0];
1742
1694
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
1743
1695
}
1744
1696
 
1745
1697
 
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)
 
1698
bool sys_var_collation_sv::update(Session *session, set_var *var)
1803
1699
{
1804
1700
  if (var->type == OPT_GLOBAL)
1805
1701
    global_system_variables.*offset= var->save_result.charset;
1806
1702
  else
1807
1703
  {
1808
 
    thd->variables.*offset= var->save_result.charset;
1809
 
    thd->update_charset();
 
1704
    session->variables.*offset= var->save_result.charset;
 
1705
    session->update_charset();
1810
1706
  }
1811
1707
  return 0;
1812
1708
}
1813
1709
 
1814
1710
 
1815
 
void sys_var_collation_sv::set_default(THD *thd, enum_var_type type)
 
1711
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1816
1712
{
1817
1713
  if (type == OPT_GLOBAL)
1818
1714
    global_system_variables.*offset= *global_default;
1819
1715
  else
1820
1716
  {
1821
 
    thd->variables.*offset= global_system_variables.*offset;
1822
 
    thd->update_charset();
 
1717
    session->variables.*offset= global_system_variables.*offset;
 
1718
    session->update_charset();
1823
1719
  }
1824
1720
}
1825
1721
 
1826
1722
 
1827
 
unsigned char *sys_var_collation_sv::value_ptr(THD *thd, enum_var_type type,
 
1723
unsigned char *sys_var_collation_sv::value_ptr(Session *session, enum_var_type type,
1828
1724
                                       LEX_STRING *base __attribute__((unused)))
1829
1725
{
1830
1726
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1831
 
                     global_system_variables.*offset : thd->variables.*offset);
 
1727
                     global_system_variables.*offset : session->variables.*offset);
1832
1728
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1833
1729
}
1834
1730
 
1847
1743
}
1848
1744
 
1849
1745
 
1850
 
unsigned char *sys_var_key_cache_param::value_ptr(THD *thd __attribute__((unused)),
 
1746
unsigned char *sys_var_key_cache_param::value_ptr(Session *session __attribute__((unused)),
1851
1747
                                          enum_var_type type __attribute__((unused)),
1852
1748
                                          LEX_STRING *base __attribute__((unused)))
1853
1749
{
1858
1754
}
1859
1755
 
1860
1756
 
1861
 
bool sys_var_key_buffer_size::update(THD *thd, set_var *var)
 
1757
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1862
1758
{
1863
1759
  uint64_t tmp= var->save_result.uint64_t_value;
1864
1760
  LEX_STRING *base_name= &var->base;
1896
1792
  {
1897
1793
    if (key_cache == dflt_key_cache)
1898
1794
    {
1899
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1795
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1900
1796
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1901
1797
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1902
1798
      goto end;                                 // Ignore default key cache
1913
1809
                                              base_name->length, &list);
1914
1810
      key_cache->in_init= 1;
1915
1811
      pthread_mutex_unlock(&LOCK_global_system_variables);
1916
 
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
 
1812
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1917
1813
      pthread_mutex_lock(&LOCK_global_system_variables);
1918
1814
      key_cache->in_init= 0;
1919
1815
    }
1925
1821
  }
1926
1822
 
1927
1823
  key_cache->param_buff_size=
1928
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1824
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1929
1825
 
1930
1826
  /* If key cache didn't existed initialize it, else resize it */
1931
1827
  key_cache->in_init= 1;
1951
1847
  This should be changed so that we wait until the previous
1952
1848
  assignment is done and then do the new assign
1953
1849
*/
1954
 
bool sys_var_key_cache_long::update(THD *thd, set_var *var)
 
1850
bool sys_var_key_cache_long::update(Session *session, set_var *var)
1955
1851
{
1956
1852
  ulong tmp= (ulong) var->value->val_int();
1957
1853
  LEX_STRING *base_name= &var->base;
1979
1875
    goto end;
1980
1876
 
1981
1877
  *((ulong*) (((char*) key_cache) + offset))=
1982
 
    (ulong) fix_unsigned(thd, tmp, option_limits);
 
1878
    (ulong) fix_unsigned(session, tmp, option_limits);
1983
1879
 
1984
1880
  /*
1985
1881
    Don't create a new key cache if it didn't exist
2000
1896
}
2001
1897
 
2002
1898
 
2003
 
bool sys_var_log_state::update(THD *thd __attribute__((unused)), set_var *var)
 
1899
bool sys_var_log_state::update(Session *session __attribute__((unused)), set_var *var)
2004
1900
{
2005
1901
  bool res;
2006
1902
  pthread_mutex_lock(&LOCK_global_system_variables);
2012
1908
  return res;
2013
1909
}
2014
1910
 
2015
 
void sys_var_log_state::set_default(THD *thd __attribute__((unused)),
 
1911
void sys_var_log_state::set_default(Session *session __attribute__((unused)),
2016
1912
                                    enum_var_type type __attribute__((unused)))
2017
1913
{
2018
1914
}
2019
1915
 
2020
1916
 
2021
 
bool update_sys_var_str_path(THD *thd __attribute__((unused)),
 
1917
bool update_sys_var_str_path(Session *session __attribute__((unused)),
2022
1918
                             sys_var_str *var_str,
2023
1919
                             set_var *var, const char *log_ext,
2024
1920
                             bool log_state, uint32_t log_type)
2067
1963
}
2068
1964
 
2069
1965
 
2070
 
bool sys_var_log_output::update(THD *thd __attribute__((unused)),
 
1966
bool sys_var_log_output::update(Session *session __attribute__((unused)),
2071
1967
                                set_var *var)
2072
1968
{
2073
1969
  pthread_mutex_lock(&LOCK_global_system_variables);
2079
1975
}
2080
1976
 
2081
1977
 
2082
 
void sys_var_log_output::set_default(THD *thd __attribute__((unused)),
 
1978
void sys_var_log_output::set_default(Session *session __attribute__((unused)),
2083
1979
                                     enum_var_type type __attribute__((unused)))
2084
1980
{
2085
1981
  pthread_mutex_lock(&LOCK_global_system_variables);
2090
1986
}
2091
1987
 
2092
1988
 
2093
 
unsigned char *sys_var_log_output::value_ptr(THD *thd,
 
1989
unsigned char *sys_var_log_output::value_ptr(Session *session,
2094
1990
                                     enum_var_type type __attribute__((unused)),
2095
1991
                                     LEX_STRING *base __attribute__((unused)))
2096
1992
{
2112
2008
 
2113
2009
  if ((length= tmp.length()))
2114
2010
    length--;
2115
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2011
  return (unsigned char*) session->strmake(tmp.ptr(), length);
2116
2012
}
2117
2013
 
2118
2014
 
2120
2016
  Functions to handle SET NAMES and SET CHARACTER SET
2121
2017
*****************************************************************************/
2122
2018
 
2123
 
int set_var_collation_client::check(THD *thd __attribute__((unused)))
 
2019
int set_var_collation_client::check(Session *session __attribute__((unused)))
2124
2020
{
2125
2021
  /* Currently, UCS-2 cannot be used as a client character set */
2126
2022
  if (character_set_client->mbminlen > 1)
2132
2028
  return 0;
2133
2029
}
2134
2030
 
2135
 
int set_var_collation_client::update(THD *thd)
 
2031
int set_var_collation_client::update(Session *session)
2136
2032
{
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);
 
2033
  session->variables.character_set_client= character_set_client;
 
2034
  session->variables.character_set_results= character_set_results;
 
2035
  session->variables.collation_connection= collation_connection;
 
2036
  session->update_charset();
 
2037
  session->protocol_text.init(session);
2142
2038
  return 0;
2143
2039
}
2144
2040
 
2145
2041
/****************************************************************************/
2146
2042
 
2147
 
bool sys_var_timestamp::update(THD *thd,  set_var *var)
 
2043
bool sys_var_timestamp::update(Session *session,  set_var *var)
2148
2044
{
2149
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
2045
  session->set_time((time_t) var->save_result.uint64_t_value);
2150
2046
  return 0;
2151
2047
}
2152
2048
 
2153
2049
 
2154
 
void sys_var_timestamp::set_default(THD *thd,
 
2050
void sys_var_timestamp::set_default(Session *session,
2155
2051
                                    enum_var_type type __attribute__((unused)))
2156
2052
{
2157
 
  thd->user_time=0;
 
2053
  session->user_time=0;
2158
2054
}
2159
2055
 
2160
2056
 
2161
 
unsigned char *sys_var_timestamp::value_ptr(THD *thd,
 
2057
unsigned char *sys_var_timestamp::value_ptr(Session *session,
2162
2058
                                    enum_var_type type __attribute__((unused)),
2163
2059
                                    LEX_STRING *base __attribute__((unused)))
2164
2060
{
2165
 
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2166
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2061
  session->sys_var_tmp.long_value= (long) session->start_time;
 
2062
  return (unsigned char*) &session->sys_var_tmp.long_value;
2167
2063
}
2168
2064
 
2169
2065
 
2170
 
bool sys_var_last_insert_id::update(THD *thd, set_var *var)
 
2066
bool sys_var_last_insert_id::update(Session *session, set_var *var)
2171
2067
{
2172
 
  thd->first_successful_insert_id_in_prev_stmt=
 
2068
  session->first_successful_insert_id_in_prev_stmt=
2173
2069
    var->save_result.uint64_t_value;
2174
2070
  return 0;
2175
2071
}
2176
2072
 
2177
2073
 
2178
 
unsigned char *sys_var_last_insert_id::value_ptr(THD *thd,
 
2074
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2179
2075
                                         enum_var_type type __attribute__((unused)),
2180
2076
                                         LEX_STRING *base __attribute__((unused)))
2181
2077
{
2183
2079
    this tmp var makes it robust againt change of type of
2184
2080
    read_first_successful_insert_id_in_prev_stmt().
2185
2081
  */
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;
 
2082
  session->sys_var_tmp.uint64_t_value= 
 
2083
    session->read_first_successful_insert_id_in_prev_stmt();
 
2084
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
2189
2085
}
2190
2086
 
2191
2087
 
2192
 
bool sys_var_insert_id::update(THD *thd, set_var *var)
 
2088
bool sys_var_insert_id::update(Session *session, set_var *var)
2193
2089
{
2194
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
 
2090
  session->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2195
2091
  return 0;
2196
2092
}
2197
2093
 
2198
2094
 
2199
 
unsigned char *sys_var_insert_id::value_ptr(THD *thd,
 
2095
unsigned char *sys_var_insert_id::value_ptr(Session *session,
2200
2096
                                    enum_var_type type __attribute__((unused)),
2201
2097
                                    LEX_STRING *base __attribute__((unused)))
2202
2098
{
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)
 
2099
  session->sys_var_tmp.uint64_t_value=
 
2100
    session->auto_inc_intervals_forced.minimum();
 
2101
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
2102
}
 
2103
 
 
2104
 
 
2105
bool sys_var_rand_seed1::update(Session *session, set_var *var)
 
2106
{
 
2107
  session->rand.seed1= (ulong) var->save_result.uint64_t_value;
 
2108
  return 0;
 
2109
}
 
2110
 
 
2111
bool sys_var_rand_seed2::update(Session *session, set_var *var)
 
2112
{
 
2113
  session->rand.seed2= (ulong) var->save_result.uint64_t_value;
 
2114
  return 0;
 
2115
}
 
2116
 
 
2117
 
 
2118
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2223
2119
{
2224
2120
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2225
2121
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2226
2122
  String *res= var->value->val_str(&str);
2227
2123
 
2228
 
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
 
2124
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
2229
2125
  {
2230
2126
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2231
2127
    return 1;
2234
2130
}
2235
2131
 
2236
2132
 
2237
 
bool sys_var_thd_time_zone::update(THD *thd, set_var *var)
 
2133
bool sys_var_session_time_zone::update(Session *session, set_var *var)
2238
2134
{
2239
2135
  /* We are using Time_zone object found during check() phase. */
2240
2136
  if (var->type == OPT_GLOBAL)
2244
2140
    pthread_mutex_unlock(&LOCK_global_system_variables);
2245
2141
  }
2246
2142
  else
2247
 
    thd->variables.time_zone= var->save_result.time_zone;
 
2143
    session->variables.time_zone= var->save_result.time_zone;
2248
2144
  return 0;
2249
2145
}
2250
2146
 
2251
2147
 
2252
 
unsigned char *sys_var_thd_time_zone::value_ptr(THD *thd, enum_var_type type,
 
2148
unsigned char *sys_var_session_time_zone::value_ptr(Session *session, enum_var_type type,
2253
2149
                                        LEX_STRING *base __attribute__((unused)))
2254
2150
{
2255
2151
  /* 
2268
2164
      timezone). If it's the global value which was used we can't replicate
2269
2165
      (binlog code stores session value only).
2270
2166
    */
2271
 
    thd->time_zone_used= 1;
2272
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2167
    session->time_zone_used= 1;
 
2168
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
2273
2169
  }
2274
2170
}
2275
2171
 
2276
2172
 
2277
 
void sys_var_thd_time_zone::set_default(THD *thd, enum_var_type type)
 
2173
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
2278
2174
{
2279
2175
 pthread_mutex_lock(&LOCK_global_system_variables);
2280
2176
 if (type == OPT_GLOBAL)
2286
2182
       We are guaranteed to find this time zone since its existence
2287
2183
       is checked during start-up.
2288
2184
     */
2289
 
     global_system_variables.time_zone= my_tz_find(thd, &str);
 
2185
     global_system_variables.time_zone= my_tz_find(session, &str);
2290
2186
   }
2291
2187
   else
2292
2188
     global_system_variables.time_zone= my_tz_SYSTEM;
2293
2189
 }
2294
2190
 else
2295
 
   thd->variables.time_zone= global_system_variables.time_zone;
 
2191
   session->variables.time_zone= global_system_variables.time_zone;
2296
2192
 pthread_mutex_unlock(&LOCK_global_system_variables);
2297
2193
}
2298
2194
 
2299
2195
 
2300
 
bool sys_var_max_user_conn::check(THD *thd, set_var *var)
 
2196
bool sys_var_max_user_conn::check(Session *session, set_var *var)
2301
2197
{
2302
2198
  if (var->type == OPT_GLOBAL)
2303
 
    return sys_var_thd::check(thd, var);
 
2199
    return sys_var_session::check(session, var);
2304
2200
  else
2305
2201
  {
2306
2202
    /*
2312
2208
  }
2313
2209
}
2314
2210
 
2315
 
bool sys_var_max_user_conn::update(THD *thd __attribute__((unused)),
 
2211
bool sys_var_max_user_conn::update(Session *session __attribute__((unused)),
2316
2212
                                   set_var *var)
2317
2213
{
2318
2214
  assert(var->type == OPT_GLOBAL);
2323
2219
}
2324
2220
 
2325
2221
 
2326
 
void sys_var_max_user_conn::set_default(THD *thd __attribute__((unused)),
 
2222
void sys_var_max_user_conn::set_default(Session *session __attribute__((unused)),
2327
2223
                                        enum_var_type type __attribute__((unused)))
2328
2224
{
2329
2225
  assert(type == OPT_GLOBAL);
2333
2229
}
2334
2230
 
2335
2231
 
2336
 
unsigned char *sys_var_max_user_conn::value_ptr(THD *thd, enum_var_type type,
 
2232
unsigned char *sys_var_max_user_conn::value_ptr(Session *session, enum_var_type type,
2337
2233
                                        LEX_STRING *base __attribute__((unused)))
2338
2234
{
2339
2235
  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);
 
2236
      session->user_connect && session->user_connect->user_resources.user_conn)
 
2237
    return (unsigned char*) &(session->user_connect->user_resources.user_conn);
2342
2238
  return (unsigned char*) &(max_user_connections);
2343
2239
}
2344
2240
 
2345
2241
 
2346
 
bool sys_var_thd_lc_time_names::check(THD *thd __attribute__((unused)),
 
2242
bool sys_var_session_lc_time_names::check(Session *session __attribute__((unused)),
2347
2243
                                      set_var *var)
2348
2244
{
2349
2245
  MY_LOCALE *locale_match;
2381
2277
}
2382
2278
 
2383
2279
 
2384
 
bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var)
 
2280
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2385
2281
{
2386
2282
  if (var->type == OPT_GLOBAL)
2387
2283
    global_system_variables.lc_time_names= var->save_result.locale_value;
2388
2284
  else
2389
 
    thd->variables.lc_time_names= var->save_result.locale_value;
 
2285
    session->variables.lc_time_names= var->save_result.locale_value;
2390
2286
  return 0;
2391
2287
}
2392
2288
 
2393
2289
 
2394
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(THD *thd,
 
2290
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
2395
2291
                                            enum_var_type type,
2396
2292
                                            LEX_STRING *base __attribute__((unused)))
2397
2293
{
2398
2294
  return type == OPT_GLOBAL ?
2399
2295
                 (unsigned char *) global_system_variables.lc_time_names->name :
2400
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2296
                 (unsigned char *) session->variables.lc_time_names->name;
2401
2297
}
2402
2298
 
2403
2299
 
2404
 
void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type)
 
2300
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
2405
2301
{
2406
2302
  if (type == OPT_GLOBAL)
2407
2303
    global_system_variables.lc_time_names= my_default_lc_time_names;
2408
2304
  else
2409
 
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
 
2305
    session->variables.lc_time_names= global_system_variables.lc_time_names;
2410
2306
}
2411
2307
 
2412
2308
/*
2418
2314
    This is used for handling long_query_time
2419
2315
*/
2420
2316
 
2421
 
bool sys_var_microseconds::update(THD *thd, set_var *var)
 
2317
bool sys_var_microseconds::update(Session *session, set_var *var)
2422
2318
{
2423
2319
  double num= var->value->val_real();
2424
2320
  int64_t microseconds;
2434
2330
    pthread_mutex_unlock(&LOCK_global_system_variables);
2435
2331
  }
2436
2332
  else
2437
 
    thd->variables.*offset= microseconds;
 
2333
    session->variables.*offset= microseconds;
2438
2334
  return 0;
2439
2335
}
2440
2336
 
2441
2337
 
2442
 
void sys_var_microseconds::set_default(THD *thd, enum_var_type type)
 
2338
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
2443
2339
{
2444
2340
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
2445
2341
  if (type == OPT_GLOBAL)
2449
2345
    pthread_mutex_unlock(&LOCK_global_system_variables);
2450
2346
  }
2451
2347
  else
2452
 
    thd->variables.*offset= microseconds;
 
2348
    session->variables.*offset= microseconds;
2453
2349
}
2454
2350
 
2455
2351
 
2456
 
unsigned char *sys_var_microseconds::value_ptr(THD *thd, enum_var_type type,
 
2352
unsigned char *sys_var_microseconds::value_ptr(Session *session, enum_var_type type,
2457
2353
                                          LEX_STRING *base __attribute__((unused)))
2458
2354
{
2459
 
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
2355
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2460
2356
                                   global_system_variables.*offset :
2461
 
                                   thd->variables.*offset) / 1000000.0;
2462
 
  return (unsigned char*) &thd->tmp_double_value;
 
2357
                                   session->variables.*offset) / 1000000.0;
 
2358
  return (unsigned char*) &session->tmp_double_value;
2463
2359
}
2464
2360
 
2465
2361
 
2466
2362
/*
2467
 
  Functions to update thd->options bits
 
2363
  Functions to update session->options bits
2468
2364
*/
2469
2365
 
2470
 
static bool set_option_bit(THD *thd, set_var *var)
 
2366
static bool set_option_bit(Session *session, set_var *var)
2471
2367
{
2472
 
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
 
2368
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
2473
2369
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2474
 
    thd->options&= ~sys_var->bit_flag;
 
2370
    session->options&= ~sys_var->bit_flag;
2475
2371
  else
2476
 
    thd->options|= sys_var->bit_flag;
 
2372
    session->options|= sys_var->bit_flag;
2477
2373
  return 0;
2478
2374
}
2479
2375
 
2480
2376
 
2481
 
static bool set_option_autocommit(THD *thd, set_var *var)
 
2377
static bool set_option_autocommit(Session *session, set_var *var)
2482
2378
{
2483
2379
  /* The test is negative as the flag we use is NOT autocommit */
2484
2380
 
2485
 
  uint64_t org_options= thd->options;
 
2381
  uint64_t org_options= session->options;
2486
2382
 
2487
2383
  if (var->save_result.ulong_value != 0)
2488
 
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
 
2384
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2489
2385
  else
2490
 
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
 
2386
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2491
2387
 
2492
 
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
 
2388
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2493
2389
  {
2494
2390
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2495
2391
    {
2496
2392
      /* We changed to auto_commit mode */
2497
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2498
 
      thd->transaction.all.modified_non_trans_table= false;
2499
 
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2500
 
      if (ha_commit(thd))
 
2393
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2394
      session->transaction.all.modified_non_trans_table= false;
 
2395
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
2396
      if (ha_commit(session))
2501
2397
        return 1;
2502
2398
    }
2503
2399
    else
2504
2400
    {
2505
 
      thd->transaction.all.modified_non_trans_table= false;
2506
 
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
2401
      session->transaction.all.modified_non_trans_table= false;
 
2402
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2507
2403
    }
2508
2404
  }
2509
2405
  return 0;
2510
2406
}
2511
2407
 
2512
 
static int check_log_update(THD *thd __attribute__((unused)),
 
2408
static int check_log_update(Session *session __attribute__((unused)),
2513
2409
                            set_var *var __attribute__((unused)))
2514
2410
{
2515
2411
  return 0;
2516
2412
}
2517
2413
 
2518
2414
 
2519
 
static int check_pseudo_thread_id(THD *thd __attribute__((unused)),
 
2415
static int check_pseudo_thread_id(Session *session __attribute__((unused)),
2520
2416
                                  set_var *var)
2521
2417
{
2522
2418
  var->save_result.uint64_t_value= var->value->val_int();
2523
2419
  return 0;
2524
2420
}
2525
2421
 
2526
 
static unsigned char *get_warning_count(THD *thd)
 
2422
static unsigned char *get_warning_count(Session *session)
2527
2423
{
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;
 
2424
  session->sys_var_tmp.long_value=
 
2425
    (session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
 
2426
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
 
2427
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
 
2428
  return (unsigned char*) &session->sys_var_tmp.long_value;
2533
2429
}
2534
2430
 
2535
 
static unsigned char *get_error_count(THD *thd)
 
2431
static unsigned char *get_error_count(Session *session)
2536
2432
{
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;
 
2433
  session->sys_var_tmp.long_value= 
 
2434
    session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
 
2435
  return (unsigned char*) &session->sys_var_tmp.long_value;
2540
2436
}
2541
2437
 
2542
2438
 
2549
2445
  that is actually a call to my_tmpdir() which cycles among possible
2550
2446
  temporary directories.
2551
2447
 
2552
 
  @param thd            thread handle
 
2448
  @param session                thread handle
2553
2449
 
2554
2450
  @retval
2555
2451
    ptr         pointer to NUL-terminated string
2556
2452
*/
2557
 
static unsigned char *get_tmpdir(THD *thd __attribute__((unused)))
 
2453
static unsigned char *get_tmpdir(Session *session __attribute__((unused)))
2558
2454
{
2559
2455
  if (opt_mysql_tmpdir)
2560
2456
    return (unsigned char *)opt_mysql_tmpdir;
2686
2582
  
2687
2583
  SYNOPSIS
2688
2584
    enumerate_sys_vars()
2689
 
    thd         current thread
 
2585
    session         current thread
2690
2586
    sorted      If TRUE, the system variables should be sorted
2691
2587
  
2692
2588
  RETURN VALUES
2694
2590
    NULL        FAILURE
2695
2591
*/
2696
2592
 
2697
 
SHOW_VAR* enumerate_sys_vars(THD *thd, bool sorted)
 
2593
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted)
2698
2594
{
2699
2595
  int count= system_variable_hash.records, i;
2700
2596
  int fixed_count= fixed_show_vars.elements;
2701
2597
  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2702
 
  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
 
2598
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2703
2599
 
2704
2600
  if (result)
2705
2601
  {
2835
2731
  This should ensure that in all normal cases none all or variables are
2836
2732
  updated.
2837
2733
 
2838
 
  @param THD            Thread id
 
2734
  @param Session                Thread id
2839
2735
  @param var_list       List of variables to update
2840
2736
 
2841
2737
  @retval
2846
2742
    -1  ERROR, message not sent
2847
2743
*/
2848
2744
 
2849
 
int sql_set_variables(THD *thd, List<set_var_base> *var_list)
 
2745
int sql_set_variables(Session *session, List<set_var_base> *var_list)
2850
2746
{
2851
2747
  int error;
2852
2748
  List_iterator_fast<set_var_base> it(*var_list);
2854
2750
  set_var_base *var;
2855
2751
  while ((var=it++))
2856
2752
  {
2857
 
    if ((error= var->check(thd)))
 
2753
    if ((error= var->check(session)))
2858
2754
      goto err;
2859
2755
  }
2860
 
  if (!(error= test(thd->is_error())))
 
2756
  if (!(error= test(session->is_error())))
2861
2757
  {
2862
2758
    it.rewind();
2863
2759
    while ((var= it++))
2864
 
      error|= var->update(thd);         // Returns 0, -1 or 1
 
2760
      error|= var->update(session);         // Returns 0, -1 or 1
2865
2761
  }
2866
2762
 
2867
2763
err:
2868
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
2764
  free_underlaid_joins(session, &session->lex->select_lex);
2869
2765
  return(error);
2870
2766
}
2871
2767
 
2903
2799
  Functions to handle SET mysql_internal_variable=const_expr
2904
2800
*****************************************************************************/
2905
2801
 
2906
 
int set_var::check(THD *thd)
 
2802
int set_var::check(Session *session)
2907
2803
{
2908
2804
  if (var->is_readonly())
2909
2805
  {
2928
2824
  }
2929
2825
 
2930
2826
  if ((!value->fixed &&
2931
 
       value->fix_fields(thd, &value)) || value->check_cols(1))
 
2827
       value->fix_fields(session, &value)) || value->check_cols(1))
2932
2828
    return -1;
2933
2829
  if (var->check_update_type(value->result_type()))
2934
2830
  {
2935
2831
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
2936
2832
    return -1;
2937
2833
  }
2938
 
  return var->check(thd, this) ? -1 : 0;
 
2834
  return var->check(session, this) ? -1 : 0;
2939
2835
}
2940
2836
 
2941
2837
/**
2942
2838
  Update variable
2943
2839
 
2944
 
  @param   thd    thread handler
 
2840
  @param   session    thread handler
2945
2841
  @returns 0|1    ok or ERROR
2946
2842
 
2947
2843
  @note ERROR can be only due to abnormal operations involving
2950
2846
  Consider set_var::check() method if there is a need to return
2951
2847
  an error due to logics.
2952
2848
*/
2953
 
int set_var::update(THD *thd)
 
2849
int set_var::update(Session *session)
2954
2850
{
2955
2851
  if (!value)
2956
 
    var->set_default(thd, type);
2957
 
  else if (var->update(thd, this))
 
2852
    var->set_default(session, type);
 
2853
  else if (var->update(session, this))
2958
2854
    return -1;                          // should never happen
2959
2855
  if (var->after_update)
2960
 
    (*var->after_update)(thd, type);
 
2856
    (*var->after_update)(session, type);
2961
2857
  return 0;
2962
2858
}
2963
2859
 
2966
2862
  Functions to handle SET @user_variable=const_expr
2967
2863
*****************************************************************************/
2968
2864
 
2969
 
int set_var_user::check(THD *thd)
 
2865
int set_var_user::check(Session *session)
2970
2866
{
2971
2867
  /*
2972
2868
    Item_func_set_user_var can't substitute something else on its place =>
2973
2869
    0 can be passed as last argument (reference on item)
2974
2870
  */
2975
 
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
 
2871
  return (user_var_item->fix_fields(session, (Item**) 0) ||
2976
2872
          user_var_item->check(0)) ? -1 : 0;
2977
2873
}
2978
2874
 
2979
2875
 
2980
 
int set_var_user::update(THD *thd __attribute__((unused)))
 
2876
int set_var_user::update(Session *session __attribute__((unused)))
2981
2877
{
2982
2878
  if (user_var_item->update())
2983
2879
  {
2994
2890
 
2995
2891
/* Based upon sys_var::check_enum() */
2996
2892
 
2997
 
bool sys_var_thd_storage_engine::check(THD *thd, set_var *var)
 
2893
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
2998
2894
{
2999
2895
  char buff[STRING_BUFFER_USUAL_SIZE];
3000
2896
  const char *value;
3008
2904
    if (!(res=var->value->val_str(&str)) ||
3009
2905
        !(engine_name.str= (char *)res->ptr()) ||
3010
2906
        !(engine_name.length= res->length()) ||
3011
 
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
 
2907
        !(var->save_result.plugin= ha_resolve_by_name(session, &engine_name)) ||
3012
2908
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
3013
2909
    {
3014
2910
      value= res ? res->c_ptr() : "NULL";
3024
2920
}
3025
2921
 
3026
2922
 
3027
 
unsigned char *sys_var_thd_storage_engine::value_ptr(THD *thd, enum_var_type type,
 
2923
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, enum_var_type type,
3028
2924
                                             LEX_STRING *base __attribute__((unused)))
3029
2925
{
3030
2926
  unsigned char* result;
3031
2927
  handlerton *hton;
3032
2928
  LEX_STRING *engine_name;
3033
 
  plugin_ref plugin= thd->variables.*offset;
 
2929
  plugin_ref plugin= session->variables.*offset;
3034
2930
  if (type == OPT_GLOBAL)
3035
 
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
 
2931
    plugin= my_plugin_lock(session, &(global_system_variables.*offset));
3036
2932
  hton= plugin_data(plugin, handlerton*);
3037
2933
  engine_name= &hton2plugin[hton->slot]->name;
3038
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
2934
  result= (unsigned char *) session->strmake(engine_name->str, engine_name->length);
3039
2935
  if (type == OPT_GLOBAL)
3040
 
    plugin_unlock(thd, plugin);
 
2936
    plugin_unlock(session, plugin);
3041
2937
  return result;
3042
2938
}
3043
2939
 
3044
2940
 
3045
 
void sys_var_thd_storage_engine::set_default(THD *thd, enum_var_type type)
 
2941
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
3046
2942
{
3047
2943
  plugin_ref old_value, new_value, *value;
3048
2944
  if (type == OPT_GLOBAL)
3052
2948
  }
3053
2949
  else
3054
2950
  {
3055
 
    value= &(thd->variables.*offset);
 
2951
    value= &(session->variables.*offset);
3056
2952
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
3057
2953
  }
3058
2954
  assert(new_value);
3062
2958
}
3063
2959
 
3064
2960
 
3065
 
bool sys_var_thd_storage_engine::update(THD *thd, set_var *var)
 
2961
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
3066
2962
{
3067
2963
  plugin_ref *value= &(global_system_variables.*offset), old_value;
3068
2964
   if (var->type != OPT_GLOBAL)
3069
 
     value= &(thd->variables.*offset);
 
2965
     value= &(session->variables.*offset);
3070
2966
  old_value= *value;
3071
2967
  if (old_value != var->save_result.plugin)
3072
2968
  {
3077
2973
}
3078
2974
 
3079
2975
bool
3080
 
sys_var_thd_optimizer_switch::
3081
 
symbolic_mode_representation(THD *thd, uint64_t val, LEX_STRING *rep)
 
2976
sys_var_session_optimizer_switch::
 
2977
symbolic_mode_representation(Session *session, uint64_t val, LEX_STRING *rep)
3082
2978
{
3083
2979
  char buff[STRING_BUFFER_USUAL_SIZE*8];
3084
2980
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
3098
2994
  if (tmp.length())
3099
2995
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
3100
2996
 
3101
 
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
 
2997
  rep->str= session->strmake(tmp.ptr(), tmp.length());
3102
2998
 
3103
2999
  rep->length= rep->str ? tmp.length() : 0;
3104
3000
 
3106
3002
}
3107
3003
 
3108
3004
 
3109
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(THD *thd, enum_var_type type,
 
3005
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session, enum_var_type type,
3110
3006
                                               LEX_STRING *base __attribute__((unused)))
3111
3007
{
3112
3008
  LEX_STRING opts;
3113
3009
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3114
 
                  thd->variables.*offset);
3115
 
  (void) symbolic_mode_representation(thd, val, &opts);
 
3010
                  session->variables.*offset);
 
3011
  (void) symbolic_mode_representation(session, val, &opts);
3116
3012
  return (unsigned char *) opts.str;
3117
3013
}
3118
3014
 
3119
3015
 
3120
 
void sys_var_thd_optimizer_switch::set_default(THD *thd, enum_var_type type)
 
3016
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3121
3017
{
3122
3018
  if (type == OPT_GLOBAL)
3123
3019
    global_system_variables.*offset= 0;
3124
3020
  else
3125
 
    thd->variables.*offset= global_system_variables.*offset;
 
3021
    session->variables.*offset= global_system_variables.*offset;
3126
3022
}
3127
3023
 
3128
3024
 
3229
3125
}
3230
3126
 
3231
3127
 
3232
 
bool sys_var_opt_readonly::update(THD *thd, set_var *var)
 
3128
bool sys_var_opt_readonly::update(Session *session, set_var *var)
3233
3129
{
3234
3130
  bool result;
3235
3131
 
3236
3132
  /* Prevent self dead-lock */
3237
 
  if (thd->locked_tables || thd->active_transaction())
 
3133
  if (session->locked_tables || session->active_transaction())
3238
3134
  {
3239
3135
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3240
3136
    return(true);
3241
3137
  }
3242
3138
 
3243
 
  if (thd->global_read_lock)
 
3139
  if (session->global_read_lock)
3244
3140
  {
3245
3141
    /*
3246
3142
      This connection already holds the global read lock.
3248
3144
      - FLUSH TABLES WITH READ LOCK
3249
3145
      - SET GLOBAL READ_ONLY = 1
3250
3146
    */
3251
 
    result= sys_var_bool_ptr::update(thd, var);
 
3147
    result= sys_var_bool_ptr::update(session, var);
3252
3148
    return(result);
3253
3149
  }
3254
3150
 
3263
3159
    [3] prevents transactions from being committed.
3264
3160
  */
3265
3161
 
3266
 
  if (lock_global_read_lock(thd))
 
3162
  if (lock_global_read_lock(session))
3267
3163
    return(true);
3268
3164
 
3269
3165
  /*
3275
3171
    can cause to wait on a read lock, it's required for the client application
3276
3172
    to unlock everything, and acceptable for the server to wait on all locks.
3277
3173
  */
3278
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3174
  if ((result= close_cached_tables(session, NULL, false, true, true)) == true)
3279
3175
    goto end_with_read_lock;
3280
3176
 
3281
 
  if ((result= make_global_read_lock_block_commit(thd)) == true)
 
3177
  if ((result= make_global_read_lock_block_commit(session)) == true)
3282
3178
    goto end_with_read_lock;
3283
3179
 
3284
3180
  /* Change the opt_readonly system variable, safe because the lock is held */
3285
 
  result= sys_var_bool_ptr::update(thd, var);
 
3181
  result= sys_var_bool_ptr::update(session, var);
3286
3182
 
3287
3183
end_with_read_lock:
3288
3184
  /* Release the lock */
3289
 
  unlock_global_read_lock(thd);
 
3185
  unlock_global_read_lock(session);
3290
3186
  return(result);
3291
3187
}
3292
3188