~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/set_var.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 04:28:21 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020042821-rqqdrccuu8195k3y
Second pass of thd cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
87
87
static void sys_default_init_connect(Session*, enum_var_type type);
88
88
static bool sys_update_init_slave(Session*, set_var*);
89
89
static void sys_default_init_slave(Session*, enum_var_type type);
90
 
static bool set_option_bit(Session *thd, set_var *var);
91
 
static bool set_option_autocommit(Session *thd, set_var *var);
92
 
static int  check_log_update(Session *thd, set_var *var);
93
 
static int  check_pseudo_thread_id(Session *thd, set_var *var);
94
 
static void fix_low_priority_updates(Session *thd, enum_var_type type);
95
 
static int check_tx_isolation(Session *thd, set_var *var);
96
 
static void fix_tx_isolation(Session *thd, enum_var_type type);
97
 
static int check_completion_type(Session *thd, set_var *var);
98
 
static void fix_completion_type(Session *thd, enum_var_type type);
99
 
static void fix_net_read_timeout(Session *thd, enum_var_type type);
100
 
static void fix_net_write_timeout(Session *thd, enum_var_type type);
101
 
static void fix_net_retry_count(Session *thd, enum_var_type type);
102
 
static void fix_max_join_size(Session *thd, enum_var_type type);
103
 
static void fix_myisam_max_sort_file_size(Session *thd, enum_var_type type);
104
 
static void fix_max_binlog_size(Session *thd, enum_var_type type);
105
 
static void fix_max_relay_log_size(Session *thd, enum_var_type type);
106
 
static void fix_max_connections(Session *thd, enum_var_type type);
107
 
static void fix_thd_mem_root(Session *thd, enum_var_type type);
108
 
static void fix_trans_mem_root(Session *thd, enum_var_type type);
109
 
static void fix_server_id(Session *thd, 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
110
static uint64_t fix_unsigned(Session *, uint64_t, const struct my_option *);
111
 
static bool get_unsigned(Session *thd, set_var *var);
112
 
bool throw_bounds_warning(Session *thd, bool fixed, bool unsignd,
 
111
static bool get_unsigned(Session *session, set_var *var);
 
112
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
113
113
                          const char *name, int64_t val);
114
114
static KEY_CACHE *create_key_cache(const char *name, uint32_t length);
115
 
static unsigned char *get_error_count(Session *thd);
116
 
static unsigned char *get_warning_count(Session *thd);
117
 
static unsigned char *get_tmpdir(Session *thd);
 
115
static unsigned char *get_error_count(Session *session);
 
116
static unsigned char *get_warning_count(Session *session);
 
117
static unsigned char *get_tmpdir(Session *session);
118
118
 
119
119
/*
120
120
  Variable definition list
128
128
 
129
129
static sys_var_chain vars = { NULL, NULL };
130
130
 
131
 
static sys_var_thd_ulong
 
131
static sys_var_session_ulong
132
132
sys_auto_increment_increment(&vars, "auto_increment_increment",
133
133
                             &SV::auto_increment_increment, NULL, NULL,
134
134
                             sys_var::SESSION_VARIABLE_IN_BINLOG);
135
 
static sys_var_thd_ulong
 
135
static sys_var_session_ulong
136
136
sys_auto_increment_offset(&vars, "auto_increment_offset",
137
137
                          &SV::auto_increment_offset, NULL, NULL,
138
138
                          sys_var::SESSION_VARIABLE_IN_BINLOG);
140
140
static sys_var_const_str       sys_basedir(&vars, "basedir", mysql_home);
141
141
static sys_var_long_ptr sys_binlog_cache_size(&vars, "binlog_cache_size",
142
142
                                              &binlog_cache_size);
143
 
static sys_var_thd_binlog_format sys_binlog_format(&vars, "binlog_format",
 
143
static sys_var_session_binlog_format sys_binlog_format(&vars, "binlog_format",
144
144
                                            &SV::binlog_format);
145
 
static sys_var_thd_ulong        sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
 
145
static sys_var_session_ulong    sys_bulk_insert_buff_size(&vars, "bulk_insert_buffer_size",
146
146
                                                  &SV::bulk_insert_buff_size);
147
 
static sys_var_thd_ulong        sys_completion_type(&vars, "completion_type",
 
147
static sys_var_session_ulong    sys_completion_type(&vars, "completion_type",
148
148
                                         &SV::completion_type,
149
149
                                         check_completion_type,
150
150
                                         fix_completion_type);
177
177
sys_var_str             sys_init_slave(&vars, "init_slave", 0,
178
178
                                       sys_update_init_slave,
179
179
                                       sys_default_init_slave,0);
180
 
static sys_var_thd_ulong        sys_interactive_timeout(&vars, "interactive_timeout",
 
180
static sys_var_session_ulong    sys_interactive_timeout(&vars, "interactive_timeout",
181
181
                                                &SV::net_interactive_timeout);
182
 
static sys_var_thd_ulong        sys_join_buffer_size(&vars, "join_buffer_size",
 
182
static sys_var_session_ulong    sys_join_buffer_size(&vars, "join_buffer_size",
183
183
                                             &SV::join_buff_size);
184
184
static sys_var_key_buffer_size  sys_key_buffer_size(&vars, "key_buffer_size");
185
185
static sys_var_key_cache_long  sys_key_cache_block_size(&vars, "key_cache_block_size",
193
193
                                                              param_age_threshold));
194
194
static sys_var_bool_ptr sys_local_infile(&vars, "local_infile",
195
195
                                         &opt_local_infile);
196
 
static sys_var_thd_bool sys_low_priority_updates(&vars, "low_priority_updates",
 
196
static sys_var_session_bool     sys_low_priority_updates(&vars, "low_priority_updates",
197
197
                                                 &SV::low_priority_updates,
198
198
                                                 fix_low_priority_updates);
199
199
#ifndef TO_BE_DELETED   /* Alias for the low_priority_updates */
200
 
static sys_var_thd_bool sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
 
200
static sys_var_session_bool     sys_sql_low_priority_updates(&vars, "sql_low_priority_updates",
201
201
                                                     &SV::low_priority_updates,
202
202
                                                     fix_low_priority_updates);
203
203
#endif
204
 
static sys_var_thd_ulong        sys_max_allowed_packet(&vars, "max_allowed_packet",
 
204
static sys_var_session_ulong    sys_max_allowed_packet(&vars, "max_allowed_packet",
205
205
                                               &SV::max_allowed_packet);
206
206
static sys_var_long_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size",
207
207
                                                  &max_binlog_cache_size);
213
213
                                            fix_max_connections);
214
214
static sys_var_long_ptr sys_max_connect_errors(&vars, "max_connect_errors",
215
215
                                               &max_connect_errors);
216
 
