~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

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

Show diffs side-by-side

added added

removed removed

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