github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/sessionctx/variable/sysvar.go (about)

     1  // Copyright 2015 PingCAP, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package variable
    15  
    16  import (
    17  	"strings"
    18  
    19  	"github.com/insionng/yougam/libraries/pingcap/tidb/context"
    20  	"github.com/insionng/yougam/libraries/pingcap/tidb/mysql"
    21  	"github.com/insionng/yougam/libraries/pingcap/tidb/terror"
    22  )
    23  
    24  // ScopeFlag is for system variable whether can be changed in global/session dynamically or not.
    25  type ScopeFlag uint8
    26  
    27  const (
    28  	// ScopeNone means the system variable can not be changed dynamically.
    29  	ScopeNone ScopeFlag = iota << 0
    30  	// ScopeGlobal means the system variable can be changed globally.
    31  	ScopeGlobal
    32  	// ScopeSession means the system variable can only be changed in current session.
    33  	ScopeSession
    34  )
    35  
    36  // SysVar is for system variable.
    37  type SysVar struct {
    38  	// Scope is for whether can be changed or not
    39  	Scope ScopeFlag
    40  
    41  	// Variable name
    42  	Name string
    43  
    44  	// Variable value
    45  	Value string
    46  }
    47  
    48  // SysVars is global sys vars map.
    49  var SysVars map[string]*SysVar
    50  
    51  // GetSysVar returns sys var info for name as key.
    52  func GetSysVar(name string) *SysVar {
    53  	name = strings.ToLower(name)
    54  	return SysVars[name]
    55  }
    56  
    57  // Variable error codes.
    58  const (
    59  	CodeUnknownStatusVar terror.ErrCode = 1
    60  	CodeUnknownSystemVar terror.ErrCode = 1193
    61  )
    62  
    63  // Variable errors
    64  var (
    65  	UnknownStatusVar = terror.ClassVariable.New(CodeUnknownStatusVar, "unknown status variable")
    66  	UnknownSystemVar = terror.ClassVariable.New(CodeUnknownSystemVar, "unknown system variable")
    67  )
    68  
    69  func init() {
    70  	SysVars = make(map[string]*SysVar)
    71  	for _, v := range defaultSysVars {
    72  		SysVars[v.Name] = v
    73  	}
    74  
    75  	// Register terror to mysql error map.
    76  	mySQLErrCodes := map[terror.ErrCode]uint16{
    77  		CodeUnknownSystemVar: mysql.ErrUnknownSystemVariable,
    78  	}
    79  	terror.ErrClassToMySQLCodes[terror.ClassVariable] = mySQLErrCodes
    80  }
    81  
    82  // we only support MySQL now
    83  var defaultSysVars = []*SysVar{
    84  	{ScopeGlobal, "gtid_mode", "OFF"},
    85  	{ScopeGlobal, "flush_time", "0"},
    86  	{ScopeSession, "pseudo_slave_mode", ""},
    87  	{ScopeNone, "performance_schema_max_mutex_classes", "200"},
    88  	{ScopeGlobal | ScopeSession, "low_priority_updates", "OFF"},
    89  	{ScopeGlobal | ScopeSession, "session_track_gtids", ""},
    90  	{ScopeGlobal | ScopeSession, "ndbinfo_max_rows", ""},
    91  	{ScopeGlobal | ScopeSession, "ndb_index_stat_option", ""},
    92  	{ScopeGlobal | ScopeSession, "old_passwords", "0"},
    93  	{ScopeNone, "innodb_version", "5.6.25"},
    94  	{ScopeGlobal, "max_connections", "151"},
    95  	{ScopeGlobal | ScopeSession, "big_tables", "OFF"},
    96  	{ScopeNone, "skip_external_locking", "ON"},
    97  	{ScopeGlobal, "slave_pending_jobs_size_max", "16777216"},
    98  	{ScopeNone, "innodb_sync_array_size", "1"},
    99  	{ScopeSession, "rand_seed2", ""},
   100  	{ScopeGlobal, "validate_password_number_count", ""},
   101  	{ScopeSession, "gtid_next", ""},
   102  	{ScopeGlobal | ScopeSession, "sql_select_limit", "18446744073709551615"},
   103  	{ScopeGlobal, "ndb_show_foreign_key_mock_tables", ""},
   104  	{ScopeNone, "multi_range_count", "256"},
   105  	{ScopeGlobal | ScopeSession, "default_week_format", "0"},
   106  	{ScopeGlobal | ScopeSession, "binlog_error_action", "IGNORE_ERROR"},
   107  	{ScopeGlobal, "slave_transaction_retries", "10"},
   108  	{ScopeGlobal | ScopeSession, "default_storage_engine", "InnoDB"},
   109  	{ScopeNone, "ft_query_expansion_limit", "20"},
   110  	{ScopeGlobal, "max_connect_errors", "100"},
   111  	{ScopeGlobal, "sync_binlog", "0"},
   112  	{ScopeNone, "max_digest_length", "1024"},
   113  	{ScopeNone, "innodb_force_load_corrupted", "OFF"},
   114  	{ScopeNone, "performance_schema_max_table_handles", "4000"},
   115  	{ScopeGlobal, "innodb_fast_shutdown", "1"},
   116  	{ScopeNone, "ft_max_word_len", "84"},
   117  	{ScopeGlobal, "log_backward_compatible_user_definitions", ""},
   118  	{ScopeNone, "lc_messages_dir", "/usr/local/mysql-5.6.25-osx10.8-x86_64/share/"},
   119  	{ScopeGlobal, "ft_boolean_syntax", "+ -><()~*:\"\"&|"},
   120  	{ScopeGlobal, "table_definition_cache", "1400"},
   121  	{ScopeNone, "skip_name_resolve", "OFF"},
   122  	{ScopeNone, "performance_schema_max_file_handles", "32768"},
   123  	{ScopeSession, "transaction_allow_batching", ""},
   124  	{ScopeGlobal | ScopeSession, "sql_mode", "NO_ENGINE_SUBSTITUTION"},
   125  	{ScopeNone, "performance_schema_max_statement_classes", "168"},
   126  	{ScopeGlobal, "server_id", "0"},
   127  	{ScopeGlobal, "innodb_flushing_avg_loops", "30"},
   128  	{ScopeGlobal | ScopeSession, "tmp_table_size", "16777216"},
   129  	{ScopeGlobal, "innodb_max_purge_lag", "0"},
   130  	{ScopeGlobal | ScopeSession, "preload_buffer_size", "32768"},
   131  	{ScopeGlobal, "slave_checkpoint_period", "300"},
   132  	{ScopeGlobal, "check_proxy_users", ""},
   133  	{ScopeNone, "have_query_cache", "YES"},
   134  	{ScopeGlobal, "innodb_flush_log_at_timeout", "1"},
   135  	{ScopeGlobal, "innodb_max_undo_log_size", ""},
   136  	{ScopeGlobal | ScopeSession, "range_alloc_block_size", "4096"},
   137  	{ScopeGlobal, "connect_timeout", "10"},
   138  	{ScopeGlobal | ScopeSession, "collation_server", "latin1_swedish_ci"},
   139  	{ScopeNone, "have_rtree_keys", "YES"},
   140  	{ScopeGlobal, "innodb_old_blocks_pct", "37"},
   141  	{ScopeGlobal, "innodb_file_format", "Antelope"},
   142  	{ScopeGlobal, "innodb_compression_failure_threshold_pct", "5"},
   143  	{ScopeNone, "performance_schema_events_waits_history_long_size", "10000"},
   144  	{ScopeGlobal, "innodb_checksum_algorithm", "innodb"},
   145  	{ScopeNone, "innodb_ft_sort_pll_degree", "2"},
   146  	{ScopeNone, "thread_stack", "262144"},
   147  	{ScopeGlobal, "relay_log_info_repository", "FILE"},
   148  	{ScopeGlobal | ScopeSession, "sql_log_bin", "ON"},
   149  	{ScopeGlobal, "super_read_only", ""},
   150  	{ScopeGlobal | ScopeSession, "max_delayed_threads", "20"},
   151  	{ScopeNone, "protocol_version", "10"},
   152  	{ScopeGlobal | ScopeSession, "new", "OFF"},
   153  	{ScopeGlobal | ScopeSession, "myisam_sort_buffer_size", "8388608"},
   154  	{ScopeGlobal | ScopeSession, "optimizer_trace_offset", "-1"},
   155  	{ScopeGlobal, "innodb_buffer_pool_dump_at_shutdown", "OFF"},
   156  	{ScopeGlobal | ScopeSession, "sql_notes", "ON"},
   157  	{ScopeGlobal, "innodb_cmp_per_index_enabled", "OFF"},
   158  	{ScopeGlobal, "innodb_ft_server_stopword_table", ""},
   159  	{ScopeNone, "performance_schema_max_file_instances", "7693"},
   160  	{ScopeNone, "log_output", "FILE"},
   161  	{ScopeGlobal, "binlog_group_commit_sync_delay", ""},
   162  	{ScopeGlobal, "binlog_group_commit_sync_no_delay_count", ""},
   163  	{ScopeNone, "have_crypt", "YES"},
   164  	{ScopeGlobal, "innodb_log_write_ahead_size", ""},
   165  	{ScopeNone, "innodb_log_group_home_dir", "./"},
   166  	{ScopeNone, "performance_schema_events_statements_history_size", "10"},
   167  	{ScopeGlobal, "general_log", "OFF"},
   168  	{ScopeGlobal, "validate_password_dictionary_file", ""},
   169  	{ScopeGlobal, "binlog_order_commits", "ON"},
   170  	{ScopeGlobal, "master_verify_checksum", "OFF"},
   171  	{ScopeGlobal, "key_cache_division_limit", "100"},
   172  	{ScopeGlobal, "rpl_semi_sync_master_trace_level", ""},
   173  	{ScopeGlobal | ScopeSession, "max_insert_delayed_threads", "20"},
   174  	{ScopeNone, "performance_schema_session_connect_attrs_size", "512"},
   175  	{ScopeGlobal | ScopeSession, "time_zone", "SYSTEM"},
   176  	{ScopeGlobal, "innodb_max_dirty_pages_pct", "75"},
   177  	{ScopeGlobal, "innodb_file_per_table", "ON"},
   178  	{ScopeGlobal, "innodb_log_compressed_pages", "ON"},
   179  	{ScopeGlobal, "master_info_repository", "FILE"},
   180  	{ScopeGlobal, "rpl_stop_slave_timeout", "31536000"},
   181  	{ScopeNone, "skip_networking", "OFF"},
   182  	{ScopeGlobal, "innodb_monitor_reset", ""},
   183  	{ScopeNone, "have_ssl", "DISABLED"},
   184  	{ScopeNone, "system_time_zone", "CST"},
   185  	{ScopeGlobal, "innodb_print_all_deadlocks", "OFF"},
   186  	{ScopeNone, "innodb_autoinc_lock_mode", "1"},
   187  	{ScopeGlobal, "slave_net_timeout", "3600"},
   188  	{ScopeGlobal, "key_buffer_size", "8388608"},
   189  	{ScopeGlobal | ScopeSession, "foreign_key_checks", "ON"},
   190  	{ScopeGlobal, "host_cache_size", "279"},
   191  	{ScopeGlobal, "delay_key_write", "ON"},
   192  	{ScopeNone, "metadata_locks_cache_size", "1024"},
   193  	{ScopeNone, "innodb_force_recovery", "0"},
   194  	{ScopeGlobal, "innodb_file_format_max", "Antelope"},
   195  	{ScopeGlobal | ScopeSession, "debug", ""},
   196  	{ScopeGlobal, "log_warnings", "1"},
   197  	{ScopeGlobal, "offline_mode", ""},
   198  	{ScopeGlobal | ScopeSession, "innodb_strict_mode", "OFF"},
   199  	{ScopeGlobal, "innodb_rollback_segments", "128"},
   200  	{ScopeGlobal | ScopeSession, "join_buffer_size", "262144"},
   201  	{ScopeNone, "innodb_mirrored_log_groups", "1"},
   202  	{ScopeGlobal, "max_binlog_size", "1073741824"},
   203  	{ScopeGlobal, "sync_master_info", "10000"},
   204  	{ScopeGlobal, "concurrent_insert", "AUTO"},
   205  	{ScopeGlobal, "innodb_adaptive_hash_index", "ON"},
   206  	{ScopeGlobal, "innodb_ft_enable_stopword", "ON"},
   207  	{ScopeGlobal, "general_log_file", "/usr/local/mysql/data/localhost.log"},
   208  	{ScopeGlobal | ScopeSession, "innodb_support_xa", "ON"},
   209  	{ScopeGlobal, "innodb_compression_level", "6"},
   210  	{ScopeNone, "innodb_file_format_check", "ON"},
   211  	{ScopeNone, "myisam_mmap_size", "18446744073709551615"},
   212  	{ScopeGlobal, "init_slave", ""},
   213  	{ScopeNone, "innodb_buffer_pool_instances", "8"},
   214  	{ScopeGlobal | ScopeSession, "block_encryption_mode", "aes-128-ecb"},
   215  	{ScopeGlobal | ScopeSession, "max_length_for_sort_data", "1024"},
   216  	{ScopeNone, "character_set_system", "utf8"},
   217  	{ScopeGlobal | ScopeSession, "interactive_timeout", "28800"},
   218  	{ScopeGlobal, "innodb_optimize_fulltext_only", "OFF"},
   219  	{ScopeNone, "character_sets_dir", "/usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/"},
   220  	{ScopeGlobal | ScopeSession, "query_cache_type", "OFF"},
   221  	{ScopeNone, "innodb_rollback_on_timeout", "OFF"},
   222  	{ScopeGlobal | ScopeSession, "query_alloc_block_size", "8192"},
   223  	{ScopeGlobal, "slave_compressed_protocol", "OFF"},
   224  	{ScopeGlobal, "init_connect", ""},
   225  	{ScopeGlobal, "rpl_semi_sync_slave_trace_level", ""},
   226  	{ScopeNone, "have_compress", "YES"},
   227  	{ScopeNone, "thread_concurrency", "10"},
   228  	{ScopeGlobal | ScopeSession, "query_prealloc_size", "8192"},
   229  	{ScopeNone, "relay_log_space_limit", "0"},
   230  	{ScopeGlobal | ScopeSession, "max_user_connections", "0"},
   231  	{ScopeNone, "performance_schema_max_thread_classes", "50"},
   232  	{ScopeGlobal, "innodb_api_trx_level", "0"},
   233  	{ScopeNone, "disconnect_on_expired_password", "ON"},
   234  	{ScopeNone, "performance_schema_max_file_classes", "50"},
   235  	{ScopeGlobal, "expire_logs_days", "0"},
   236  	{ScopeGlobal | ScopeSession, "binlog_rows_query_log_events", "OFF"},
   237  	{ScopeGlobal, "validate_password_policy", ""},
   238  	{ScopeGlobal, "default_password_lifetime", ""},
   239  	{ScopeNone, "pid_file", "/usr/local/mysql/data/localhost.pid"},
   240  	{ScopeNone, "innodb_undo_tablespaces", "0"},
   241  	{ScopeGlobal, "innodb_status_output_locks", "OFF"},
   242  	{ScopeNone, "performance_schema_accounts_size", "100"},
   243  	{ScopeGlobal | ScopeSession, "max_error_count", "64"},
   244  	{ScopeGlobal, "max_write_lock_count", "18446744073709551615"},
   245  	{ScopeNone, "performance_schema_max_socket_instances", "322"},
   246  	{ScopeNone, "performance_schema_max_table_instances", "12500"},
   247  	{ScopeGlobal, "innodb_stats_persistent_sample_pages", "20"},
   248  	{ScopeGlobal, "show_compatibility_56", ""},
   249  	{ScopeGlobal, "log_slow_slave_statements", "OFF"},
   250  	{ScopeNone, "innodb_open_files", "2000"},
   251  	{ScopeGlobal, "innodb_spin_wait_delay", "6"},
   252  	{ScopeGlobal, "thread_cache_size", "9"},
   253  	{ScopeGlobal, "log_slow_admin_statements", "OFF"},
   254  	{ScopeNone, "innodb_checksums", "ON"},
   255  	{ScopeNone, "hostname", "localhost"},
   256  	{ScopeGlobal | ScopeSession, "auto_increment_offset", "1"},
   257  	{ScopeNone, "ft_stopword_file", "(built-in)"},
   258  	{ScopeGlobal, "innodb_max_dirty_pages_pct_lwm", "0"},
   259  	{ScopeGlobal, "log_queries_not_using_indexes", "OFF"},
   260  	{ScopeSession, "timestamp", ""},
   261  	{ScopeGlobal | ScopeSession, "query_cache_wlock_invalidate", "OFF"},
   262  	{ScopeGlobal | ScopeSession, "sql_buffer_result", "OFF"},
   263  	{ScopeGlobal | ScopeSession, "character_set_filesystem", "binary"},
   264  	{ScopeGlobal | ScopeSession, "collation_database", "latin1_swedish_ci"},
   265  	{ScopeGlobal | ScopeSession, "auto_increment_increment", "1"},
   266  	{ScopeGlobal | ScopeSession, "max_heap_table_size", "16777216"},
   267  	{ScopeGlobal | ScopeSession, "div_precision_increment", "4"},
   268  	{ScopeGlobal, "innodb_lru_scan_depth", "1024"},
   269  	{ScopeGlobal, "innodb_purge_rseg_truncate_frequency", ""},
   270  	{ScopeGlobal | ScopeSession, "sql_auto_is_null", "OFF"},
   271  	{ScopeNone, "innodb_api_enable_binlog", "OFF"},
   272  	{ScopeGlobal | ScopeSession, "innodb_ft_user_stopword_table", ""},
   273  	{ScopeNone, "server_id_bits", "32"},
   274  	{ScopeGlobal, "innodb_log_checksum_algorithm", ""},
   275  	{ScopeNone, "innodb_buffer_pool_load_at_startup", "OFF"},
   276  	{ScopeGlobal | ScopeSession, "sort_buffer_size", "262144"},
   277  	{ScopeGlobal, "innodb_flush_neighbors", "1"},
   278  	{ScopeNone, "innodb_use_sys_malloc", "ON"},
   279  	{ScopeNone, "plugin_dir", "/usr/local/mysql/lib/plugin/"},
   280  	{ScopeNone, "performance_schema_max_socket_classes", "10"},
   281  	{ScopeNone, "performance_schema_max_stage_classes", "150"},
   282  	{ScopeGlobal, "innodb_purge_batch_size", "300"},
   283  	{ScopeNone, "have_profiling", "YES"},
   284  	{ScopeGlobal, "slave_checkpoint_group", "512"},
   285  	{ScopeGlobal | ScopeSession, "character_set_client", "latin1"},
   286  	{ScopeNone, "slave_load_tmpdir", "/var/tmp/"},
   287  	{ScopeGlobal, "innodb_buffer_pool_dump_now", "OFF"},
   288  	{ScopeGlobal, "relay_log_purge", "ON"},
   289  	{ScopeGlobal, "ndb_distribution", ""},
   290  	{ScopeGlobal, "myisam_data_pointer_size", "6"},
   291  	{ScopeGlobal, "ndb_optimization_delay", ""},
   292  	{ScopeGlobal, "innodb_ft_num_word_optimize", "2000"},
   293  	{ScopeGlobal | ScopeSession, "max_join_size", "18446744073709551615"},
   294  	{ScopeNone, "core_file", "OFF"},
   295  	{ScopeGlobal | ScopeSession, "max_seeks_for_key", "18446744073709551615"},
   296  	{ScopeNone, "innodb_log_buffer_size", "8388608"},
   297  	{ScopeGlobal, "delayed_insert_timeout", "300"},
   298  	{ScopeGlobal, "max_relay_log_size", "0"},
   299  	{ScopeGlobal | ScopeSession, "max_sort_length", "1024"},
   300  	{ScopeNone, "metadata_locks_hash_instances", "8"},
   301  	{ScopeGlobal, "ndb_eventbuffer_free_percent", ""},
   302  	{ScopeNone, "large_files_support", "ON"},
   303  	{ScopeGlobal, "binlog_max_flush_queue_time", "0"},
   304  	{ScopeGlobal, "innodb_fill_factor", ""},
   305  	{ScopeGlobal, "log_syslog_facility", ""},
   306  	{ScopeNone, "innodb_ft_min_token_size", "3"},
   307  	{ScopeGlobal | ScopeSession, "transaction_write_set_extraction", ""},
   308  	{ScopeGlobal | ScopeSession, "ndb_blob_write_batch_bytes", ""},
   309  	{ScopeGlobal, "automatic_sp_privileges", "ON"},
   310  	{ScopeGlobal, "innodb_flush_sync", ""},
   311  	{ScopeNone, "performance_schema_events_statements_history_long_size", "10000"},
   312  	{ScopeGlobal, "innodb_monitor_disable", ""},
   313  	{ScopeNone, "innodb_doublewrite", "ON"},
   314  	{ScopeGlobal, "slave_parallel_type", ""},
   315  	{ScopeNone, "log_bin_use_v1_row_events", "OFF"},
   316  	{ScopeSession, "innodb_optimize_point_storage", ""},
   317  	{ScopeNone, "innodb_api_disable_rowlock", "OFF"},
   318  	{ScopeGlobal, "innodb_adaptive_flushing_lwm", "10"},
   319  	{ScopeNone, "innodb_log_files_in_group", "2"},
   320  	{ScopeGlobal, "innodb_buffer_pool_load_now", "OFF"},
   321  	{ScopeNone, "performance_schema_max_rwlock_classes", "40"},
   322  	{ScopeNone, "binlog_gtid_simple_recovery", "OFF"},
   323  	{ScopeNone, "port", "3306"},
   324  	{ScopeNone, "performance_schema_digests_size", "10000"},
   325  	{ScopeGlobal | ScopeSession, "profiling", "OFF"},
   326  	{ScopeNone, "lower_case_table_names", "2"},
   327  	{ScopeSession, "rand_seed1", ""},
   328  	{ScopeGlobal, "sha256_password_proxy_users", ""},
   329  	{ScopeGlobal | ScopeSession, "sql_quote_show_create", "ON"},
   330  	{ScopeGlobal | ScopeSession, "binlogging_impossible_mode", "IGNORE_ERROR"},
   331  	{ScopeGlobal, "query_cache_size", "1048576"},
   332  	{ScopeGlobal, "innodb_stats_transient_sample_pages", "8"},
   333  	{ScopeGlobal, "innodb_stats_on_metadata", "OFF"},
   334  	{ScopeNone, "server_uuid", "d530594e-1c86-11e5-878b-6b36ce6799ca"},
   335  	{ScopeNone, "open_files_limit", "5000"},
   336  	{ScopeGlobal | ScopeSession, "ndb_force_send", ""},
   337  	{ScopeNone, "skip_show_database", "OFF"},
   338  	{ScopeGlobal, "log_timestamps", ""},
   339  	{ScopeNone, "version_compile_machine", "x86_64"},
   340  	{ScopeGlobal, "slave_parallel_workers", "0"},
   341  	{ScopeGlobal, "event_scheduler", "OFF"},
   342  	{ScopeGlobal | ScopeSession, "ndb_deferred_constraints", ""},
   343  	{ScopeGlobal, "log_syslog_include_pid", ""},
   344  	{ScopeSession, "last_insert_id", ""},
   345  	{ScopeNone, "innodb_ft_cache_size", "8000000"},
   346  	{ScopeNone, "log_bin", "OFF"},
   347  	{ScopeGlobal, "innodb_disable_sort_file_cache", "OFF"},
   348  	{ScopeGlobal, "log_error_verbosity", ""},
   349  	{ScopeNone, "performance_schema_hosts_size", "100"},
   350  	{ScopeGlobal, "innodb_replication_delay", "0"},
   351  	{ScopeGlobal, "slow_query_log", "OFF"},
   352  	{ScopeSession, "debug_sync", ""},
   353  	{ScopeGlobal, "innodb_stats_auto_recalc", "ON"},
   354  	{ScopeGlobal, "timed_mutexes", "OFF"},
   355  	{ScopeGlobal | ScopeSession, "lc_messages", "en_US"},
   356  	{ScopeGlobal | ScopeSession, "bulk_insert_buffer_size", "8388608"},
   357  	{ScopeGlobal | ScopeSession, "binlog_direct_non_transactional_updates", "OFF"},
   358  	{ScopeGlobal, "innodb_change_buffering", "all"},
   359  	{ScopeGlobal | ScopeSession, "sql_big_selects", "ON"},
   360  	{ScopeGlobal | ScopeSession, "character_set_results", "latin1"},
   361  	{ScopeGlobal, "innodb_max_purge_lag_delay", "0"},
   362  	{ScopeGlobal | ScopeSession, "session_track_schema", ""},
   363  	{ScopeGlobal, "innodb_io_capacity_max", "2000"},
   364  	{ScopeGlobal, "innodb_autoextend_increment", "64"},
   365  	{ScopeGlobal | ScopeSession, "binlog_format", "STATEMENT"},
   366  	{ScopeGlobal | ScopeSession, "optimizer_trace", "enabled=off,one_line=off"},
   367  	{ScopeGlobal | ScopeSession, "read_rnd_buffer_size", "262144"},
   368  	{ScopeNone, "version_comment", "MySQL Community Server (GPL)"},
   369  	{ScopeGlobal | ScopeSession, "net_write_timeout", "60"},
   370  	{ScopeGlobal, "innodb_buffer_pool_load_abort", "OFF"},
   371  	{ScopeGlobal | ScopeSession, "tx_isolation", "REPEATABLE-READ"},
   372  	{ScopeGlobal | ScopeSession, "collation_connection", "latin1_swedish_ci"},
   373  	{ScopeGlobal, "rpl_semi_sync_master_timeout", ""},
   374  	{ScopeGlobal | ScopeSession, "transaction_prealloc_size", "4096"},
   375  	{ScopeNone, "slave_skip_errors", "OFF"},
   376  	{ScopeNone, "performance_schema_setup_objects_size", "100"},
   377  	{ScopeGlobal, "sync_relay_log", "10000"},
   378  	{ScopeGlobal, "innodb_ft_result_cache_limit", "2000000000"},
   379  	{ScopeNone, "innodb_sort_buffer_size", "1048576"},
   380  	{ScopeGlobal, "innodb_ft_enable_diag_print", "OFF"},
   381  	{ScopeNone, "thread_handling", "one-thread-per-connection"},
   382  	{ScopeGlobal, "stored_program_cache", "256"},
   383  	{ScopeNone, "performance_schema_max_mutex_instances", "15906"},
   384  	{ScopeGlobal, "innodb_adaptive_max_sleep_delay", "150000"},
   385  	{ScopeNone, "large_pages", "OFF"},
   386  	{ScopeGlobal | ScopeSession, "session_track_system_variables", ""},
   387  	{ScopeGlobal, "innodb_change_buffer_max_size", "25"},
   388  	{ScopeGlobal, "log_bin_trust_function_creators", "OFF"},
   389  	{ScopeNone, "innodb_write_io_threads", "4"},
   390  	{ScopeGlobal, "mysql_native_password_proxy_users", ""},
   391  	{ScopeGlobal, "read_only", "OFF"},
   392  	{ScopeNone, "large_page_size", "0"},
   393  	{ScopeNone, "table_open_cache_instances", "1"},
   394  	{ScopeGlobal, "innodb_stats_persistent", "ON"},
   395  	{ScopeGlobal | ScopeSession, "session_track_state_change", ""},
   396  	{ScopeNone, "optimizer_switch", "index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,subquery_materialization_cost_based=on,use_index_extensions=on"},
   397  	{ScopeGlobal, "delayed_queue_size", "1000"},
   398  	{ScopeNone, "innodb_read_only", "OFF"},
   399  	{ScopeNone, "datetime_format", "%Y-%m-%d %H:%i:%s"},
   400  	{ScopeGlobal, "log_syslog", ""},
   401  	{ScopeNone, "version", "5.6.25"},
   402  	{ScopeGlobal | ScopeSession, "transaction_alloc_block_size", "8192"},
   403  	{ScopeGlobal, "sql_slave_skip_counter", "0"},
   404  	{ScopeNone, "have_openssl", "DISABLED"},
   405  	{ScopeGlobal, "innodb_large_prefix", "OFF"},
   406  	{ScopeNone, "performance_schema_max_cond_classes", "80"},
   407  	{ScopeGlobal, "innodb_io_capacity", "200"},
   408  	{ScopeGlobal, "max_binlog_cache_size", "18446744073709547520"},
   409  	{ScopeGlobal | ScopeSession, "ndb_index_stat_enable", ""},
   410  	{ScopeGlobal, "executed_gtids_compression_period", ""},
   411  	{ScopeNone, "time_format", "%H:%i:%s"},
   412  	{ScopeGlobal | ScopeSession, "old_alter_table", "OFF"},
   413  	{ScopeGlobal | ScopeSession, "long_query_time", "10.000000"},
   414  	{ScopeNone, "innodb_use_native_aio", "OFF"},
   415  	{ScopeGlobal, "log_throttle_queries_not_using_indexes", "0"},
   416  	{ScopeNone, "locked_in_memory", "OFF"},
   417  	{ScopeNone, "innodb_api_enable_mdl", "OFF"},
   418  	{ScopeGlobal, "binlog_cache_size", "32768"},
   419  	{ScopeGlobal, "innodb_compression_pad_pct_max", "50"},
   420  	{ScopeGlobal, "innodb_commit_concurrency", "0"},
   421  	{ScopeNone, "ft_min_word_len", "4"},
   422  	{ScopeGlobal, "enforce_gtid_consistency", "OFF"},
   423  	{ScopeGlobal, "secure_auth", "ON"},
   424  	{ScopeNone, "max_tmp_tables", "32"},
   425  	{ScopeGlobal, "innodb_random_read_ahead", "OFF"},
   426  	{ScopeGlobal | ScopeSession, "unique_checks", "ON"},
   427  	{ScopeGlobal, "internal_tmp_disk_storage_engine", ""},
   428  	{ScopeGlobal | ScopeSession, "myisam_repair_threads", "1"},
   429  	{ScopeGlobal, "ndb_eventbuffer_max_alloc", ""},
   430  	{ScopeGlobal, "innodb_read_ahead_threshold", "56"},
   431  	{ScopeGlobal, "key_cache_block_size", "1024"},
   432  	{ScopeGlobal, "rpl_semi_sync_slave_enabled", ""},
   433  	{ScopeNone, "ndb_recv_thread_cpu_mask", ""},
   434  	{ScopeGlobal, "gtid_purged", ""},
   435  	{ScopeGlobal, "max_binlog_stmt_cache_size", "18446744073709547520"},
   436  	{ScopeGlobal | ScopeSession, "lock_wait_timeout", "31536000"},
   437  	{ScopeGlobal | ScopeSession, "read_buffer_size", "131072"},
   438  	{ScopeNone, "innodb_read_io_threads", "4"},
   439  	{ScopeGlobal | ScopeSession, "max_sp_recursion_depth", "0"},
   440  	{ScopeNone, "ignore_builtin_innodb", "OFF"},
   441  	{ScopeGlobal, "rpl_semi_sync_master_enabled", ""},
   442  	{ScopeGlobal, "slow_query_log_file", "/usr/local/mysql/data/localhost-slow.log"},
   443  	{ScopeGlobal, "innodb_thread_sleep_delay", "10000"},
   444  	{ScopeNone, "license", "GPL"},
   445  	{ScopeGlobal, "innodb_ft_aux_table", ""},
   446  	{ScopeGlobal | ScopeSession, "sql_warnings", "OFF"},
   447  	{ScopeGlobal | ScopeSession, "keep_files_on_create", "OFF"},
   448  	{ScopeGlobal, "slave_preserve_commit_order", ""},
   449  	{ScopeNone, "innodb_data_file_path", "ibdata1:12M:autoextend"},
   450  	{ScopeNone, "performance_schema_setup_actors_size", "100"},
   451  	{ScopeNone, "innodb_additional_mem_pool_size", "8388608"},
   452  	{ScopeNone, "log_error", "/usr/local/mysql/data/localhost.err"},
   453  	{ScopeGlobal, "slave_exec_mode", "STRICT"},
   454  	{ScopeGlobal, "binlog_stmt_cache_size", "32768"},
   455  	{ScopeNone, "relay_log_info_file", "relay-log.info"},
   456  	{ScopeNone, "innodb_ft_total_cache_size", "640000000"},
   457  	{ScopeNone, "performance_schema_max_rwlock_instances", "9102"},
   458  	{ScopeGlobal, "table_open_cache", "2000"},
   459  	{ScopeNone, "log_slave_updates", "OFF"},
   460  	{ScopeNone, "performance_schema_events_stages_history_long_size", "10000"},
   461  	{ScopeGlobal | ScopeSession, "autocommit", "ON"},
   462  	{ScopeSession, "insert_id", ""},
   463  	{ScopeGlobal | ScopeSession, "default_tmp_storage_engine", "InnoDB"},
   464  	{ScopeGlobal | ScopeSession, "optimizer_search_depth", "62"},
   465  	{ScopeGlobal, "max_points_in_geometry", ""},
   466  	{ScopeGlobal, "innodb_stats_sample_pages", "8"},
   467  	{ScopeGlobal | ScopeSession, "profiling_history_size", "15"},
   468  	{ScopeGlobal | ScopeSession, "character_set_database", "latin1"},
   469  	{ScopeNone, "have_symlink", "YES"},
   470  	{ScopeGlobal | ScopeSession, "storage_engine", "InnoDB"},
   471  	{ScopeGlobal | ScopeSession, "sql_log_off", "OFF"},
   472  	{ScopeNone, "explicit_defaults_for_timestamp", "OFF"},
   473  	{ScopeNone, "performance_schema_events_waits_history_size", "10"},
   474  	{ScopeGlobal, "log_syslog_tag", ""},
   475  	{ScopeGlobal | ScopeSession, "tx_read_only", "OFF"},
   476  	{ScopeGlobal, "rpl_semi_sync_master_wait_point", ""},
   477  	{ScopeGlobal, "innodb_undo_log_truncate", ""},
   478  	{ScopeNone, "simplified_binlog_gtid_recovery", "OFF"},
   479  	{ScopeSession, "innodb_create_intrinsic", ""},
   480  	{ScopeGlobal, "gtid_executed_compression_period", ""},
   481  	{ScopeGlobal, "ndb_log_empty_epochs", ""},
   482  	{ScopeGlobal, "max_prepared_stmt_count", "16382"},
   483  	{ScopeNone, "have_geometry", "YES"},
   484  	{ScopeGlobal | ScopeSession, "optimizer_trace_max_mem_size", "16384"},
   485  	{ScopeGlobal | ScopeSession, "net_retry_count", "10"},
   486  	{ScopeSession, "ndb_table_no_logging", ""},
   487  	{ScopeGlobal | ScopeSession, "optimizer_trace_features", "greedy_search=on,range_optimizer=on,dynamic_range=on,repeated_subselect=on"},
   488  	{ScopeGlobal, "innodb_flush_log_at_trx_commit", "1"},
   489  	{ScopeGlobal, "rewriter_enabled", ""},
   490  	{ScopeGlobal, "query_cache_min_res_unit", "4096"},
   491  	{ScopeGlobal | ScopeSession, "updatable_views_with_limit", "YES"},
   492  	{ScopeGlobal | ScopeSession, "optimizer_prune_level", "1"},
   493  	{ScopeGlobal, "slave_sql_verify_checksum", "ON"},
   494  	{ScopeGlobal | ScopeSession, "completion_type", "NO_CHAIN"},
   495  	{ScopeGlobal, "binlog_checksum", "CRC32"},
   496  	{ScopeNone, "report_port", "3306"},
   497  	{ScopeGlobal | ScopeSession, "show_old_temporals", "OFF"},
   498  	{ScopeGlobal, "query_cache_limit", "1048576"},
   499  	{ScopeGlobal, "innodb_buffer_pool_size", "134217728"},
   500  	{ScopeGlobal, "innodb_adaptive_flushing", "ON"},
   501  	{ScopeNone, "datadir", "/usr/local/mysql/data/"},
   502  	{ScopeGlobal | ScopeSession, "wait_timeout", "28800"},
   503  	{ScopeGlobal, "innodb_monitor_enable", ""},
   504  	{ScopeNone, "date_format", "%Y-%m-%d"},
   505  	{ScopeGlobal, "innodb_buffer_pool_filename", "ib_buffer_pool"},
   506  	{ScopeGlobal, "slow_launch_time", "2"},
   507  	{ScopeGlobal, "slave_max_allowed_packet", "1073741824"},
   508  	{ScopeGlobal | ScopeSession, "ndb_use_transactions", ""},
   509  	{ScopeNone, "innodb_purge_threads", "1"},
   510  	{ScopeGlobal, "innodb_concurrency_tickets", "5000"},
   511  	{ScopeGlobal, "innodb_monitor_reset_all", ""},
   512  	{ScopeNone, "performance_schema_users_size", "100"},
   513  	{ScopeGlobal, "ndb_log_updated_only", ""},
   514  	{ScopeNone, "basedir", "/usr/local/mysql"},
   515  	{ScopeGlobal, "innodb_old_blocks_time", "1000"},
   516  	{ScopeGlobal, "innodb_stats_method", "nulls_equal"},
   517  	{ScopeGlobal | ScopeSession, "innodb_lock_wait_timeout", "50"},
   518  	{ScopeGlobal, "local_infile", "ON"},
   519  	{ScopeGlobal | ScopeSession, "myisam_stats_method", "nulls_unequal"},
   520  	{ScopeNone, "version_compile_os", "osx10.8"},
   521  	{ScopeNone, "relay_log_recovery", "OFF"},
   522  	{ScopeNone, "old", "OFF"},
   523  	{ScopeGlobal | ScopeSession, "innodb_table_locks", "ON"},
   524  	{ScopeNone, "performance_schema", "ON"},
   525  	{ScopeNone, "myisam_recover_options", "OFF"},
   526  	{ScopeGlobal | ScopeSession, "net_buffer_length", "16384"},
   527  	{ScopeGlobal, "rpl_semi_sync_master_wait_for_slave_count", ""},
   528  	{ScopeGlobal | ScopeSession, "binlog_row_image", "FULL"},
   529  	{ScopeNone, "innodb_locks_unsafe_for_binlog", "OFF"},
   530  	{ScopeSession, "rbr_exec_mode", ""},
   531  	{ScopeGlobal, "myisam_max_sort_file_size", "9223372036853727232"},
   532  	{ScopeNone, "back_log", "80"},
   533  	{ScopeNone, "lower_case_file_system", "ON"},
   534  	{ScopeGlobal, "rpl_semi_sync_master_wait_no_slave", ""},
   535  	{ScopeGlobal | ScopeSession, "group_concat_max_len", "1024"},
   536  	{ScopeSession, "pseudo_thread_id", ""},
   537  	{ScopeNone, "socket", "/tmp/myssock"},
   538  	{ScopeNone, "have_dynamic_loading", "YES"},
   539  	{ScopeGlobal, "rewriter_verbose", ""},
   540  	{ScopeGlobal, "innodb_undo_logs", "128"},
   541  	{ScopeNone, "performance_schema_max_cond_instances", "3504"},
   542  	{ScopeGlobal, "delayed_insert_limit", "100"},
   543  	{ScopeGlobal, "flush", "OFF"},
   544  	{ScopeGlobal | ScopeSession, "eq_range_index_dive_limit", "10"},
   545  	{ScopeNone, "performance_schema_events_stages_history_size", "10"},
   546  	{ScopeGlobal | ScopeSession, "character_set_connection", "latin1"},
   547  	{ScopeGlobal, "myisam_use_mmap", "OFF"},
   548  	{ScopeGlobal | ScopeSession, "ndb_join_pushdown", ""},
   549  	{ScopeGlobal | ScopeSession, "character_set_server", "latin1"},
   550  	{ScopeGlobal, "validate_password_special_char_count", ""},
   551  	{ScopeNone, "performance_schema_max_thread_instances", "402"},
   552  	{ScopeGlobal, "slave_rows_search_algorithms", "TABLE_SCAN,INDEX_SCAN"},
   553  	{ScopeGlobal | ScopeSession, "ndbinfo_show_hidden", ""},
   554  	{ScopeGlobal | ScopeSession, "net_read_timeout", "30"},
   555  	{ScopeNone, "innodb_page_size", "16384"},
   556  	{ScopeGlobal, "max_allowed_packet", "4194304"},
   557  	{ScopeNone, "innodb_log_file_size", "50331648"},
   558  	{ScopeGlobal, "sync_relay_log_info", "10000"},
   559  	{ScopeGlobal | ScopeSession, "optimizer_trace_limit", "1"},
   560  	{ScopeNone, "innodb_ft_max_token_size", "84"},
   561  	{ScopeGlobal, "validate_password_length", ""},
   562  	{ScopeGlobal, "ndb_log_binlog_index", ""},
   563  	{ScopeGlobal, "validate_password_mixed_case_count", ""},
   564  	{ScopeGlobal, "innodb_api_bk_commit_interval", "5"},
   565  	{ScopeNone, "innodb_undo_directory", "."},
   566  	{ScopeNone, "bind_address", "*"},
   567  	{ScopeGlobal, "innodb_sync_spin_loops", "30"},
   568  	{ScopeGlobal | ScopeSession, "sql_safe_updates", "OFF"},
   569  	{ScopeNone, "tmpdir", "/var/tmp/"},
   570  	{ScopeGlobal, "innodb_thread_concurrency", "0"},
   571  	{ScopeGlobal, "slave_allow_batching", "OFF"},
   572  	{ScopeGlobal, "innodb_buffer_pool_dump_pct", ""},
   573  	{ScopeGlobal | ScopeSession, "lc_time_names", "en_US"},
   574  	{ScopeGlobal | ScopeSession, "max_statement_time", ""},
   575  	{ScopeGlobal | ScopeSession, "end_markers_in_json", "OFF"},
   576  	{ScopeGlobal, "avoid_temporal_upgrade", "OFF"},
   577  	{ScopeGlobal, "key_cache_age_threshold", "300"},
   578  	{ScopeGlobal, "innodb_status_output", "OFF"},
   579  	{ScopeSession, "identity", ""},
   580  	{ScopeGlobal | ScopeSession, "min_examined_row_limit", "0"},
   581  	{ScopeGlobal, "sync_frm", "ON"},
   582  	{ScopeGlobal, "innodb_online_alter_log_max_size", "134217728"},
   583  }
   584  
   585  // SetNamesVariables is the system variable names related to set names statements.
   586  var SetNamesVariables = []string{
   587  	"character_set_client",
   588  	"character_set_connection",
   589  	"character_set_results",
   590  }
   591  
   592  const (
   593  	// CollationConnection is the name for collation_connection system variable.
   594  	CollationConnection = "collation_connection"
   595  	// CharsetDatabase is the name for charactor_set_database system variable.
   596  	CharsetDatabase = "character_set_database"
   597  	// CollationDatabase is the name for collation_database system variable.
   598  	CollationDatabase = "collation_database"
   599  )
   600  
   601  // GlobalVarAccessor is the interface for accessing global scope system and status variables.
   602  type GlobalVarAccessor interface {
   603  	// GetGlobalSysVar gets the global system variable value for name.
   604  	GetGlobalSysVar(ctx context.Context, name string) (string, error)
   605  	// SetGlobalSysVar sets the global system variable name to value.
   606  	SetGlobalSysVar(ctx context.Context, name string, value string) error
   607  }
   608  
   609  // globalSysVarAccessorKeyType is a dummy type to avoid naming collision in context.
   610  type globalSysVarAccessorKeyType int
   611  
   612  // String defines a Stringer function for debugging and pretty printing.
   613  func (k globalSysVarAccessorKeyType) String() string {
   614  	return "global_sysvar_accessor"
   615  }
   616  
   617  const accessorKey globalSysVarAccessorKeyType = 0
   618  
   619  // BindGlobalVarAccessor binds global var accessor to context.
   620  func BindGlobalVarAccessor(ctx context.Context, accessor GlobalVarAccessor) {
   621  	ctx.SetValue(accessorKey, accessor)
   622  }
   623  
   624  // GetGlobalVarAccessor gets accessor from ctx.
   625  func GetGlobalVarAccessor(ctx context.Context) GlobalVarAccessor {
   626  	v, ok := ctx.Value(accessorKey).(GlobalVarAccessor)
   627  	if !ok {
   628  		panic("Miss global sysvar accessor")
   629  	}
   630  	return v
   631  }