static sys_var_thd_ulong        sys_max_error_count(&vars, "max_error_count",
 
216
static sys_var_session_ulong    sys_max_error_count(&vars, "max_error_count",
217
217
                                            &SV::max_error_count);
218
 
static sys_var_thd_uint64_t     sys_max_heap_table_size(&vars, "max_heap_table_size",
 
218
static sys_var_session_uint64_t sys_max_heap_table_size(&vars, "max_heap_table_size",
219
219
                                                &SV::max_heap_table_size);
220
 
static sys_var_thd_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
 
220
static sys_var_session_ulong sys_pseudo_thread_id(&vars, "pseudo_thread_id",
221
221
                                              &SV::pseudo_thread_id,
222
222
                                              check_pseudo_thread_id, 0,
223
223
                                              sys_var::SESSION_VARIABLE_IN_BINLOG);
224
 
static sys_var_thd_ha_rows      sys_max_join_size(&vars, "max_join_size",
 
224
static sys_var_session_ha_rows  sys_max_join_size(&vars, "max_join_size",
225
225
                                          &SV::max_join_size,
226
226
                                          fix_max_join_size);
227
 
static sys_var_thd_ulong        sys_max_seeks_for_key(&vars, "max_seeks_for_key",
 
227
static sys_var_session_ulong    sys_max_seeks_for_key(&vars, "max_seeks_for_key",
228
228
                                              &SV::max_seeks_for_key);
229
 
static sys_var_thd_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
 
229
static sys_var_session_ulong   sys_max_length_for_sort_data(&vars, "max_length_for_sort_data",
230
230
                                                 &SV::max_length_for_sort_data);
231
231
static sys_var_long_ptr sys_max_relay_log_size(&vars, "max_relay_log_size",
232
232
                                               &max_relay_log_size,
233
233
                                               fix_max_relay_log_size);
234
 
static sys_var_thd_ulong        sys_max_sort_length(&vars, "max_sort_length",
 
234
static sys_var_session_ulong    sys_max_sort_length(&vars, "max_sort_length",
235
235
                                            &SV::max_sort_length);
236
236
static sys_var_max_user_conn   sys_max_user_connections(&vars, "max_user_connections");
237
 
static sys_var_thd_ulong        sys_max_tmp_tables(&vars, "max_tmp_tables",
 
237
static sys_var_session_ulong    sys_max_tmp_tables(&vars, "max_tmp_tables",
238
238
                                           &SV::max_tmp_tables);
239
239
static sys_var_long_ptr sys_max_write_lock_count(&vars, "max_write_lock_count",
240
240
                                                 &max_write_lock_count);
241
 
static sys_var_thd_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
 
241
static sys_var_session_ulong       sys_min_examined_row_limit(&vars, "min_examined_row_limit",
242
242
                                                          &SV::min_examined_row_limit);
243
 
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);
244
 
static sys_var_thd_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
245
 
static sys_var_thd_ulong        sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
 
243
static sys_var_session_uint64_t sys_myisam_max_sort_file_size(&vars, "myisam_max_sort_file_size", &SV::myisam_max_sort_file_size, fix_myisam_max_sort_file_size, 1);
 
244
static sys_var_session_ulong       sys_myisam_repair_threads(&vars, "myisam_repair_threads", &SV::myisam_repair_threads);
 
245
static sys_var_session_ulong    sys_myisam_sort_buffer_size(&vars, "myisam_sort_buffer_size", &SV::myisam_sort_buff_size);
246
246
 
247
 
static sys_var_thd_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
 
247
static sys_var_session_enum         sys_myisam_stats_method(&vars, "myisam_stats_method",
248
248
                                                &SV::myisam_stats_method,
249
249
                                                &myisam_stats_method_typelib,
250
250
                                                NULL);
251
 
static sys_var_thd_ulong        sys_net_buffer_length(&vars, "net_buffer_length",
 
251
static sys_var_session_ulong    sys_net_buffer_length(&vars, "net_buffer_length",
252
252
                                              &SV::net_buffer_length);
253
 
static sys_var_thd_ulong        sys_net_read_timeout(&vars, "net_read_timeout",
 
253
static sys_var_session_ulong    sys_net_read_timeout(&vars, "net_read_timeout",
254
254
                                             &SV::net_read_timeout,
255
255
                                             0, fix_net_read_timeout);
256
 
static sys_var_thd_ulong        sys_net_write_timeout(&vars, "net_write_timeout",
 
256
static sys_var_session_ulong    sys_net_write_timeout(&vars, "net_write_timeout",
257
257
                                              &SV::net_write_timeout,
258
258
                                              0, fix_net_write_timeout);
259
 
static sys_var_thd_ulong        sys_net_retry_count(&vars, "net_retry_count",
 
259
static sys_var_session_ulong    sys_net_retry_count(&vars, "net_retry_count",
260
260
                                            &SV::net_retry_count,
261
261
                                            0, fix_net_retry_count);
262
 
static sys_var_thd_bool sys_new_mode(&vars, "new", &SV::new_mode);
 
262
static sys_var_session_bool     sys_new_mode(&vars, "new", &SV::new_mode);
263
263
static sys_var_bool_ptr_readonly sys_old_mode(&vars, "old",
264
264
                                       &global_system_variables.old_mode);
265
265
/* these two cannot be static */
266
 
sys_var_thd_bool                sys_old_alter_table(&vars, "old_alter_table",
 
266
sys_var_session_bool                sys_old_alter_table(&vars, "old_alter_table",
267
267
                                            &SV::old_alter_table);
268
 
static sys_var_thd_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
 
268
static sys_var_session_ulong        sys_optimizer_prune_level(&vars, "optimizer_prune_level",
269
269
                                                  &SV::optimizer_prune_level);
270
 
static sys_var_thd_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
 
270
static sys_var_session_ulong        sys_optimizer_search_depth(&vars, "optimizer_search_depth",
271
271
                                                   &SV::optimizer_search_depth);
272
272
 
273
273
const char *optimizer_use_mrr_names[] = {"auto", "force", "disable", NULL};
276
276
  optimizer_use_mrr_names, NULL
277
277
};
278
278
 
279
 
static sys_var_thd_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
 
279
static sys_var_session_enum        sys_optimizer_use_mrr(&vars, "optimizer_use_mrr",
280
280
                                              &SV::optimizer_use_mrr,
281
281
                                              &optimizer_use_mrr_typelib,
282
282
                                              NULL);
283
283
 
284
 
static sys_var_thd_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
 
284
static sys_var_session_ulong        sys_preload_buff_size(&vars, "preload_buffer_size",
285
285
                                              &SV::preload_buff_size);
286
 
static sys_var_thd_ulong        sys_read_buff_size(&vars, "read_buffer_size",
 
286
static sys_var_session_ulong    sys_read_buff_size(&vars, "read_buffer_size",
287
287
                                           &SV::read_buff_size);
288
288
static sys_var_opt_readonly     sys_readonly(&vars, "read_only", &opt_readonly);
289
 
static sys_var_thd_ulong        sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
 
289
static sys_var_session_ulong    sys_read_rnd_buff_size(&vars, "read_rnd_buffer_size",
290
290
                                               &SV::read_rnd_buff_size);
291
 
static sys_var_thd_ulong        sys_div_precincrement(&vars, "div_precision_increment",
 
291
static sys_var_session_ulong    sys_div_precincrement(&vars, "div_precision_increment",
292
292
                                              &SV::div_precincrement);
293
293
 
294
 
static sys_var_thd_ulong        sys_range_alloc_block_size(&vars, "range_alloc_block_size",
 
294
static sys_var_session_ulong    sys_range_alloc_block_size(&vars, "range_alloc_block_size",
295
295
                                                   &SV::range_alloc_block_size);
296
 
static sys_var_thd_ulong        sys_query_alloc_block_size(&vars, "query_alloc_block_size",
 
296
static sys_var_session_ulong    sys_query_alloc_block_size(&vars, "query_alloc_block_size",
297
297
                                                   &SV::query_alloc_block_size,
298
 
                                                   0, fix_thd_mem_root);
299
 
static sys_var_thd_ulong        sys_query_prealloc_size(&vars, "query_prealloc_size",
 
298
                                                   0, fix_session_mem_root);
 
299
static sys_var_session_ulong    sys_query_prealloc_size(&vars, "query_prealloc_size",
300
300
                                                &SV::query_prealloc_size,
301
 
                                                0, fix_thd_mem_root);
 
301
                                                0, fix_session_mem_root);
302
302
static sys_var_readonly        sys_tmpdir(&vars, "tmpdir", OPT_GLOBAL, SHOW_CHAR, get_tmpdir);
303
 
static sys_var_thd_ulong        sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
 
303
static sys_var_session_ulong    sys_trans_alloc_block_size(&vars, "transaction_alloc_block_size",
304
304
                                                   &SV::trans_alloc_block_size,
305
305
                                                   0, fix_trans_mem_root);
306
 
static sys_var_thd_ulong        sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
 
306
static sys_var_session_ulong    sys_trans_prealloc_size(&vars, "transaction_prealloc_size",
307
307
                                                &SV::trans_prealloc_size,
308
308
                                                0, fix_trans_mem_root);
309
309
 
321
321
                                              0);
322
322
static sys_var_long_ptr sys_slow_launch_time(&vars, "slow_launch_time",
323
323
                                             &slow_launch_time);
324
 
static sys_var_thd_ulong        sys_sort_buffer(&vars, "sort_buffer_size",
 
324
static sys_var_session_ulong    sys_sort_buffer(&vars, "sort_buffer_size",
325
325
                                        &SV::sortbuff_size);
326
326
/*
327
327
  sql_mode should *not* have binlog_mode=SESSION_VARIABLE_IN_BINLOG:
329
329
  MODE_NO_DIR_IN_CREATE variable, so slave's value differs from
330
330
  master's (see log_event.cc: Query_log_event::do_apply_event()).
331
331
*/
332
 
static sys_var_thd_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
 
332
static sys_var_session_optimizer_switch   sys_optimizer_switch(&vars, "optimizer_switch",
333
333
                                     &SV::optimizer_switch);
334
334
 
335
 
static sys_var_thd_storage_engine sys_storage_engine(&vars, "storage_engine",
 
335
static sys_var_session_storage_engine sys_storage_engine(&vars, "storage_engine",
336
336
                                       &SV::table_plugin);
337
337
static sys_var_const_str        sys_system_time_zone(&vars, "system_time_zone",
338
338
                                             system_time_zone);
346
346
                                              &thread_cache_size);
347
347
sys_var_long_ptr        sys_thread_pool_size(&vars, "thread_pool_size",
348
348
                                              &thread_pool_size);
349
 
static sys_var_thd_enum sys_tx_isolation(&vars, "tx_isolation",
 
349
static sys_var_session_enum     sys_tx_isolation(&vars, "tx_isolation",
350
350
                                         &SV::tx_isolation,
351
351
                                         &tx_isolation_typelib,
352
352
                                         fix_tx_isolation,
353
353
                                         check_tx_isolation);
354
 
static sys_var_thd_uint64_t     sys_tmp_table_size(&vars, "tmp_table_size",
 
354
static sys_var_session_uint64_t sys_tmp_table_size(&vars, "tmp_table_size",
355
355
                                           &SV::tmp_table_size);
356
356
static sys_var_bool_ptr  sys_timed_mutexes(&vars, "timed_mutexes", &timed_mutexes);
357
357
static sys_var_const_str        sys_version(&vars, "version", server_version);
361
361
                                                    MACHINE_TYPE);
362
362
static sys_var_const_str        sys_version_compile_os(&vars, "version_compile_os",
363
363
                                               SYSTEM_TYPE);
364
 
static sys_var_thd_ulong        sys_net_wait_timeout(&vars, "wait_timeout",
 
364
static sys_var_session_ulong    sys_net_wait_timeout(&vars, "wait_timeout",
365
365
                                             &SV::net_wait_timeout);
366
366
 
367
367
/* Condition pushdown to storage engine */
368
 
static sys_var_thd_bool
 
368
static sys_var_session_bool
369
369
sys_engine_condition_pushdown(&vars, "engine_condition_pushdown",
370
370
                              &SV::engine_condition_pushdown);
371
371
 
372
372
/* Time/date/datetime formats */
373
373
 
374
 
static sys_var_thd_date_time_format sys_time_format(&vars, "time_format",
 
374
static sys_var_session_date_time_format sys_time_format(&vars, "time_format",
375
375
                                             &SV::time_format,
376
376
                                             DRIZZLE_TIMESTAMP_TIME);
377
 
static sys_var_thd_date_time_format sys_date_format(&vars, "date_format",
 
377
static sys_var_session_date_time_format sys_date_format(&vars, "date_format",
378
378
                                             &SV::date_format,
379
379
                                             DRIZZLE_TIMESTAMP_DATE);
380
 
static sys_var_thd_date_time_format sys_datetime_format(&vars, "datetime_format",
 
380
static sys_var_session_date_time_format sys_datetime_format(&vars, "datetime_format",
381
381
                                                 &SV::datetime_format,
382
382
                                                 DRIZZLE_TIMESTAMP_DATETIME);
383
383
 
384
384
/* Variables that are bits in Session */
385
385
 
386
 
sys_var_thd_bit sys_autocommit(&vars, "autocommit", 0,
 
386
sys_var_session_bit sys_autocommit(&vars, "autocommit", 0,
387
387
                               set_option_autocommit,
388
388
                               OPTION_NOT_AUTOCOMMIT,
389
389
                               1);
390
 
static sys_var_thd_bit  sys_big_selects(&vars, "sql_big_selects", 0,
 
390
static sys_var_session_bit      sys_big_selects(&vars, "sql_big_selects", 0,
391
391
                                        set_option_bit,
392
392
                                        OPTION_BIG_SELECTS);
393
 
static sys_var_thd_bit  sys_log_binlog(&vars, "sql_log_bin",
 
393
static sys_var_session_bit      sys_log_binlog(&vars, "sql_log_bin",
394
394
                                       check_log_update,
395
395
                                       set_option_bit,
396
396
                                       OPTION_BIN_LOG);
397
 
static sys_var_thd_bit  sys_sql_warnings(&vars, "sql_warnings", 0,
 
397
static sys_var_session_bit      sys_sql_warnings(&vars, "sql_warnings", 0,
398
398
                                         set_option_bit,
399
399
                                         OPTION_WARNINGS);
400
 
static sys_var_thd_bit  sys_sql_notes(&vars, "sql_notes", 0,
 
400
static sys_var_session_bit      sys_sql_notes(&vars, "sql_notes", 0,
401
401
                                         set_option_bit,
402
402
                                         OPTION_SQL_NOTES);
403
 
static sys_var_thd_bit  sys_safe_updates(&vars, "sql_safe_updates", 0,
 
403
static sys_var_session_bit      sys_safe_updates(&vars, "sql_safe_updates", 0,
404
404
                                         set_option_bit,
405
405
                                         OPTION_SAFE_UPDATES);
406
 
static sys_var_thd_bit  sys_buffer_results(&vars, "sql_buffer_result", 0,
 
406
static sys_var_session_bit      sys_buffer_results(&vars, "sql_buffer_result", 0,
407
407
                                           set_option_bit,
408
408
                                           OPTION_BUFFER_RESULT);
409
 
static sys_var_thd_bit  sys_quote_show_create(&vars, "sql_quote_show_create", 0,
 
409
static sys_var_session_bit      sys_quote_show_create(&vars, "sql_quote_show_create", 0,
410
410
                                              set_option_bit,
411
411
                                              OPTION_QUOTE_SHOW_CREATE);
412
 
static sys_var_thd_bit  sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
 
412
static sys_var_session_bit      sys_foreign_key_checks(&vars, "foreign_key_checks", 0,
413
413
                                               set_option_bit,
414
414
                                               OPTION_NO_FOREIGN_KEY_CHECKS,
415
415
                                               1, sys_var::SESSION_VARIABLE_IN_BINLOG);
416
 
static sys_var_thd_bit  sys_unique_checks(&vars, "unique_checks", 0,
 
416
static sys_var_session_bit      sys_unique_checks(&vars, "unique_checks", 0,
417
417
                                          set_option_bit,
418
418
                                          OPTION_RELAXED_UNIQUE_CHECKS,
419
419
                                          1,
420
420
                                          sys_var::SESSION_VARIABLE_IN_BINLOG);
421
421
/* Local state variables */
422
422
 
423
 
static sys_var_thd_ha_rows      sys_select_limit(&vars, "sql_select_limit",
 
423
static sys_var_session_ha_rows  sys_select_limit(&vars, "sql_select_limit",
424
424
                                                 &SV::select_limit);
425
425
static sys_var_timestamp sys_timestamp(&vars, "timestamp",
426
426
                                       sys_var::SESSION_VARIABLE_IN_BINLOG);
434
434
static sys_var_last_insert_id
435
435
sys_identity(&vars, "identity", sys_var::SESSION_VARIABLE_IN_BINLOG);
436
436
 
437
 
static sys_var_thd_lc_time_names
 
437
static sys_var_session_lc_time_names
438
438
sys_lc_time_names(&vars, "lc_time_names", sys_var::SESSION_VARIABLE_IN_BINLOG);
439
439
 
440
440
/*
471
471
static sys_var_rand_seed2 sys_rand_seed2(&vars, "rand_seed2",
472
472
                                         sys_var::SESSION_VARIABLE_IN_BINLOG);
473
473
 
474
 
static sys_var_thd_ulong        sys_default_week_format(&vars, "default_week_format",
 
474
static sys_var_session_ulong        sys_default_week_format(&vars, "default_week_format",
475
475
                                                        &SV::default_week_format);
476
476
 
477
 
sys_var_thd_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
 
477
sys_var_session_ulong               sys_group_concat_max_len(&vars, "group_concat_max_len",
478
478
                                                         &SV::group_concat_max_len);
479
479
 
480
 
sys_var_thd_time_zone sys_time_zone(&vars, "time_zone",
 
480
sys_var_session_time_zone sys_time_zone(&vars, "time_zone",
481
481
                                    sys_var::SESSION_VARIABLE_IN_BINLOG);
482
482
 
483
483
/* Global read-only variable containing hostname */
487
487
static sys_var_const_str_ptr    sys_repl_report_user(&vars, "report_user", &report_user);
488
488
static sys_var_const_str_ptr    sys_repl_report_password(&vars, "report_password", &report_password);
489
489
 
490
 
static unsigned char *slave_get_report_port(Session *thd)
 
490
static unsigned char *slave_get_report_port(Session *session)
491
491
{
492
 
  thd->sys_var_tmp.long_value= report_port;
493
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
492
  session->sys_var_tmp.long_value= report_port;
 
493
  return (unsigned char*) &session->sys_var_tmp.long_value;
494
494
}
495
495
 
496
496
static sys_var_readonly    sys_repl_report_port(&vars, "report_port", OPT_GLOBAL, SHOW_INT, slave_get_report_port);
497
497
 
498
 
sys_var_thd_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
 
498
sys_var_session_bool  sys_keep_files_on_create(&vars, "keep_files_on_create", 
499
499
                                           &SV::keep_files_on_create);
500
500
/* Read only variables */
501
501
 
528
528
};
529
529
 
530
530
 
531
 
bool sys_var::check(Session *thd __attribute__((unused)), set_var *var)
 
531
bool sys_var::check(Session *session __attribute__((unused)), set_var *var)
532
532
{
533
533
  var->save_result.uint64_t_value= var->value->val_int();
534
534
  return 0;
535
535
}
536
536
 
537
 
bool sys_var_str::check(Session *thd, set_var *var)
 
537
bool sys_var_str::check(Session *session, set_var *var)
538
538
{
539
539
  int res;
540
540
  if (!check_func)
541
541
    return 0;
542
542
 
543
 
  if ((res=(*check_func)(thd, var)) < 0)
 
543
  if ((res=(*check_func)(session, var)) < 0)
544
544
    my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0),
545
545
             name, var->value->str_value.ptr());
546
546
  return res;
582
582
}
583
583
 
584
584
 
585
 
static bool sys_update_init_connect(Session *thd __attribute__((unused)), set_var *var)
 
585
static bool sys_update_init_connect(Session *session __attribute__((unused)), set_var *var)
586
586
{
587
587
  return update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, var);
588
588
}
589
589
 
590
590
 
591
 
static void sys_default_init_connect(Session* thd __attribute__((unused)),
 
591
static void sys_default_init_connect(Session* session __attribute__((unused)),
592
592
                                     enum_var_type type __attribute__((unused)))
593
593
{
594
594
  update_sys_var_str(&sys_init_connect, &LOCK_sys_init_connect, 0);
595
595
}
596
596
 
597
597
 
598
 
static bool sys_update_init_slave(Session *thd __attribute__((unused)),
 
598
static bool sys_update_init_slave(Session *session __attribute__((unused)),
599
599
                                  set_var *var)
600
600
{
601
601
  return update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, var);
602
602
}
603
603
 
604
604
 
605
 
static void sys_default_init_slave(Session* thd __attribute__((unused)),
 
605
static void sys_default_init_slave(Session* session __attribute__((unused)),
606
606
                                   enum_var_type type __attribute__((unused)))
607
607
{
608
608
  update_sys_var_str(&sys_init_slave, &LOCK_sys_init_slave, 0);
614
614
  used lock type.
615
615
*/
616
616
 
617
 
static void fix_low_priority_updates(Session *thd, enum_var_type type)
 
617
static void fix_low_priority_updates(Session *session, enum_var_type type)
618
618
{
619
619
  if (type == OPT_GLOBAL)
620
620
    thr_upgraded_concurrent_insert_lock= 
621
621
      (global_system_variables.low_priority_updates ?
622
622
       TL_WRITE_LOW_PRIORITY : TL_WRITE);
623
623
  else
624
 
    thd->update_lock_default= (thd->variables.low_priority_updates ?
 
624
    session->update_lock_default= (session->variables.low_priority_updates ?
625
625
                               TL_WRITE_LOW_PRIORITY : TL_WRITE);
626
626
}
627
627
 
628
628
 
629
629
static void
630
 
fix_myisam_max_sort_file_size(Session *thd __attribute__((unused)),
 
630
fix_myisam_max_sort_file_size(Session *session __attribute__((unused)),
631
631
                              enum_var_type type __attribute__((unused)))
632
632
{
633
633
  myisam_max_temp_length=
638
638
  Set the OPTION_BIG_SELECTS flag if max_join_size == HA_POS_ERROR.
639
639
*/
640
640
 
641
 
static void fix_max_join_size(Session *thd, enum_var_type type)
 
641
static void fix_max_join_size(Session *session, enum_var_type type)
642
642
{
643
643
  if (type != OPT_GLOBAL)
644
644
  {
645
 
    if (thd->variables.max_join_size == HA_POS_ERROR)
646
 
      thd->options|= OPTION_BIG_SELECTS;
 
645
    if (session->variables.max_join_size == HA_POS_ERROR)
 
646
      session->options|= OPTION_BIG_SELECTS;
647
647
    else
648
 
      thd->options&= ~OPTION_BIG_SELECTS;
 
648
      session->options&= ~OPTION_BIG_SELECTS;
649
649
  }
650
650
}
651
651
 
654
654
  Can't change the 'next' tx_isolation while we are already in
655
655
  a transaction
656
656
*/
657
 
static int check_tx_isolation(Session *thd, set_var *var)
 
657
static int check_tx_isolation(Session *session, set_var *var)
658
658
{
659
 
  if (var->type == OPT_DEFAULT && (thd->server_status & SERVER_STATUS_IN_TRANS))
 
659
  if (var->type == OPT_DEFAULT && (session->server_status & SERVER_STATUS_IN_TRANS))
660
660
  {
661
661
    my_error(ER_CANT_CHANGE_TX_ISOLATION, MYF(0));
662
662
    return 1;
668
668
  If one doesn't use the SESSION modifier, the isolation level
669
669
  is only active for the next command.
670
670
*/
671
 
static void fix_tx_isolation(Session *thd, enum_var_type type)
 
671
static void fix_tx_isolation(Session *session, enum_var_type type)
672
672
{
673
673
  if (type == OPT_SESSION)
674
 
    thd->session_tx_isolation= ((enum_tx_isolation)
675
 
                                thd->variables.tx_isolation);
 
674
    session->session_tx_isolation= ((enum_tx_isolation)
 
675
                                session->variables.tx_isolation);
676
676
}
677
677
 
678
 
static void fix_completion_type(Session *thd __attribute__((unused)),
 
678
static void fix_completion_type(Session *session __attribute__((unused)),
679
679
                                enum_var_type type __attribute__((unused))) {}
680
680
 
681
 
static int check_completion_type(Session *thd __attribute__((unused)),
 
681
static int check_completion_type(Session *session __attribute__((unused)),
682
682
                                 set_var *var)
683
683
{
684
684
  int64_t val= var->value->val_int();
696
696
  If we are changing the thread variable, we have to copy it to NET too
697
697
*/
698
698
 
699
 
static void fix_net_read_timeout(Session *thd, enum_var_type type)
700
 
{
701
 
  if (type != OPT_GLOBAL)
702
 
    my_net_set_read_timeout(&thd->net, thd->variables.net_read_timeout);
703
 
}
704
 
 
705
 
 
706
 
static void fix_net_write_timeout(Session *thd, enum_var_type type)
707
 
{
708
 
  if (type != OPT_GLOBAL)
709
 
    my_net_set_write_timeout(&thd->net, thd->variables.net_write_timeout);
710
 
}
711
 
 
712
 
static void fix_net_retry_count(Session *thd, enum_var_type type)
713
 
{
714
 
  if (type != OPT_GLOBAL)
715
 
    thd->net.retry_count=thd->variables.net_retry_count;
716
 
}
717
 
 
718
 
 
719
 
extern void fix_delay_key_write(Session *thd __attribute__((unused)),
 
699
static void fix_net_read_timeout(Session *session, enum_var_type type)
 
700
{
 
701
  if (type != OPT_GLOBAL)
 
702
    my_net_set_read_timeout(&session->net, session->variables.net_read_timeout);
 
703
}
 
704
 
 
705
 
 
706
static void fix_net_write_timeout(Session *session, enum_var_type type)
 
707
{
 
708
  if (type != OPT_GLOBAL)
 
709
    my_net_set_write_timeout(&session->net, session->variables.net_write_timeout);
 
710
}
 
711
 
 
712
static void fix_net_retry_count(Session *session, enum_var_type type)
 
713
{
 
714
  if (type != OPT_GLOBAL)
 
715
    session->net.retry_count=session->variables.net_retry_count;
 
716
}
 
717
 
 
718
 
 
719
extern void fix_delay_key_write(Session *session __attribute__((unused)),
720
720
                                enum_var_type type __attribute__((unused)))
721
721
{
722
722
  switch ((enum_delay_key_write) delay_key_write_options) {
733
733
  }
734
734
}
735
735
 
736
 
bool sys_var_set::update(Session *thd __attribute__((unused)),
 
736
bool sys_var_set::update(Session *session __attribute__((unused)),
737
737
                         set_var *var)
738
738
{
739
739
  *value= var->save_result.ulong_value;
740
740
  return 0;
741
741
}
742
742
 
743
 
unsigned char *sys_var_set::value_ptr(Session *thd,
 
743
unsigned char *sys_var_set::value_ptr(Session *session,
744
744
                              enum_var_type type __attribute__((unused)),
745
745
                              LEX_STRING *base __attribute__((unused)))
746
746
{
762
762
 
763
763
  if ((length= tmp.length()))
764
764
    length--;
765
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
765
  return (unsigned char*) session->strmake(tmp.ptr(), length);
766
766
}
767
767
 
768
 
void sys_var_set_slave_mode::set_default(Session *thd __attribute__((unused)),
 
768
void sys_var_set_slave_mode::set_default(Session *session __attribute__((unused)),
769
769
                                         enum_var_type type __attribute__((unused)))
770
770
{
771
771
  slave_exec_mode_options= 0;
772
772
  bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
773
773
}
774
774
 
775
 
bool sys_var_set_slave_mode::check(Session *thd, set_var *var)
 
775
bool sys_var_set_slave_mode::check(Session *session, set_var *var)
776
776
{
777
 
  bool rc=  sys_var_set::check(thd, var);
 
777
  bool rc=  sys_var_set::check(session, var);
778
778
  if (!rc &&
779
779
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_STRICT) == 1 &&
780
780
      bit_is_set(var->save_result.ulong_value, SLAVE_EXEC_MODE_IDEMPOTENT) == 1)
785
785
  return rc;
786
786
}
787
787
 
788
 
bool sys_var_set_slave_mode::update(Session *thd, set_var *var)
 
788
bool sys_var_set_slave_mode::update(Session *session, set_var *var)
789
789
{
790
790
  bool rc;
791
791
  pthread_mutex_lock(&LOCK_global_system_variables);
792
 
  rc= sys_var_set::update(thd, var);
 
792
  rc= sys_var_set::update(session, var);
793
793
  pthread_mutex_unlock(&LOCK_global_system_variables);
794
794
  return rc;
795
795
}
807
807
    bit_do_set(slave_exec_mode_options, SLAVE_EXEC_MODE_STRICT);
808
808
}
809
809
 
810
 
bool sys_var_thd_binlog_format::is_readonly() const
 
810
bool sys_var_session_binlog_format::is_readonly() const
811
811
{
812
812
  /*
813
813
    Under certain circumstances, the variable is read-only (unchangeable):
814
814
  */
815
 
  Session *thd= current_thd;
 
815
  Session *session= current_session;
816
816
  /*
817
817
    If RBR and open temporary tables, their CREATE TABLE may not be in the
818
818
    binlog, so we can't toggle to SBR in this connection.
824
824
    If we don't have row-based replication compiled in, the variable
825
825
    is always read-only.
826
826
  */
827
 
  if ((thd->variables.binlog_format == BINLOG_FORMAT_ROW) &&
828
 
      thd->temporary_tables)
 
827
  if ((session->variables.binlog_format == BINLOG_FORMAT_ROW) &&
 
828
      session->temporary_tables)
829
829
  {
830
830
    my_error(ER_TEMP_TABLE_PREVENTS_SWITCH_OUT_OF_RBR, MYF(0));
831
831
    return 1;
832
832
  }
833
833
  
834
 
  return sys_var_thd_enum::is_readonly();
 
834
  return sys_var_session_enum::is_readonly();
835
835
}
836
836
 
837
837
 
838
 
void fix_binlog_format_after_update(Session *thd,
 
838
void fix_binlog_format_after_update(Session *session,
839
839
                                    enum_var_type type __attribute__((unused)))
840
840
{
841
 
  thd->reset_current_stmt_binlog_row_based();
 
841
  session->reset_current_stmt_binlog_row_based();
842
842
}
843
843
 
844
844
 
845
 
static void fix_max_binlog_size(Session *thd __attribute__((unused)),
 
845
static void fix_max_binlog_size(Session *session __attribute__((unused)),
846
846
                                enum_var_type type __attribute__((unused)))
847
847
{
848
848
  mysql_bin_log.set_max_size(max_binlog_size);
851
851
  return;
852
852
}
853
853
 
854
 
static void fix_max_relay_log_size(Session *thd __attribute__((unused)),
 
854
static void fix_max_relay_log_size(Session *session __attribute__((unused)),
855
855
                                   enum_var_type type __attribute__((unused)))
856
856
{
857
857
  active_mi->rli.relay_log.set_max_size(max_relay_log_size ?
859
859
  return;
860
860
}
861
861
 
862
 
static void fix_max_connections(Session *thd __attribute__((unused)),
 
862
static void fix_max_connections(Session *session __attribute__((unused)),
863
863
                                enum_var_type type __attribute__((unused)))
864
864
{
865
865
  resize_thr_alarm(max_connections +  10);
866
866
}
867
867
 
868
868
 
869
 
static void fix_thd_mem_root(Session *thd, enum_var_type type)
870
 
{
871
 
  if (type != OPT_GLOBAL)
872
 
    reset_root_defaults(thd->mem_root,
873
 
                        thd->variables.query_alloc_block_size,
874
 
                        thd->variables.query_prealloc_size);
875
 
}
876
 
 
877
 
 
878
 
static void fix_trans_mem_root(Session *thd, enum_var_type type)
879
 
{
880
 
  if (type != OPT_GLOBAL)
881
 
    reset_root_defaults(&thd->transaction.mem_root,
882
 
                        thd->variables.trans_alloc_block_size,
883
 
                        thd->variables.trans_prealloc_size);
884
 
}
885
 
 
886
 
 
887
 
static void fix_server_id(Session *thd __attribute__((unused)),
 
869
static void fix_session_mem_root(Session *session, enum_var_type type)
 
870
{
 
871
  if (type != OPT_GLOBAL)
 
872
    reset_root_defaults(session->mem_root,
 
873
                        session->variables.query_alloc_block_size,
 
874
                        session->variables.query_prealloc_size);
 
875
}
 
876
 
 
877
 
 
878
static void fix_trans_mem_root(Session *session, enum_var_type type)
 
879
{
 
880
  if (type != OPT_GLOBAL)
 
881
    reset_root_defaults(&session->transaction.mem_root,
 
882
                        session->variables.trans_alloc_block_size,
 
883
                        session->variables.trans_prealloc_size);
 
884
}
 
885
 
 
886
 
 
887
static void fix_server_id(Session *session __attribute__((unused)),
888
888
                          enum_var_type type __attribute__((unused)))
889
889
{
890
890
  server_id_supplied = 1;
891
 
  thd->server_id= server_id;
 
891
  session->server_id= server_id;
892
892
}
893
893
 
894
894
 
895
 
bool throw_bounds_warning(Session *thd, bool fixed, bool unsignd,
 
895
bool throw_bounds_warning(Session *session, bool fixed, bool unsignd,
896
896
                          const char *name, int64_t val)
897
897
{
898
898
  if (fixed)
904
904
    else
905
905
      llstr(val, buf);
906
906
 
907
 
    push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
907
    push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
908
908
                        ER_TRUNCATED_WRONG_VALUE,
909
909
                        ER(ER_TRUNCATED_WRONG_VALUE), name, buf);
910
910
  }
911
911
  return false;
912
912
}
913
913
 
914
 
static uint64_t fix_unsigned(Session *thd, uint64_t num,
 
914
static uint64_t fix_unsigned(Session *session, uint64_t num,
915
915
                              const struct my_option *option_limits)
916
916
{
917
917
  bool fixed= false;
918
918
  uint64_t out= getopt_ull_limit_value(num, option_limits, &fixed);
919
919
 
920
 
  throw_bounds_warning(thd, fixed, true, option_limits->name, (int64_t) num);
 
920
  throw_bounds_warning(session, fixed, true, option_limits->name, (int64_t) num);
921
921
  return out;
922
922
}
923
923
 
924
 
static bool get_unsigned(Session *thd __attribute__((unused)), set_var *var)
 
924
static bool get_unsigned(Session *session __attribute__((unused)), set_var *var)
925
925
{
926
926
  if (var->value->unsigned_flag)
927
927
    var->save_result.uint64_t_value= (uint64_t) var->value->val_int();
942
942
{}
943
943
 
944
944
 
945
 
bool sys_var_long_ptr_global::check(Session *thd, set_var *var)
 
945
bool sys_var_long_ptr_global::check(Session *session, set_var *var)
946
946
{
947
 
  return get_unsigned(thd, var);
 
947
  return get_unsigned(session, var);
948
948
}
949
949
 
950
 
bool sys_var_long_ptr_global::update(Session *thd, set_var *var)
 
950
bool sys_var_long_ptr_global::update(Session *session, set_var *var)
951
951
{
952
952
  uint64_t tmp= var->save_result.uint64_t_value;
953
953
  pthread_mutex_lock(guard);
954
954
  if (option_limits)
955
 
    *value= (ulong) fix_unsigned(thd, tmp, option_limits);
 
955
    *value= (ulong) fix_unsigned(session, tmp, option_limits);
956
956
  else
957
957
  {
958
958
    if (tmp > UINT32_MAX)
959
959
    {
960
960
      tmp= UINT32_MAX;
961
 
      throw_bounds_warning(thd, true, true, name,
 
961
      throw_bounds_warning(session, true, true, name,
962
962
                           (int64_t) var->save_result.uint64_t_value);
963
963
    }
964
964
    *value= (ulong) tmp;
969
969
}
970
970
 
971
971
 
972
 
void sys_var_long_ptr_global::set_default(Session *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
972
void sys_var_long_ptr_global::set_default(Session *session __attribute__((unused)), enum_var_type type __attribute__((unused)))
973
973
{
974
974
  bool not_used;
975
975
  pthread_mutex_lock(guard);
979
979
}
980
980
 
981
981
 
982
 
bool sys_var_uint64_t_ptr::update(Session *thd, set_var *var)
 
982
bool sys_var_uint64_t_ptr::update(Session *session, set_var *var)
983
983
{
984
984
  uint64_t tmp= var->save_result.uint64_t_value;
985
985
  pthread_mutex_lock(&LOCK_global_system_variables);
986
986
  if (option_limits)
987
 
    *value= (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
987
    *value= (uint64_t) fix_unsigned(session, tmp, option_limits);
988
988
  else
989
989
    *value= (uint64_t) tmp;
990
990
  pthread_mutex_unlock(&LOCK_global_system_variables);
992
992
}
993
993
 
994
994
 
995
 
void sys_var_uint64_t_ptr::set_default(Session *thd __attribute__((unused)),
 
995
void sys_var_uint64_t_ptr::set_default(Session *session __attribute__((unused)),
996
996
                                        enum_var_type type __attribute__((unused)))
997
997
{
998
998
  bool not_used;
1003
1003
}
1004
1004
 
1005
1005
 
1006
 
bool sys_var_bool_ptr::update(Session *thd __attribute__((unused)), set_var *var)
 
1006
bool sys_var_bool_ptr::update(Session *session __attribute__((unused)), set_var *var)
1007
1007
{
1008
1008
  *value= (bool) var->save_result.ulong_value;
1009
1009
  return 0;
1010
1010
}
1011
1011
 
1012
1012
 
1013
 
void sys_var_bool_ptr::set_default(Session *thd __attribute__((unused)), enum_var_type type __attribute__((unused)))
 
1013
void sys_var_bool_ptr::set_default(Session *session __attribute__((unused)), enum_var_type type __attribute__((unused)))
1014
1014
{
1015
1015
  *value= (bool) option_limits->def_value;
1016
1016
}
1017
1017
 
1018
1018
 
1019
 
bool sys_var_enum::update(Session *thd __attribute__((unused)), set_var *var)
 
1019
bool sys_var_enum::update(Session *session __attribute__((unused)), set_var *var)
1020
1020
{
1021
1021
  *value= (uint) var->save_result.ulong_value;
1022
1022
  return 0;
1023
1023
}
1024
1024
 
1025
1025
 
1026
 
unsigned char *sys_var_enum::value_ptr(Session *thd __attribute__((unused)),
 
1026
unsigned char *sys_var_enum::value_ptr(Session *session __attribute__((unused)),
1027
1027
                               enum_var_type type __attribute__((unused)),
1028
1028
                               LEX_STRING *base __attribute__((unused)))
1029
1029
{
1031
1031
}
1032
1032
 
1033
1033
 
1034
 
unsigned char *sys_var_enum_const::value_ptr(Session *thd __attribute__((unused)),
 
1034
unsigned char *sys_var_enum_const::value_ptr(Session *session __attribute__((unused)),
1035
1035
                                     enum_var_type type __attribute__((unused)),
1036
1036
                                     LEX_STRING *base __attribute__((unused)))
1037
1037
{
1038
1038
  return (unsigned char*) enum_names->type_names[global_system_variables.*offset];
1039
1039
}
1040
1040
 
1041
 
bool sys_var_thd_ulong::check(Session *thd, set_var *var)
 
1041
bool sys_var_session_ulong::check(Session *session, set_var *var)
1042
1042
{
1043
 
  return (get_unsigned(thd, var) ||
1044
 
          (check_func && (*check_func)(thd, var)));
 
1043
  return (get_unsigned(session, var) ||
 
1044
          (check_func && (*check_func)(session, var)));
1045
1045
}
1046
1046
 
1047
 
bool sys_var_thd_ulong::update(Session *thd, set_var *var)
 
1047
bool sys_var_session_ulong::update(Session *session, set_var *var)
1048
1048
{
1049
1049
  uint64_t tmp= var->save_result.uint64_t_value;
1050
1050
  
1051
1051
  /* Don't use bigger value than given with --maximum-variable-name=.. */
1052
1052
  if ((ulong) tmp > max_system_variables.*offset)
1053
1053
  {
1054
 
    throw_bounds_warning(thd, true, true, name, (int64_t) tmp);
 
1054
    throw_bounds_warning(session, true, true, name, (int64_t) tmp);
1055
1055
    tmp= max_system_variables.*offset;
1056
1056
  }
1057
1057
  
1058
1058
  if (option_limits)
1059
 
    tmp= (ulong) fix_unsigned(thd, tmp, option_limits);
 
1059
    tmp= (ulong) fix_unsigned(session, tmp, option_limits);
1060
1060
  else if (tmp > UINT32_MAX)
1061
1061
  {
1062
1062
    tmp= UINT32_MAX;
1063
 
    throw_bounds_warning(thd, true, true, name, (int64_t) var->save_result.uint64_t_value);
 
1063
    throw_bounds_warning(session, true, true, name, (int64_t) var->save_result.uint64_t_value);
1064
1064
  }
1065
1065
  
1066
1066
  if (var->type == OPT_GLOBAL)
1067
1067
     global_system_variables.*offset= (ulong) tmp;
1068
1068
   else
1069
 
     thd->variables.*offset= (ulong) tmp;
 
1069
     session->variables.*offset= (ulong) tmp;
1070
1070
 
1071
1071
   return 0;
1072
1072
 }
1073
1073
 
1074
1074
 
1075
 
 void sys_var_thd_ulong::set_default(Session *thd, enum_var_type type)
 
1075
 void sys_var_session_ulong::set_default(Session *session, enum_var_type type)
1076
1076
 {
1077
1077
   if (type == OPT_GLOBAL)
1078
1078
   {
1083
1083
                                      option_limits, &not_used);
1084
1084
   }
1085
1085
   else
1086
 
     thd->variables.*offset= global_system_variables.*offset;
 
1086
     session->variables.*offset= global_system_variables.*offset;
1087
1087
 }
1088
1088
 
1089
1089
 
1090
 
unsigned char *sys_var_thd_ulong::value_ptr(Session *thd, enum_var_type type,
 
1090
unsigned char *sys_var_session_ulong::value_ptr(Session *session, enum_var_type type,
1091
1091
                                    LEX_STRING *base __attribute__((unused)))
1092
1092
{
1093
1093
  if (type == OPT_GLOBAL)
1094
1094
    return (unsigned char*) &(global_system_variables.*offset);
1095
 
  return (unsigned char*) &(thd->variables.*offset);
 
1095
  return (unsigned char*) &(session->variables.*offset);
1096
1096
}
1097
1097
 
1098
1098
 
1099
 
bool sys_var_thd_ha_rows::update(Session *thd, set_var *var)
 
1099
bool sys_var_session_ha_rows::update(Session *session, set_var *var)
1100
1100
{
1101
1101
  uint64_t tmp= var->save_result.uint64_t_value;
1102
1102
 
1105
1105
    tmp= max_system_variables.*offset;
1106
1106
 
1107
1107
  if (option_limits)
1108
 
    tmp= (ha_rows) fix_unsigned(thd, tmp, option_limits);
 
1108
    tmp= (ha_rows) fix_unsigned(session, tmp, option_limits);
1109
1109
  if (var->type == OPT_GLOBAL)
1110
1110
  {
1111
1111
    /* Lock is needed to make things safe on 32 bit systems */
1114
1114
    pthread_mutex_unlock(&LOCK_global_system_variables);
1115
1115
  }
1116
1116
  else
1117
 
    thd->variables.*offset= (ha_rows) tmp;
 
1117
    session->variables.*offset= (ha_rows) tmp;
1118
1118
  return 0;
1119
1119
}
1120
1120
 
1121
1121
 
1122
 
void sys_var_thd_ha_rows::set_default(Session *thd, enum_var_type type)
 
1122
void sys_var_session_ha_rows::set_default(Session *session, enum_var_type type)
1123
1123
{
1124
1124
  if (type == OPT_GLOBAL)
1125
1125
  {
1132
1132
    pthread_mutex_unlock(&LOCK_global_system_variables);
1133
1133
  }
1134
1134
  else
1135
 
    thd->variables.*offset= global_system_variables.*offset;
 
1135
    session->variables.*offset= global_system_variables.*offset;
1136
1136
}
1137
1137
 
1138
1138
 
1139
 
unsigned char *sys_var_thd_ha_rows::value_ptr(Session *thd, enum_var_type type,
 
1139
unsigned char *sys_var_session_ha_rows::value_ptr(Session *session, enum_var_type type,
1140
1140
                                      LEX_STRING *base __attribute__((unused)))
1141
1141
{
1142
1142
  if (type == OPT_GLOBAL)
1143
1143
    return (unsigned char*) &(global_system_variables.*offset);
1144
 
  return (unsigned char*) &(thd->variables.*offset);
 
1144
  return (unsigned char*) &(session->variables.*offset);
1145
1145
}
1146
1146
 
1147
 
bool sys_var_thd_uint64_t::check(Session *thd, set_var *var)
 
1147
bool sys_var_session_uint64_t::check(Session *session, set_var *var)
1148
1148
{
1149
 
  return get_unsigned(thd, var);
 
1149
  return get_unsigned(session, var);
1150
1150
}
1151
1151
 
1152
 
bool sys_var_thd_uint64_t::update(Session *thd,  set_var *var)
 
1152
bool sys_var_session_uint64_t::update(Session *session,  set_var *var)
1153
1153
{
1154
1154
  uint64_t tmp= var->save_result.uint64_t_value;
1155
1155
 
1157
1157
    tmp= max_system_variables.*offset;
1158
1158
 
1159
1159
  if (option_limits)
1160
 
    tmp= fix_unsigned(thd, tmp, option_limits);
 
1160
    tmp= fix_unsigned(session, tmp, option_limits);
1161
1161
  if (var->type == OPT_GLOBAL)
1162
1162
  {
1163
1163
    /* Lock is needed to make things safe on 32 bit systems */
1166
1166
    pthread_mutex_unlock(&LOCK_global_system_variables);
1167
1167
  }
1168
1168
  else
1169
 
    thd->variables.*offset= (uint64_t) tmp;
 
1169
    session->variables.*offset= (uint64_t) tmp;
1170
1170
  return 0;
1171
1171
}
1172
1172
 
1173
1173
 
1174
 
void sys_var_thd_uint64_t::set_default(Session *thd, enum_var_type type)
 
1174
void sys_var_session_uint64_t::set_default(Session *session, enum_var_type type)
1175
1175
{
1176
1176
  if (type == OPT_GLOBAL)
1177
1177
  {
1183
1183
    pthread_mutex_unlock(&LOCK_global_system_variables);
1184
1184
  }
1185
1185
  else
1186
 
    thd->variables.*offset= global_system_variables.*offset;
 
1186
    session->variables.*offset= global_system_variables.*offset;
1187
1187
}
1188
1188
 
1189
1189
 
1190
 
unsigned char *sys_var_thd_uint64_t::value_ptr(Session *thd, enum_var_type type,
 
1190
unsigned char *sys_var_session_uint64_t::value_ptr(Session *session, enum_var_type type,
1191
1191
                                        LEX_STRING *base __attribute__((unused)))
1192
1192
{
1193
1193
  if (type == OPT_GLOBAL)
1194
1194
    return (unsigned char*) &(global_system_variables.*offset);
1195
 
  return (unsigned char*) &(thd->variables.*offset);
 
1195
  return (unsigned char*) &(session->variables.*offset);
1196
1196
}
1197
1197
 
1198
1198
 
1199
 
bool sys_var_thd_bool::update(Session *thd,  set_var *var)
 
1199
bool sys_var_session_bool::update(Session *session,  set_var *var)
1200
1200
{
1201
1201
  if (var->type == OPT_GLOBAL)
1202
1202
    global_system_variables.*offset= (bool) var->save_result.ulong_value;
1203
1203
  else
1204
 
    thd->variables.*offset= (bool) var->save_result.ulong_value;
 
1204
    session->variables.*offset= (bool) var->save_result.ulong_value;
1205
1205
  return 0;
1206
1206
}
1207
1207
 
1208
1208
 
1209
 
void sys_var_thd_bool::set_default(Session *thd,  enum_var_type type)
 
1209
void sys_var_session_bool::set_default(Session *session,  enum_var_type type)
1210
1210
{
1211
1211
  if (type == OPT_GLOBAL)
1212
1212
    global_system_variables.*offset= (bool) option_limits->def_value;
1213
1213
  else
1214
 
    thd->variables.*offset= global_system_variables.*offset;
 
1214
    session->variables.*offset= global_system_variables.*offset;
1215
1215
}
1216
1216
 
1217
1217
 
1218
 
unsigned char *sys_var_thd_bool::value_ptr(Session *thd, enum_var_type type,
 
1218
unsigned char *sys_var_session_bool::value_ptr(Session *session, enum_var_type type,
1219
1219
                                   LEX_STRING *base __attribute__((unused)))
1220
1220
{
1221
1221
  if (type == OPT_GLOBAL)
1222
1222
    return (unsigned char*) &(global_system_variables.*offset);
1223
 
  return (unsigned char*) &(thd->variables.*offset);
 
1223
  return (unsigned char*) &(session->variables.*offset);
1224
1224
}
1225
1225
 
1226
1226
 
1227
 
bool sys_var::check_enum(Session *thd __attribute__((unused)),
 
1227
bool sys_var::check_enum(Session *session __attribute__((unused)),
1228
1228
                         set_var *var, const TYPELIB *enum_names)
1229
1229
{
1230
1230
  char buff[STRING_BUFFER_USUAL_SIZE];
1261
1261
}
1262
1262
 
1263
1263
 
1264
 
bool sys_var::check_set(Session *thd __attribute__((unused)),
 
1264
bool sys_var::check_set(Session *session __attribute__((unused)),
1265
1265
                        set_var *var, TYPELIB *enum_names)
1266
1266
{
1267
1267
  bool not_used;
1336
1336
  If type is not given, return local value if exists, else global.
1337
1337
*/
1338
1338
 
1339
 
Item *sys_var::item(Session *thd, enum_var_type var_type, LEX_STRING *base)
 
1339
Item *sys_var::item(Session *session, enum_var_type var_type, LEX_STRING *base)
1340
1340
{
1341
1341
  if (check_type(var_type))
1342
1342
  {
1354
1354
  {
1355
1355
    uint32_t value;
1356
1356
    pthread_mutex_lock(&LOCK_global_system_variables);
1357
 
    value= *(uint*) value_ptr(thd, var_type, base);
 
1357
    value= *(uint*) value_ptr(session, var_type, base);
1358
1358
    pthread_mutex_unlock(&LOCK_global_system_variables);
1359
1359
    return new Item_uint((uint64_t) value);
1360
1360
  }
1362
1362
  {
1363
1363
    ulong value;
1364
1364
    pthread_mutex_lock(&LOCK_global_system_variables);
1365
 
    value= *(ulong*) value_ptr(thd, var_type, base);
 
1365
    value= *(ulong*) value_ptr(session, var_type, base);
1366
1366
    pthread_mutex_unlock(&LOCK_global_system_variables);
1367
1367
    return new Item_uint((uint64_t) value);
1368
1368
  }
1370
1370
  {
1371
1371
    int64_t value;
1372
1372
    pthread_mutex_lock(&LOCK_global_system_variables);
1373
 
    value= *(int64_t*) value_ptr(thd, var_type, base);
 
1373
    value= *(int64_t*) value_ptr(session, var_type, base);
1374
1374
    pthread_mutex_unlock(&LOCK_global_system_variables);
1375
1375
    return new Item_int(value);
1376
1376
  }
1378
1378
  {
1379
1379
    double value;
1380
1380
    pthread_mutex_lock(&LOCK_global_system_variables);
1381
 
    value= *(double*) value_ptr(thd, var_type, base);
 
1381
    value= *(double*) value_ptr(session, var_type, base);
1382
1382
    pthread_mutex_unlock(&LOCK_global_system_variables);
1383
1383
    /* 6, as this is for now only used with microseconds */
1384
1384
    return new Item_float(value, 6);
1387
1387
  {
1388
1388
    ha_rows value;
1389
1389
    pthread_mutex_lock(&LOCK_global_system_variables);
1390
 
    value= *(ha_rows*) value_ptr(thd, var_type, base);
 
1390
    value= *(ha_rows*) value_ptr(session, var_type, base);
1391
1391
    pthread_mutex_unlock(&LOCK_global_system_variables);
1392
1392
    return new Item_int((uint64_t) value);
1393
1393
  }
1395
1395
  {
1396
1396
    int32_t value;
1397
1397
    pthread_mutex_lock(&LOCK_global_system_variables);
1398
 
    value= *(bool*) value_ptr(thd, var_type, base);
 
1398
    value= *(bool*) value_ptr(session, var_type, base);
1399
1399
    pthread_mutex_unlock(&LOCK_global_system_variables);
1400
1400
    return new Item_int(value,1);
1401
1401
  }
1403
1403
  {
1404
1404
    Item *tmp;
1405
1405
    pthread_mutex_lock(&LOCK_global_system_variables);
1406
 
    char *str= *(char**) value_ptr(thd, var_type, base);
 
1406
    char *str= *(char**) value_ptr(session, var_type, base);
1407
1407
    if (str)
1408
1408
    {
1409
1409
      uint32_t length= strlen(str);
1410
 
      tmp= new Item_string(thd->strmake(str, length), length,
 
1410
      tmp= new Item_string(session->strmake(str, length), length,
1411
1411
                           system_charset_info, DERIVATION_SYSCONST);
1412
1412
    }
1413
1413
    else
1422
1422
  {
1423
1423
    Item *tmp;
1424
1424
    pthread_mutex_lock(&LOCK_global_system_variables);
1425
 
    char *str= (char*) value_ptr(thd, var_type, base);
 
1425
    char *str= (char*) value_ptr(session, var_type, base);
1426
1426
    if (str)
1427
1427
      tmp= new Item_string(str, strlen(str),
1428
1428
                           system_charset_info, DERIVATION_SYSCONST);
1441
1441
}
1442
1442
 
1443
1443
 
1444
 
bool sys_var_thd_enum::update(Session *thd, set_var *var)
 
1444
bool sys_var_session_enum::update(Session *session, set_var *var)
1445
1445
{
1446
1446
  if (var->type == OPT_GLOBAL)
1447
1447
    global_system_variables.*offset= var->save_result.ulong_value;
1448
1448
  else
1449
 
    thd->variables.*offset= var->save_result.ulong_value;
 
1449
    session->variables.*offset= var->save_result.ulong_value;
1450
1450
  return 0;
1451
1451
}
1452
1452
 
1453
1453
 
1454
 
void sys_var_thd_enum::set_default(Session *thd, enum_var_type type)
 
1454
void sys_var_session_enum::set_default(Session *session, enum_var_type type)
1455
1455
{
1456
1456
  if (type == OPT_GLOBAL)
1457
1457
    global_system_variables.*offset= (ulong) option_limits->def_value;
1458
1458
  else
1459
 
    thd->variables.*offset= global_system_variables.*offset;
 
1459
    session->variables.*offset= global_system_variables.*offset;
1460
1460
}
1461
1461
 
1462
1462
 
1463
 
unsigned char *sys_var_thd_enum::value_ptr(Session *thd, enum_var_type type,
 
1463
unsigned char *sys_var_session_enum::value_ptr(Session *session, enum_var_type type,
1464
1464
                                   LEX_STRING *base __attribute__((unused)))
1465
1465
{
1466
1466
  ulong tmp= ((type == OPT_GLOBAL) ?
1467
1467
              global_system_variables.*offset :
1468
 
              thd->variables.*offset);
 
1468
              session->variables.*offset);
1469
1469
  return (unsigned char*) enum_names->type_names[tmp];
1470
1470
}
1471
1471
 
1472
 
bool sys_var_thd_bit::check(Session *thd, set_var *var)
 
1472
bool sys_var_session_bit::check(Session *session, set_var *var)
1473
1473
{
1474
 
  return (check_enum(thd, var, &bool_typelib) ||
1475
 
          (check_func && (*check_func)(thd, var)));
 
1474
  return (check_enum(session, var, &bool_typelib) ||
 
1475
          (check_func && (*check_func)(session, var)));
1476
1476
}
1477
1477
 
1478
 
bool sys_var_thd_bit::update(Session *thd, set_var *var)
 
1478
bool sys_var_session_bit::update(Session *session, set_var *var)
1479
1479
{
1480
 
  int res= (*update_func)(thd, var);
 
1480
  int res= (*update_func)(session, var);
1481
1481
  return res;
1482
1482
}
1483
1483
 
1484
1484
 
1485
 
unsigned char *sys_var_thd_bit::value_ptr(Session *thd,
 
1485
unsigned char *sys_var_session_bit::value_ptr(Session *session,
1486
1486
                                  enum_var_type type __attribute__((unused)),
1487
1487
                                  LEX_STRING *base __attribute__((unused)))
1488
1488
{
1490
1490
    If reverse is 0 (default) return 1 if bit is set.
1491
1491
    If reverse is 1, return 0 if bit is set
1492
1492
  */
1493
 
  thd->sys_var_tmp.bool_value= ((thd->options & bit_flag) ?
 
1493
  session->sys_var_tmp.bool_value= ((session->options & bit_flag) ?
1494
1494
                                   !reverse : reverse);
1495
 
  return (unsigned char*) &thd->sys_var_tmp.bool_value;
 
1495
  return (unsigned char*) &session->sys_var_tmp.bool_value;
1496
1496
}
1497
1497
 
1498
1498
 
1499
1499
/** Update a date_time format variable based on given value. */
1500
1500
 
1501
 
void sys_var_thd_date_time_format::update2(Session *thd, enum_var_type type,
 
1501
void sys_var_session_date_time_format::update2(Session *session, enum_var_type type,
1502
1502
                                           DATE_TIME_FORMAT *new_value)
1503
1503
{
1504
1504
  DATE_TIME_FORMAT *old;
1512
1512
  }
1513
1513
  else
1514
1514
  {
1515
 
    old= (thd->variables.*offset);
1516
 
    (thd->variables.*offset)= new_value;
 
1515
    old= (session->variables.*offset);
 
1516
    (session->variables.*offset)= new_value;
1517
1517
  }
1518
1518
  free((char*) old);
1519
1519
  return;
1520
1520
}
1521
1521
 
1522
1522
 
1523
 
bool sys_var_thd_date_time_format::update(Session *thd, set_var *var)
 
1523
bool sys_var_session_date_time_format::update(Session *session, set_var *var)
1524
1524
{
1525
1525
  DATE_TIME_FORMAT *new_value;
1526
1526
  /* We must make a copy of the last value to get it into normal memory */
1528
1528
                                   var->save_result.date_time_format);
1529
1529
  if (!new_value)
1530
1530
    return 1;                                   // Out of memory
1531
 
  update2(thd, var->type, new_value);           // Can't fail
 
1531
  update2(session, var->type, new_value);               // Can't fail
1532
1532
  return 0;
1533
1533
}
1534
1534
 
1535
1535
 
1536
 
bool sys_var_thd_date_time_format::check(Session *thd, set_var *var)
 
1536
bool sys_var_session_date_time_format::check(Session *session, set_var *var)
1537
1537
{
1538
1538
  char buff[STRING_BUFFER_USUAL_SIZE];
1539
1539
  String str(buff,sizeof(buff), system_charset_info), *res;
1553
1553
    We must copy result to thread space to not get a memory leak if
1554
1554
    update is aborted
1555
1555
  */
1556
 
  var->save_result.date_time_format= date_time_format_copy(thd, format);
 
1556
  var->save_result.date_time_format= date_time_format_copy(session, format);
1557
1557
  free((char*) format);
1558
1558
  return var->save_result.date_time_format == 0;
1559
1559
}
1560
1560
 
1561
1561
 
1562
 
void sys_var_thd_date_time_format::set_default(Session *thd, enum_var_type type)
 
1562
void sys_var_session_date_time_format::set_default(Session *session, enum_var_type type)
1563
1563
{
1564
1564
  DATE_TIME_FORMAT *res= 0;
1565
1565
 
1576
1576
  }
1577
1577
 
1578
1578
  if (res)                                      // Should always be true
1579
 
    update2(thd, type, res);
 
1579
    update2(session, type, res);
1580
1580
}
1581
1581
 
1582
1582
 
1583
 
unsigned char *sys_var_thd_date_time_format::value_ptr(Session *thd, enum_var_type type,
 
1583
unsigned char *sys_var_session_date_time_format::value_ptr(Session *session, enum_var_type type,
1584
1584
                                               LEX_STRING *base __attribute__((unused)))
1585
1585
{
1586
1586
  if (type == OPT_GLOBAL)
1591
1591
      is modifying the original string while the copy is accessed
1592
1592
      (Can't happen now in SQL SHOW, but this is a good safety for the future)
1593
1593
    */
1594
 
    res= thd->strmake((global_system_variables.*offset)->format.str,
 
1594
    res= session->strmake((global_system_variables.*offset)->format.str,
1595
1595
                      (global_system_variables.*offset)->format.length);
1596
1596
    return (unsigned char*) res;
1597
1597
  }
1598
 
  return (unsigned char*) (thd->variables.*offset)->format.str;
 
1598
  return (unsigned char*) (session->variables.*offset)->format.str;
1599
1599
}
1600
1600
 
1601
1601
 
1605
1605
  const char *new_name;
1606
1606
} my_old_conv;
1607
1607
 
1608
 
bool sys_var_collation::check(Session *thd __attribute__((unused)),
 
1608
bool sys_var_collation::check(Session *session __attribute__((unused)),
1609
1609
                              set_var *var)
1610
1610
{
1611
1611
  const CHARSET_INFO *tmp;
1640
1640
}
1641
1641
 
1642
1642
 
1643
 
bool sys_var_character_set::check(Session *thd __attribute__((unused)),
 
1643
bool sys_var_character_set::check(Session *session __attribute__((unused)),
1644
1644
                                  set_var *var)
1645
1645
{
1646
1646
  const CHARSET_INFO *tmp;
1679
1679
}
1680
1680
 
1681
1681
 
1682
 
bool sys_var_character_set::update(Session *thd, set_var *var)
 
1682
bool sys_var_character_set::update(Session *session, set_var *var)
1683
1683
{
1684
 
  ci_ptr(thd,var->type)[0]= var->save_result.charset;
1685
 
  thd->update_charset();
 
1684
  ci_ptr(session,var->type)[0]= var->save_result.charset;
 
1685
  session->update_charset();
1686
1686
  return 0;
1687
1687
}
1688
1688
 
1689
1689
 
1690
 
unsigned char *sys_var_character_set::value_ptr(Session *thd, enum_var_type type,
 
1690
unsigned char *sys_var_character_set::value_ptr(Session *session, enum_var_type type,
1691
1691
                                        LEX_STRING *base __attribute__((unused)))
1692
1692
{
1693
 
  const CHARSET_INFO * const cs= ci_ptr(thd,type)[0];
 
1693
  const CHARSET_INFO * const cs= ci_ptr(session,type)[0];
1694
1694
  return cs ? (unsigned char*) cs->csname : (unsigned char*) NULL;
1695
1695
}
1696
1696
 
1697
1697
 
1698
 
bool sys_var_collation_sv::update(Session *thd, set_var *var)
 
1698
bool sys_var_collation_sv::update(Session *session, set_var *var)
1699
1699
{
1700
1700
  if (var->type == OPT_GLOBAL)
1701
1701
    global_system_variables.*offset= var->save_result.charset;
1702
1702
  else
1703
1703
  {
1704
 
    thd->variables.*offset= var->save_result.charset;
1705
 
    thd->update_charset();
 
1704
    session->variables.*offset= var->save_result.charset;
 
1705
    session->update_charset();
1706
1706
  }
1707
1707
  return 0;
1708
1708
}
1709
1709
 
1710
1710
 
1711
 
void sys_var_collation_sv::set_default(Session *thd, enum_var_type type)
 
1711
void sys_var_collation_sv::set_default(Session *session, enum_var_type type)
1712
1712
{
1713
1713
  if (type == OPT_GLOBAL)
1714
1714
    global_system_variables.*offset= *global_default;
1715
1715
  else
1716
1716
  {
1717
 
    thd->variables.*offset= global_system_variables.*offset;
1718
 
    thd->update_charset();
 
1717
    session->variables.*offset= global_system_variables.*offset;
 
1718
    session->update_charset();
1719
1719
  }
1720
1720
}
1721
1721
 
1722
1722
 
1723
 
unsigned char *sys_var_collation_sv::value_ptr(Session *thd, enum_var_type type,
 
1723
unsigned char *sys_var_collation_sv::value_ptr(Session *session, enum_var_type type,
1724
1724
                                       LEX_STRING *base __attribute__((unused)))
1725
1725
{
1726
1726
  const CHARSET_INFO *cs= ((type == OPT_GLOBAL) ?
1727
 
                     global_system_variables.*offset : thd->variables.*offset);
 
1727
                     global_system_variables.*offset : session->variables.*offset);
1728
1728
  return cs ? (unsigned char*) cs->name : (unsigned char*) "NULL";
1729
1729
}
1730
1730
 
1743
1743
}
1744
1744
 
1745
1745
 
1746
 
unsigned char *sys_var_key_cache_param::value_ptr(Session *thd __attribute__((unused)),
 
1746
unsigned char *sys_var_key_cache_param::value_ptr(Session *session __attribute__((unused)),
1747
1747
                                          enum_var_type type __attribute__((unused)),
1748
1748
                                          LEX_STRING *base __attribute__((unused)))
1749
1749
{
1754
1754
}
1755
1755
 
1756
1756
 
1757
 
bool sys_var_key_buffer_size::update(Session *thd, set_var *var)
 
1757
bool sys_var_key_buffer_size::update(Session *session, set_var *var)
1758
1758
{
1759
1759
  uint64_t tmp= var->save_result.uint64_t_value;
1760
1760
  LEX_STRING *base_name= &var->base;
1792
1792
  {
1793
1793
    if (key_cache == dflt_key_cache)
1794
1794
    {
1795
 
      push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1795
      push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1796
1796
                          ER_WARN_CANT_DROP_DEFAULT_KEYCACHE,
1797
1797
                          ER(ER_WARN_CANT_DROP_DEFAULT_KEYCACHE));
1798
1798
      goto end;                                 // Ignore default key cache
1809
1809
                                              base_name->length, &list);
1810
1810
      key_cache->in_init= 1;
1811
1811
      pthread_mutex_unlock(&LOCK_global_system_variables);
1812
 
      error= reassign_keycache_tables(thd, key_cache, dflt_key_cache);
 
1812
      error= reassign_keycache_tables(session, key_cache, dflt_key_cache);
1813
1813
      pthread_mutex_lock(&LOCK_global_system_variables);
1814
1814
      key_cache->in_init= 0;
1815
1815
    }
1821
1821
  }
1822
1822
 
1823
1823
  key_cache->param_buff_size=
1824
 
    (uint64_t) fix_unsigned(thd, tmp, option_limits);
 
1824
    (uint64_t) fix_unsigned(session, tmp, option_limits);
1825
1825
 
1826
1826
  /* If key cache didn't existed initialize it, else resize it */
1827
1827
  key_cache->in_init= 1;
1847
1847
  This should be changed so that we wait until the previous
1848
1848
  assignment is done and then do the new assign
1849
1849
*/
1850
 
bool sys_var_key_cache_long::update(Session *thd, set_var *var)
 
1850
bool sys_var_key_cache_long::update(Session *session, set_var *var)
1851
1851
{
1852
1852
  ulong tmp= (ulong) var->value->val_int();
1853
1853
  LEX_STRING *base_name= &var->base;
1875
1875
    goto end;
1876
1876
 
1877
1877
  *((ulong*) (((char*) key_cache) + offset))=
1878
 
    (ulong) fix_unsigned(thd, tmp, option_limits);
 
1878
    (ulong) fix_unsigned(session, tmp, option_limits);
1879
1879
 
1880
1880
  /*
1881
1881
    Don't create a new key cache if it didn't exist
1896
1896
}
1897
1897
 
1898
1898
 
1899
 
bool sys_var_log_state::update(Session *thd __attribute__((unused)), set_var *var)
 
1899
bool sys_var_log_state::update(Session *session __attribute__((unused)), set_var *var)
1900
1900
{
1901
1901
  bool res;
1902
1902
  pthread_mutex_lock(&LOCK_global_system_variables);
1908
1908
  return res;
1909
1909
}
1910
1910
 
1911
 
void sys_var_log_state::set_default(Session *thd __attribute__((unused)),
 
1911
void sys_var_log_state::set_default(Session *session __attribute__((unused)),
1912
1912
                                    enum_var_type type __attribute__((unused)))
1913
1913
{
1914
1914
}
1915
1915
 
1916
1916
 
1917
 
bool update_sys_var_str_path(Session *thd __attribute__((unused)),
 
1917
bool update_sys_var_str_path(Session *session __attribute__((unused)),
1918
1918
                             sys_var_str *var_str,
1919
1919
                             set_var *var, const char *log_ext,
1920
1920
                             bool log_state, uint32_t log_type)
1963
1963
}
1964
1964
 
1965
1965
 
1966
 
bool sys_var_log_output::update(Session *thd __attribute__((unused)),
 
1966
bool sys_var_log_output::update(Session *session __attribute__((unused)),
1967
1967
                                set_var *var)
1968
1968
{
1969
1969
  pthread_mutex_lock(&LOCK_global_system_variables);
1975
1975
}
1976
1976
 
1977
1977
 
1978
 
void sys_var_log_output::set_default(Session *thd __attribute__((unused)),
 
1978
void sys_var_log_output::set_default(Session *session __attribute__((unused)),
1979
1979
                                     enum_var_type type __attribute__((unused)))
1980
1980
{
1981
1981
  pthread_mutex_lock(&LOCK_global_system_variables);
1986
1986
}
1987
1987
 
1988
1988
 
1989
 
unsigned char *sys_var_log_output::value_ptr(Session *thd,
 
1989
unsigned char *sys_var_log_output::value_ptr(Session *session,
1990
1990
                                     enum_var_type type __attribute__((unused)),
1991
1991
                                     LEX_STRING *base __attribute__((unused)))
1992
1992
{
2008
2008
 
2009
2009
  if ((length= tmp.length()))
2010
2010
    length--;
2011
 
  return (unsigned char*) thd->strmake(tmp.ptr(), length);
 
2011
  return (unsigned char*) session->strmake(tmp.ptr(), length);
2012
2012
}
2013
2013
 
2014
2014
 
2016
2016
  Functions to handle SET NAMES and SET CHARACTER SET
2017
2017
*****************************************************************************/
2018
2018
 
2019
 
int set_var_collation_client::check(Session *thd __attribute__((unused)))
 
2019
int set_var_collation_client::check(Session *session __attribute__((unused)))
2020
2020
{
2021
2021
  /* Currently, UCS-2 cannot be used as a client character set */
2022
2022
  if (character_set_client->mbminlen > 1)
2028
2028
  return 0;
2029
2029
}
2030
2030
 
2031
 
int set_var_collation_client::update(Session *thd)
 
2031
int set_var_collation_client::update(Session *session)
2032
2032
{
2033
 
  thd->variables.character_set_client= character_set_client;
2034
 
  thd->variables.character_set_results= character_set_results;
2035
 
  thd->variables.collation_connection= collation_connection;
2036
 
  thd->update_charset();
2037
 
  thd->protocol_text.init(thd);
 
2033
  session->variables.character_set_client= character_set_client;
 
2034
  session->variables.character_set_results= character_set_results;
 
2035
  session->variables.collation_connection= collation_connection;
 
2036
  session->update_charset();
 
2037
  session->protocol_text.init(session);
2038
2038
  return 0;
2039
2039
}
2040
2040
 
2041
2041
/****************************************************************************/
2042
2042
 
2043
 
bool sys_var_timestamp::update(Session *thd,  set_var *var)
 
2043
bool sys_var_timestamp::update(Session *session,  set_var *var)
2044
2044
{
2045
 
  thd->set_time((time_t) var->save_result.uint64_t_value);
 
2045
  session->set_time((time_t) var->save_result.uint64_t_value);
2046
2046
  return 0;
2047
2047
}
2048
2048
 
2049
2049
 
2050
 
void sys_var_timestamp::set_default(Session *thd,
 
2050
void sys_var_timestamp::set_default(Session *session,
2051
2051
                                    enum_var_type type __attribute__((unused)))
2052
2052
{
2053
 
  thd->user_time=0;
 
2053
  session->user_time=0;
2054
2054
}
2055
2055
 
2056
2056
 
2057
 
unsigned char *sys_var_timestamp::value_ptr(Session *thd,
 
2057
unsigned char *sys_var_timestamp::value_ptr(Session *session,
2058
2058
                                    enum_var_type type __attribute__((unused)),
2059
2059
                                    LEX_STRING *base __attribute__((unused)))
2060
2060
{
2061
 
  thd->sys_var_tmp.long_value= (long) thd->start_time;
2062
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2061
  session->sys_var_tmp.long_value= (long) session->start_time;
 
2062
  return (unsigned char*) &session->sys_var_tmp.long_value;
2063
2063
}
2064
2064
 
2065
2065
 
2066
 
bool sys_var_last_insert_id::update(Session *thd, set_var *var)
 
2066
bool sys_var_last_insert_id::update(Session *session, set_var *var)
2067
2067
{
2068
 
  thd->first_successful_insert_id_in_prev_stmt=
 
2068
  session->first_successful_insert_id_in_prev_stmt=
2069
2069
    var->save_result.uint64_t_value;
2070
2070
  return 0;
2071
2071
}
2072
2072
 
2073
2073
 
2074
 
unsigned char *sys_var_last_insert_id::value_ptr(Session *thd,
 
2074
unsigned char *sys_var_last_insert_id::value_ptr(Session *session,
2075
2075
                                         enum_var_type type __attribute__((unused)),
2076
2076
                                         LEX_STRING *base __attribute__((unused)))
2077
2077
{
2079
2079
    this tmp var makes it robust againt change of type of
2080
2080
    read_first_successful_insert_id_in_prev_stmt().
2081
2081
  */
2082
 
  thd->sys_var_tmp.uint64_t_value= 
2083
 
    thd->read_first_successful_insert_id_in_prev_stmt();
2084
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
 
2082
  session->sys_var_tmp.uint64_t_value= 
 
2083
    session->read_first_successful_insert_id_in_prev_stmt();
 
2084
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
2085
2085
}
2086
2086
 
2087
2087
 
2088
 
bool sys_var_insert_id::update(Session *thd, set_var *var)
 
2088
bool sys_var_insert_id::update(Session *session, set_var *var)
2089
2089
{
2090
 
  thd->force_one_auto_inc_interval(var->save_result.uint64_t_value);
 
2090
  session->force_one_auto_inc_interval(var->save_result.uint64_t_value);
2091
2091
  return 0;
2092
2092
}
2093
2093
 
2094
2094
 
2095
 
unsigned char *sys_var_insert_id::value_ptr(Session *thd,
 
2095
unsigned char *sys_var_insert_id::value_ptr(Session *session,
2096
2096
                                    enum_var_type type __attribute__((unused)),
2097
2097
                                    LEX_STRING *base __attribute__((unused)))
2098
2098
{
2099
 
  thd->sys_var_tmp.uint64_t_value=
2100
 
    thd->auto_inc_intervals_forced.minimum();
2101
 
  return (unsigned char*) &thd->sys_var_tmp.uint64_t_value;
2102
 
}
2103
 
 
2104
 
 
2105
 
bool sys_var_rand_seed1::update(Session *thd, set_var *var)
2106
 
{
2107
 
  thd->rand.seed1= (ulong) var->save_result.uint64_t_value;
2108
 
  return 0;
2109
 
}
2110
 
 
2111
 
bool sys_var_rand_seed2::update(Session *thd, set_var *var)
2112
 
{
2113
 
  thd->rand.seed2= (ulong) var->save_result.uint64_t_value;
2114
 
  return 0;
2115
 
}
2116
 
 
2117
 
 
2118
 
bool sys_var_thd_time_zone::check(Session *thd, set_var *var)
 
2099
  session->sys_var_tmp.uint64_t_value=
 
2100
    session->auto_inc_intervals_forced.minimum();
 
2101
  return (unsigned char*) &session->sys_var_tmp.uint64_t_value;
 
2102
}
 
2103
 
 
2104
 
 
2105
bool sys_var_rand_seed1::update(Session *session, set_var *var)
 
2106
{
 
2107
  session->rand.seed1= (ulong) var->save_result.uint64_t_value;
 
2108
  return 0;
 
2109
}
 
2110
 
 
2111
bool sys_var_rand_seed2::update(Session *session, set_var *var)
 
2112
{
 
2113
  session->rand.seed2= (ulong) var->save_result.uint64_t_value;
 
2114
  return 0;
 
2115
}
 
2116
 
 
2117
 
 
2118
bool sys_var_session_time_zone::check(Session *session, set_var *var)
2119
2119
{
2120
2120
  char buff[MAX_TIME_ZONE_NAME_LENGTH];
2121
2121
  String str(buff, sizeof(buff), &my_charset_utf8_general_ci);
2122
2122
  String *res= var->value->val_str(&str);
2123
2123
 
2124
 
  if (!(var->save_result.time_zone= my_tz_find(thd, res)))
 
2124
  if (!(var->save_result.time_zone= my_tz_find(session, res)))
2125
2125
  {
2126
2126
    my_error(ER_UNKNOWN_TIME_ZONE, MYF(0), res ? res->c_ptr() : "NULL");
2127
2127
    return 1;
2130
2130
}
2131
2131
 
2132
2132
 
2133
 
bool sys_var_thd_time_zone::update(Session *thd, set_var *var)
 
2133
bool sys_var_session_time_zone::update(Session *session, set_var *var)
2134
2134
{
2135
2135
  /* We are using Time_zone object found during check() phase. */
2136
2136
  if (var->type == OPT_GLOBAL)
2140
2140
    pthread_mutex_unlock(&LOCK_global_system_variables);
2141
2141
  }
2142
2142
  else
2143
 
    thd->variables.time_zone= var->save_result.time_zone;
 
2143
    session->variables.time_zone= var->save_result.time_zone;
2144
2144
  return 0;
2145
2145
}
2146
2146
 
2147
2147
 
2148
 
unsigned char *sys_var_thd_time_zone::value_ptr(Session *thd, enum_var_type type,
 
2148
unsigned char *sys_var_session_time_zone::value_ptr(Session *session, enum_var_type type,
2149
2149
                                        LEX_STRING *base __attribute__((unused)))
2150
2150
{
2151
2151
  /* 
2164
2164
      timezone). If it's the global value which was used we can't replicate
2165
2165
      (binlog code stores session value only).
2166
2166
    */
2167
 
    thd->time_zone_used= 1;
2168
 
    return (unsigned char *)(thd->variables.time_zone->get_name()->ptr());
 
2167
    session->time_zone_used= 1;
 
2168
    return (unsigned char *)(session->variables.time_zone->get_name()->ptr());
2169
2169
  }
2170
2170
}
2171
2171
 
2172
2172
 
2173
 
void sys_var_thd_time_zone::set_default(Session *thd, enum_var_type type)
 
2173
void sys_var_session_time_zone::set_default(Session *session, enum_var_type type)
2174
2174
{
2175
2175
 pthread_mutex_lock(&LOCK_global_system_variables);
2176
2176
 if (type == OPT_GLOBAL)
2182
2182
       We are guaranteed to find this time zone since its existence
2183
2183
       is checked during start-up.
2184
2184
     */
2185
 
     global_system_variables.time_zone= my_tz_find(thd, &str);
 
2185
     global_system_variables.time_zone= my_tz_find(session, &str);
2186
2186
   }
2187
2187
   else
2188
2188
     global_system_variables.time_zone= my_tz_SYSTEM;
2189
2189
 }
2190
2190
 else
2191
 
   thd->variables.time_zone= global_system_variables.time_zone;
 
2191
   session->variables.time_zone= global_system_variables.time_zone;
2192
2192
 pthread_mutex_unlock(&LOCK_global_system_variables);
2193
2193
}
2194
2194
 
2195
2195
 
2196
 
bool sys_var_max_user_conn::check(Session *thd, set_var *var)
 
2196
bool sys_var_max_user_conn::check(Session *session, set_var *var)
2197
2197
{
2198
2198
  if (var->type == OPT_GLOBAL)
2199
 
    return sys_var_thd::check(thd, var);
 
2199
    return sys_var_session::check(session, var);
2200
2200
  else
2201
2201
  {
2202
2202
    /*
2208
2208
  }
2209
2209
}
2210
2210
 
2211
 
bool sys_var_max_user_conn::update(Session *thd __attribute__((unused)),
 
2211
bool sys_var_max_user_conn::update(Session *session __attribute__((unused)),
2212
2212
                                   set_var *var)
2213
2213
{
2214
2214
  assert(var->type == OPT_GLOBAL);
2219
2219
}
2220
2220
 
2221
2221
 
2222
 
void sys_var_max_user_conn::set_default(Session *thd __attribute__((unused)),
 
2222
void sys_var_max_user_conn::set_default(Session *session __attribute__((unused)),
2223
2223
                                        enum_var_type type __attribute__((unused)))
2224
2224
{
2225
2225
  assert(type == OPT_GLOBAL);
2229
2229
}
2230
2230
 
2231
2231
 
2232
 
unsigned char *sys_var_max_user_conn::value_ptr(Session *thd, enum_var_type type,
 
2232
unsigned char *sys_var_max_user_conn::value_ptr(Session *session, enum_var_type type,
2233
2233
                                        LEX_STRING *base __attribute__((unused)))
2234
2234
{
2235
2235
  if (type != OPT_GLOBAL &&
2236
 
      thd->user_connect && thd->user_connect->user_resources.user_conn)
2237
 
    return (unsigned char*) &(thd->user_connect->user_resources.user_conn);
 
2236
      session->user_connect && session->user_connect->user_resources.user_conn)
 
2237
    return (unsigned char*) &(session->user_connect->user_resources.user_conn);
2238
2238
  return (unsigned char*) &(max_user_connections);
2239
2239
}
2240
2240
 
2241
2241
 
2242
 
bool sys_var_thd_lc_time_names::check(Session *thd __attribute__((unused)),
 
2242
bool sys_var_session_lc_time_names::check(Session *session __attribute__((unused)),
2243
2243
                                      set_var *var)
2244
2244
{
2245
2245
  MY_LOCALE *locale_match;
2277
2277
}
2278
2278
 
2279
2279
 
2280
 
bool sys_var_thd_lc_time_names::update(Session *thd, set_var *var)
 
2280
bool sys_var_session_lc_time_names::update(Session *session, set_var *var)
2281
2281
{
2282
2282
  if (var->type == OPT_GLOBAL)
2283
2283
    global_system_variables.lc_time_names= var->save_result.locale_value;
2284
2284
  else
2285
 
    thd->variables.lc_time_names= var->save_result.locale_value;
 
2285
    session->variables.lc_time_names= var->save_result.locale_value;
2286
2286
  return 0;
2287
2287
}
2288
2288
 
2289
2289
 
2290
 
unsigned char *sys_var_thd_lc_time_names::value_ptr(Session *thd,
 
2290
unsigned char *sys_var_session_lc_time_names::value_ptr(Session *session,
2291
2291
                                            enum_var_type type,
2292
2292
                                            LEX_STRING *base __attribute__((unused)))
2293
2293
{
2294
2294
  return type == OPT_GLOBAL ?
2295
2295
                 (unsigned char *) global_system_variables.lc_time_names->name :
2296
 
                 (unsigned char *) thd->variables.lc_time_names->name;
 
2296
                 (unsigned char *) session->variables.lc_time_names->name;
2297
2297
}
2298
2298
 
2299
2299
 
2300
 
void sys_var_thd_lc_time_names::set_default(Session *thd, enum_var_type type)
 
2300
void sys_var_session_lc_time_names::set_default(Session *session, enum_var_type type)
2301
2301
{
2302
2302
  if (type == OPT_GLOBAL)
2303
2303
    global_system_variables.lc_time_names= my_default_lc_time_names;
2304
2304
  else
2305
 
    thd->variables.lc_time_names= global_system_variables.lc_time_names;
 
2305
    session->variables.lc_time_names= global_system_variables.lc_time_names;
2306
2306
}
2307
2307
 
2308
2308
/*
2314
2314
    This is used for handling long_query_time
2315
2315
*/
2316
2316
 
2317
 
bool sys_var_microseconds::update(Session *thd, set_var *var)
 
2317
bool sys_var_microseconds::update(Session *session, set_var *var)
2318
2318
{
2319
2319
  double num= var->value->val_real();
2320
2320
  int64_t microseconds;
2330
2330
    pthread_mutex_unlock(&LOCK_global_system_variables);
2331
2331
  }
2332
2332
  else
2333
 
    thd->variables.*offset= microseconds;
 
2333
    session->variables.*offset= microseconds;
2334
2334
  return 0;
2335
2335
}
2336
2336
 
2337
2337
 
2338
 
void sys_var_microseconds::set_default(Session *thd, enum_var_type type)
 
2338
void sys_var_microseconds::set_default(Session *session, enum_var_type type)
2339
2339
{
2340
2340
  int64_t microseconds= (int64_t) (option_limits->def_value * 1000000.0);
2341
2341
  if (type == OPT_GLOBAL)
2345
2345
    pthread_mutex_unlock(&LOCK_global_system_variables);
2346
2346
  }
2347
2347
  else
2348
 
    thd->variables.*offset= microseconds;
 
2348
    session->variables.*offset= microseconds;
2349
2349
}
2350
2350
 
2351
2351
 
2352
 
unsigned char *sys_var_microseconds::value_ptr(Session *thd, enum_var_type type,
 
2352
unsigned char *sys_var_microseconds::value_ptr(Session *session, enum_var_type type,
2353
2353
                                          LEX_STRING *base __attribute__((unused)))
2354
2354
{
2355
 
  thd->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
 
2355
  session->tmp_double_value= (double) ((type == OPT_GLOBAL) ?
2356
2356
                                   global_system_variables.*offset :
2357
 
                                   thd->variables.*offset) / 1000000.0;
2358
 
  return (unsigned char*) &thd->tmp_double_value;
 
2357
                                   session->variables.*offset) / 1000000.0;
 
2358
  return (unsigned char*) &session->tmp_double_value;
2359
2359
}
2360
2360
 
2361
2361
 
2362
2362
/*
2363
 
  Functions to update thd->options bits
 
2363
  Functions to update session->options bits
2364
2364
*/
2365
2365
 
2366
 
static bool set_option_bit(Session *thd, set_var *var)
 
2366
static bool set_option_bit(Session *session, set_var *var)
2367
2367
{
2368
 
  sys_var_thd_bit *sys_var= ((sys_var_thd_bit*) var->var);
 
2368
  sys_var_session_bit *sys_var= ((sys_var_session_bit*) var->var);
2369
2369
  if ((var->save_result.ulong_value != 0) == sys_var->reverse)
2370
 
    thd->options&= ~sys_var->bit_flag;
 
2370
    session->options&= ~sys_var->bit_flag;
2371
2371
  else
2372
 
    thd->options|= sys_var->bit_flag;
 
2372
    session->options|= sys_var->bit_flag;
2373
2373
  return 0;
2374
2374
}
2375
2375
 
2376
2376
 
2377
 
static bool set_option_autocommit(Session *thd, set_var *var)
 
2377
static bool set_option_autocommit(Session *session, set_var *var)
2378
2378
{
2379
2379
  /* The test is negative as the flag we use is NOT autocommit */
2380
2380
 
2381
 
  uint64_t org_options= thd->options;
 
2381
  uint64_t org_options= session->options;
2382
2382
 
2383
2383
  if (var->save_result.ulong_value != 0)
2384
 
    thd->options&= ~((sys_var_thd_bit*) var->var)->bit_flag;
 
2384
    session->options&= ~((sys_var_session_bit*) var->var)->bit_flag;
2385
2385
  else
2386
 
    thd->options|= ((sys_var_thd_bit*) var->var)->bit_flag;
 
2386
    session->options|= ((sys_var_session_bit*) var->var)->bit_flag;
2387
2387
 
2388
 
  if ((org_options ^ thd->options) & OPTION_NOT_AUTOCOMMIT)
 
2388
  if ((org_options ^ session->options) & OPTION_NOT_AUTOCOMMIT)
2389
2389
  {
2390
2390
    if ((org_options & OPTION_NOT_AUTOCOMMIT))
2391
2391
    {
2392
2392
      /* We changed to auto_commit mode */
2393
 
      thd->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
2394
 
      thd->transaction.all.modified_non_trans_table= false;
2395
 
      thd->server_status|= SERVER_STATUS_AUTOCOMMIT;
2396
 
      if (ha_commit(thd))
 
2393
      session->options&= ~(uint64_t) (OPTION_BEGIN | OPTION_KEEP_LOG);
 
2394
      session->transaction.all.modified_non_trans_table= false;
 
2395
      session->server_status|= SERVER_STATUS_AUTOCOMMIT;
 
2396
      if (ha_commit(session))
2397
2397
        return 1;
2398
2398
    }
2399
2399
    else
2400
2400
    {
2401
 
      thd->transaction.all.modified_non_trans_table= false;
2402
 
      thd->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
 
2401
      session->transaction.all.modified_non_trans_table= false;
 
2402
      session->server_status&= ~SERVER_STATUS_AUTOCOMMIT;
2403
2403
    }
2404
2404
  }
2405
2405
  return 0;
2406
2406
}
2407
2407
 
2408
 
static int check_log_update(Session *thd __attribute__((unused)),
 
2408
static int check_log_update(Session *session __attribute__((unused)),
2409
2409
                            set_var *var __attribute__((unused)))
2410
2410
{
2411
2411
  return 0;
2412
2412
}
2413
2413
 
2414
2414
 
2415
 
static int check_pseudo_thread_id(Session *thd __attribute__((unused)),
 
2415
static int check_pseudo_thread_id(Session *session __attribute__((unused)),
2416
2416
                                  set_var *var)
2417
2417
{
2418
2418
  var->save_result.uint64_t_value= var->value->val_int();
2419
2419
  return 0;
2420
2420
}
2421
2421
 
2422
 
static unsigned char *get_warning_count(Session *thd)
 
2422
static unsigned char *get_warning_count(Session *session)
2423
2423
{
2424
 
  thd->sys_var_tmp.long_value=
2425
 
    (thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
2426
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
2427
 
     thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
2428
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2424
  session->sys_var_tmp.long_value=
 
2425
    (session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_NOTE] +
 
2426
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR] +
 
2427
     session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_WARN]);
 
2428
  return (unsigned char*) &session->sys_var_tmp.long_value;
2429
2429
}
2430
2430
 
2431
 
static unsigned char *get_error_count(Session *thd)
 
2431
static unsigned char *get_error_count(Session *session)
2432
2432
{
2433
 
  thd->sys_var_tmp.long_value= 
2434
 
    thd->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
2435
 
  return (unsigned char*) &thd->sys_var_tmp.long_value;
 
2433
  session->sys_var_tmp.long_value= 
 
2434
    session->warn_count[(uint) DRIZZLE_ERROR::WARN_LEVEL_ERROR];
 
2435
  return (unsigned char*) &session->sys_var_tmp.long_value;
2436
2436
}
2437
2437
 
2438
2438
 
2445
2445
  that is actually a call to my_tmpdir() which cycles among possible
2446
2446
  temporary directories.
2447
2447
 
2448
 
  @param thd            thread handle
 
2448
  @param session                thread handle
2449
2449
 
2450
2450
  @retval
2451
2451
    ptr         pointer to NUL-terminated string
2452
2452
*/
2453
 
static unsigned char *get_tmpdir(Session *thd __attribute__((unused)))
 
2453
static unsigned char *get_tmpdir(Session *session __attribute__((unused)))
2454
2454
{
2455
2455
  if (opt_mysql_tmpdir)
2456
2456
    return (unsigned char *)opt_mysql_tmpdir;
2582
2582
  
2583
2583
  SYNOPSIS
2584
2584
    enumerate_sys_vars()
2585
 
    thd         current thread
 
2585
    session         current thread
2586
2586
    sorted      If TRUE, the system variables should be sorted
2587
2587
  
2588
2588
  RETURN VALUES
2590
2590
    NULL        FAILURE
2591
2591
*/
2592
2592
 
2593
 
SHOW_VAR* enumerate_sys_vars(Session *thd, bool sorted)
 
2593
SHOW_VAR* enumerate_sys_vars(Session *session, bool sorted)
2594
2594
{
2595
2595
  int count= system_variable_hash.records, i;
2596
2596
  int fixed_count= fixed_show_vars.elements;
2597
2597
  int size= sizeof(SHOW_VAR) * (count + fixed_count + 1);
2598
 
  SHOW_VAR *result= (SHOW_VAR*) thd->alloc(size);
 
2598
  SHOW_VAR *result= (SHOW_VAR*) session->alloc(size);
2599
2599
 
2600
2600
  if (result)
2601
2601
  {
2742
2742
    -1  ERROR, message not sent
2743
2743
*/
2744
2744
 
2745
 
int sql_set_variables(Session *thd, List<set_var_base> *var_list)
 
2745
int sql_set_variables(Session *session, List<set_var_base> *var_list)
2746
2746
{
2747
2747
  int error;
2748
2748
  List_iterator_fast<set_var_base> it(*var_list);
2750
2750
  set_var_base *var;
2751
2751
  while ((var=it++))
2752
2752
  {
2753
 
    if ((error= var->check(thd)))
 
2753
    if ((error= var->check(session)))
2754
2754
      goto err;
2755
2755
  }
2756
 
  if (!(error= test(thd->is_error())))
 
2756
  if (!(error= test(session->is_error())))
2757
2757
  {
2758
2758
    it.rewind();
2759
2759
    while ((var= it++))
2760
 
      error|= var->update(thd);         // Returns 0, -1 or 1
 
2760
      error|= var->update(session);         // Returns 0, -1 or 1
2761
2761
  }
2762
2762
 
2763
2763
err:
2764
 
  free_underlaid_joins(thd, &thd->lex->select_lex);
 
2764
  free_underlaid_joins(session, &session->lex->select_lex);
2765
2765
  return(error);
2766
2766
}
2767
2767
 
2799
2799
  Functions to handle SET mysql_internal_variable=const_expr
2800
2800
*****************************************************************************/
2801
2801
 
2802
 
int set_var::check(Session *thd)
 
2802
int set_var::check(Session *session)
2803
2803
{
2804
2804
  if (var->is_readonly())
2805
2805
  {
2824
2824
  }
2825
2825
 
2826
2826
  if ((!value->fixed &&
2827
 
       value->fix_fields(thd, &value)) || value->check_cols(1))
 
2827
       value->fix_fields(session, &value)) || value->check_cols(1))
2828
2828
    return -1;
2829
2829
  if (var->check_update_type(value->result_type()))
2830
2830
  {
2831
2831
    my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name);
2832
2832
    return -1;
2833
2833
  }
2834
 
  return var->check(thd, this) ? -1 : 0;
 
2834
  return var->check(session, this) ? -1 : 0;
2835
2835
}
2836
2836
 
2837
2837
/**
2838
2838
  Update variable
2839
2839
 
2840
 
  @param   thd    thread handler
 
2840
  @param   session    thread handler
2841
2841
  @returns 0|1    ok or ERROR
2842
2842
 
2843
2843
  @note ERROR can be only due to abnormal operations involving
2846
2846
  Consider set_var::check() method if there is a need to return
2847
2847
  an error due to logics.
2848
2848
*/
2849
 
int set_var::update(Session *thd)
 
2849
int set_var::update(Session *session)
2850
2850
{
2851
2851
  if (!value)
2852
 
    var->set_default(thd, type);
2853
 
  else if (var->update(thd, this))
 
2852
    var->set_default(session, type);
 
2853
  else if (var->update(session, this))
2854
2854
    return -1;                          // should never happen
2855
2855
  if (var->after_update)
2856
 
    (*var->after_update)(thd, type);
 
2856
    (*var->after_update)(session, type);
2857
2857
  return 0;
2858
2858
}
2859
2859
 
2862
2862
  Functions to handle SET @user_variable=const_expr
2863
2863
*****************************************************************************/
2864
2864
 
2865
 
int set_var_user::check(Session *thd)
 
2865
int set_var_user::check(Session *session)
2866
2866
{
2867
2867
  /*
2868
2868
    Item_func_set_user_var can't substitute something else on its place =>
2869
2869
    0 can be passed as last argument (reference on item)
2870
2870
  */
2871
 
  return (user_var_item->fix_fields(thd, (Item**) 0) ||
 
2871
  return (user_var_item->fix_fields(session, (Item**) 0) ||
2872
2872
          user_var_item->check(0)) ? -1 : 0;
2873
2873
}
2874
2874
 
2875
2875
 
2876
 
int set_var_user::update(Session *thd __attribute__((unused)))
 
2876
int set_var_user::update(Session *session __attribute__((unused)))
2877
2877
{
2878
2878
  if (user_var_item->update())
2879
2879
  {
2890
2890
 
2891
2891
/* Based upon sys_var::check_enum() */
2892
2892
 
2893
 
bool sys_var_thd_storage_engine::check(Session *thd, set_var *var)
 
2893
bool sys_var_session_storage_engine::check(Session *session, set_var *var)
2894
2894
{
2895
2895
  char buff[STRING_BUFFER_USUAL_SIZE];
2896
2896
  const char *value;
2904
2904
    if (!(res=var->value->val_str(&str)) ||
2905
2905
        !(engine_name.str= (char *)res->ptr()) ||
2906
2906
        !(engine_name.length= res->length()) ||
2907
 
        !(var->save_result.plugin= ha_resolve_by_name(thd, &engine_name)) ||
 
2907
        !(var->save_result.plugin= ha_resolve_by_name(session, &engine_name)) ||
2908
2908
        !(hton= plugin_data(var->save_result.plugin, handlerton *)))
2909
2909
    {
2910
2910
      value= res ? res->c_ptr() : "NULL";
2920
2920
}
2921
2921
 
2922
2922
 
2923
 
unsigned char *sys_var_thd_storage_engine::value_ptr(Session *thd, enum_var_type type,
 
2923
unsigned char *sys_var_session_storage_engine::value_ptr(Session *session, enum_var_type type,
2924
2924
                                             LEX_STRING *base __attribute__((unused)))
2925
2925
{
2926
2926
  unsigned char* result;
2927
2927
  handlerton *hton;
2928
2928
  LEX_STRING *engine_name;
2929
 
  plugin_ref plugin= thd->variables.*offset;
 
2929
  plugin_ref plugin= session->variables.*offset;
2930
2930
  if (type == OPT_GLOBAL)
2931
 
    plugin= my_plugin_lock(thd, &(global_system_variables.*offset));
 
2931
    plugin= my_plugin_lock(session, &(global_system_variables.*offset));
2932
2932
  hton= plugin_data(plugin, handlerton*);
2933
2933
  engine_name= &hton2plugin[hton->slot]->name;
2934
 
  result= (unsigned char *) thd->strmake(engine_name->str, engine_name->length);
 
2934
  result= (unsigned char *) session->strmake(engine_name->str, engine_name->length);
2935
2935
  if (type == OPT_GLOBAL)
2936
 
    plugin_unlock(thd, plugin);
 
2936
    plugin_unlock(session, plugin);
2937
2937
  return result;
2938
2938
}
2939
2939
 
2940
2940
 
2941
 
void sys_var_thd_storage_engine::set_default(Session *thd, enum_var_type type)
 
2941
void sys_var_session_storage_engine::set_default(Session *session, enum_var_type type)
2942
2942
{
2943
2943
  plugin_ref old_value, new_value, *value;
2944
2944
  if (type == OPT_GLOBAL)
2948
2948
  }
2949
2949
  else
2950
2950
  {
2951
 
    value= &(thd->variables.*offset);
 
2951
    value= &(session->variables.*offset);
2952
2952
    new_value= my_plugin_lock(NULL, &(global_system_variables.*offset));
2953
2953
  }
2954
2954
  assert(new_value);
2958
2958
}
2959
2959
 
2960
2960
 
2961
 
bool sys_var_thd_storage_engine::update(Session *thd, set_var *var)
 
2961
bool sys_var_session_storage_engine::update(Session *session, set_var *var)
2962
2962
{
2963
2963
  plugin_ref *value= &(global_system_variables.*offset), old_value;
2964
2964
   if (var->type != OPT_GLOBAL)
2965
 
     value= &(thd->variables.*offset);
 
2965
     value= &(session->variables.*offset);
2966
2966
  old_value= *value;
2967
2967
  if (old_value != var->save_result.plugin)
2968
2968
  {
2973
2973
}
2974
2974
 
2975
2975
bool
2976
 
sys_var_thd_optimizer_switch::
2977
 
symbolic_mode_representation(Session *thd, uint64_t val, LEX_STRING *rep)
 
2976
sys_var_session_optimizer_switch::
 
2977
symbolic_mode_representation(Session *session, uint64_t val, LEX_STRING *rep)
2978
2978
{
2979
2979
  char buff[STRING_BUFFER_USUAL_SIZE*8];
2980
2980
  String tmp(buff, sizeof(buff), &my_charset_utf8_general_ci);
2994
2994
  if (tmp.length())
2995
2995
    tmp.length(tmp.length() - 1); /* trim the trailing comma */
2996
2996
 
2997
 
  rep->str= thd->strmake(tmp.ptr(), tmp.length());
 
2997
  rep->str= session->strmake(tmp.ptr(), tmp.length());
2998
2998
 
2999
2999
  rep->length= rep->str ? tmp.length() : 0;
3000
3000
 
3002
3002
}
3003
3003
 
3004
3004
 
3005
 
unsigned char *sys_var_thd_optimizer_switch::value_ptr(Session *thd, enum_var_type type,
 
3005
unsigned char *sys_var_session_optimizer_switch::value_ptr(Session *session, enum_var_type type,
3006
3006
                                               LEX_STRING *base __attribute__((unused)))
3007
3007
{
3008
3008
  LEX_STRING opts;
3009
3009
  uint64_t val= ((type == OPT_GLOBAL) ? global_system_variables.*offset :
3010
 
                  thd->variables.*offset);
3011
 
  (void) symbolic_mode_representation(thd, val, &opts);
 
3010
                  session->variables.*offset);
 
3011
  (void) symbolic_mode_representation(session, val, &opts);
3012
3012
  return (unsigned char *) opts.str;
3013
3013
}
3014
3014
 
3015
3015
 
3016
 
void sys_var_thd_optimizer_switch::set_default(Session *thd, enum_var_type type)
 
3016
void sys_var_session_optimizer_switch::set_default(Session *session, enum_var_type type)
3017
3017
{
3018
3018
  if (type == OPT_GLOBAL)
3019
3019
    global_system_variables.*offset= 0;
3020
3020
  else
3021
 
    thd->variables.*offset= global_system_variables.*offset;
 
3021
    session->variables.*offset= global_system_variables.*offset;
3022
3022
}
3023
3023
 
3024
3024
 
3125
3125
}
3126
3126
 
3127
3127
 
3128
 
bool sys_var_opt_readonly::update(Session *thd, set_var *var)
 
3128
bool sys_var_opt_readonly::update(Session *session, set_var *var)
3129
3129
{
3130
3130
  bool result;
3131
3131
 
3132
3132
  /* Prevent self dead-lock */
3133
 
  if (thd->locked_tables || thd->active_transaction())
 
3133
  if (session->locked_tables || session->active_transaction())
3134
3134
  {
3135
3135
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
3136
3136
    return(true);
3137
3137
  }
3138
3138
 
3139
 
  if (thd->global_read_lock)
 
3139
  if (session->global_read_lock)
3140
3140
  {
3141
3141
    /*
3142
3142
      This connection already holds the global read lock.
3144
3144
      - FLUSH TABLES WITH READ LOCK
3145
3145
      - SET GLOBAL READ_ONLY = 1
3146
3146
    */
3147
 
    result= sys_var_bool_ptr::update(thd, var);
 
3147
    result= sys_var_bool_ptr::update(session, var);
3148
3148
    return(result);
3149
3149
  }
3150
3150
 
3159
3159
    [3] prevents transactions from being committed.
3160
3160
  */
3161
3161
 
3162
 
  if (lock_global_read_lock(thd))
 
3162
  if (lock_global_read_lock(session))
3163
3163
    return(true);
3164
3164
 
3165
3165
  /*
3171
3171
    can cause to wait on a read lock, it's required for the client application
3172
3172
    to unlock everything, and acceptable for the server to wait on all locks.
3173
3173
  */
3174
 
  if ((result= close_cached_tables(thd, NULL, false, true, true)) == true)
 
3174
  if ((result= close_cached_tables(session, NULL, false, true, true)) == true)
3175
3175
    goto end_with_read_lock;
3176
3176
 
3177
 
  if ((result= make_global_read_lock_block_commit(thd)) == true)
 
3177
  if ((result= make_global_read_lock_block_commit(session)) == true)
3178
3178
    goto end_with_read_lock;
3179
3179
 
3180
3180
  /* Change the opt_readonly system variable, safe because the lock is held */
3181
 
  result= sys_var_bool_ptr::update(thd, var);
 
3181
  result= sys_var_bool_ptr::update(session, var);
3182
3182
 
3183
3183
end_with_read_lock:
3184
3184
  /* Release the lock */
3185
 
  unlock_global_read_lock(thd);
 
3185
  unlock_global_read_lock(session);
3186
3186
  return(result);
3187
3187
}
3188
3188