github.com/team-ide/go-dialect@v1.9.20/vitess/sysvars/sysvars.go (about)

     1  /*
     2  Copyright 2020 The Vitess Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package sysvars
    18  
    19  // This information lives here, because it's needed from the vtgate planbuilder, the vtgate engine,
    20  // and the AST rewriter, that happens to live in sqlparser.
    21  
    22  // SystemVariable is a system variable that Vitess handles in queries such as:
    23  // select @@sql_mode
    24  // set skip_query_plan_cache = true
    25  type SystemVariable struct {
    26  	// IsBoolean is used to signal necessary type coercion so that strings
    27  	// and numbers can be evaluated to a boolean value
    28  	IsBoolean bool
    29  
    30  	// IdentifierAsString allows identifiers (a.k.a. ColName) from the AST to be handled as if they are strings.
    31  	// SET transaction_mode = two_pc => SET transaction_mode = 'two_pc'
    32  	IdentifierAsString bool
    33  
    34  	// Default is the default value, if none is given
    35  	Default string
    36  
    37  	Name string
    38  }
    39  
    40  // System Settings
    41  var (
    42  	on      = "1"
    43  	off     = "0"
    44  	utf8mb4 = "'utf8mb4'"
    45  
    46  	Autocommit                  = SystemVariable{Name: "autocommit", IsBoolean: true, Default: on}
    47  	Charset                     = SystemVariable{Name: "charset", Default: utf8mb4, IdentifierAsString: true}
    48  	ClientFoundRows             = SystemVariable{Name: "client_found_rows", IsBoolean: true, Default: off}
    49  	SessionEnableSystemSettings = SystemVariable{Name: "enable_system_settings", IsBoolean: true, Default: on}
    50  	Names                       = SystemVariable{Name: "names", Default: utf8mb4, IdentifierAsString: true}
    51  	SessionUUID                 = SystemVariable{Name: "session_uuid", IdentifierAsString: true}
    52  	SkipQueryPlanCache          = SystemVariable{Name: "skip_query_plan_cache", IsBoolean: true, Default: off}
    53  	Socket                      = SystemVariable{Name: "socket", Default: off}
    54  	SQLSelectLimit              = SystemVariable{Name: "sql_select_limit", Default: off}
    55  	TransactionMode             = SystemVariable{Name: "transaction_mode", IdentifierAsString: true}
    56  	TransactionReadOnly         = SystemVariable{Name: "transaction_read_only", IsBoolean: true, Default: off}
    57  	TxReadOnly                  = SystemVariable{Name: "tx_read_only", IsBoolean: true, Default: off}
    58  	Workload                    = SystemVariable{Name: "workload", IdentifierAsString: true}
    59  
    60  	// Online DDL
    61  	DDLStrategy    = SystemVariable{Name: "ddl_strategy", IdentifierAsString: true}
    62  	Version        = SystemVariable{Name: "version"}
    63  	VersionComment = SystemVariable{Name: "version_comment"}
    64  
    65  	// Read After Write settings
    66  	ReadAfterWriteGTID    = SystemVariable{Name: "read_after_write_gtid"}
    67  	ReadAfterWriteTimeOut = SystemVariable{Name: "read_after_write_timeout"}
    68  	SessionTrackGTIDs     = SystemVariable{Name: "session_track_gtids", IdentifierAsString: true}
    69  
    70  	VitessAware = []SystemVariable{
    71  		Autocommit,
    72  		ClientFoundRows,
    73  		SkipQueryPlanCache,
    74  		TxReadOnly,
    75  		TransactionReadOnly,
    76  		SQLSelectLimit,
    77  		TransactionMode,
    78  		DDLStrategy,
    79  		Workload,
    80  		Charset,
    81  		Names,
    82  		SessionUUID,
    83  		SessionEnableSystemSettings,
    84  		ReadAfterWriteGTID,
    85  		ReadAfterWriteTimeOut,
    86  		SessionTrackGTIDs,
    87  	}
    88  
    89  	ReadOnly = []SystemVariable{
    90  		Socket,
    91  		Version,
    92  		VersionComment,
    93  	}
    94  
    95  	IgnoreThese = []SystemVariable{
    96  		{Name: "big_tables", IsBoolean: true},
    97  		{Name: "bulk_insert_buffer_size"},
    98  		{Name: "debug"},
    99  		{Name: "default_storage_engine"},
   100  		{Name: "default_tmp_storage_engine"},
   101  		{Name: "innodb_strict_mode", IsBoolean: true},
   102  		{Name: "innodb_support_xa", IsBoolean: true},
   103  		{Name: "innodb_table_locks", IsBoolean: true},
   104  		{Name: "innodb_tmpdir"},
   105  		{Name: "join_buffer_size"},
   106  		{Name: "keep_files_on_create", IsBoolean: true},
   107  		{Name: "lc_messages"},
   108  		{Name: "long_query_time"},
   109  		{Name: "low_priority_updates", IsBoolean: true},
   110  		{Name: "max_delayed_threads"},
   111  		{Name: "max_insert_delayed_threads"},
   112  		{Name: "multi_range_count"},
   113  		{Name: "net_buffer_length"},
   114  		{Name: "new", IsBoolean: true},
   115  		{Name: "query_cache_type"},
   116  		{Name: "query_cache_wlock_invalidate", IsBoolean: true},
   117  		{Name: "query_prealloc_size"},
   118  		{Name: "sql_buffer_result", IsBoolean: true},
   119  		{Name: "transaction_alloc_block_size"},
   120  		{Name: "wait_timeout"},
   121  	}
   122  
   123  	NotSupported = []SystemVariable{
   124  		{Name: "audit_log_read_buffer_size"},
   125  		{Name: "auto_increment_increment"},
   126  		{Name: "auto_increment_offset"},
   127  		{Name: "binlog_direct_non_transactional_updates"},
   128  		{Name: "binlog_row_image"},
   129  		{Name: "binlog_rows_query_log_events"},
   130  		{Name: "innodb_ft_enable_stopword"},
   131  		{Name: "innodb_ft_user_stopword_table"},
   132  		{Name: "max_points_in_geometry"},
   133  		{Name: "max_sp_recursion_depth"},
   134  		{Name: "myisam_repair_threads"},
   135  		{Name: "myisam_sort_buffer_size"},
   136  		{Name: "myisam_stats_method"},
   137  		{Name: "ndb_allow_copying_alter_table"},
   138  		{Name: "ndb_autoincrement_prefetch_sz"},
   139  		{Name: "ndb_blob_read_batch_bytes"},
   140  		{Name: "ndb_blob_write_batch_bytes"},
   141  		{Name: "ndb_deferred_constraints"},
   142  		{Name: "ndb_force_send"},
   143  		{Name: "ndb_fully_replicated"},
   144  		{Name: "ndb_index_stat_enable"},
   145  		{Name: "ndb_index_stat_option"},
   146  		{Name: "ndb_join_pushdown"},
   147  		{Name: "ndb_log_bin"},
   148  		{Name: "ndb_log_exclusive_reads"},
   149  		{Name: "ndb_row_checksum"},
   150  		{Name: "ndb_use_exact_count"},
   151  		{Name: "ndb_use_transactions"},
   152  		{Name: "ndbinfo_max_bytes"},
   153  		{Name: "ndbinfo_max_rows"},
   154  		{Name: "ndbinfo_show_hidden"},
   155  		{Name: "ndbinfo_table_prefix"},
   156  		{Name: "old_alter_table"},
   157  		{Name: "preload_buffer_size"},
   158  		{Name: "rbr_exec_mode"},
   159  		{Name: "sql_log_off"},
   160  		{Name: "thread_pool_high_priority_connection"},
   161  		{Name: "thread_pool_prio_kickup_timer"},
   162  		{Name: "transaction_write_set_extraction"},
   163  	}
   164  	UseReservedConn = []SystemVariable{
   165  		{Name: "default_week_format"},
   166  		{Name: "end_markers_in_json", IsBoolean: true},
   167  		{Name: "eq_range_index_dive_limit"},
   168  		{Name: "explicit_defaults_for_timestamp"},
   169  		{Name: "foreign_key_checks", IsBoolean: true},
   170  		{Name: "group_concat_max_len"},
   171  		{Name: "information_schema_stats_expiry"},
   172  		{Name: "max_heap_table_size"},
   173  		{Name: "max_seeks_for_key"},
   174  		{Name: "max_tmp_tables"},
   175  		{Name: "min_examined_row_limit"},
   176  		{Name: "old_passwords"},
   177  		{Name: "optimizer_prune_level"},
   178  		{Name: "optimizer_search_depth"},
   179  		{Name: "optimizer_switch"},
   180  		{Name: "optimizer_trace"},
   181  		{Name: "optimizer_trace_features"},
   182  		{Name: "optimizer_trace_limit"},
   183  		{Name: "optimizer_trace_max_mem_size"},
   184  		{Name: "transaction_isolation"},
   185  		{Name: "tx_isolation"},
   186  		{Name: "optimizer_trace_offset"},
   187  		{Name: "parser_max_mem_size"},
   188  		{Name: "profiling", IsBoolean: true},
   189  		{Name: "profiling_history_size"},
   190  		{Name: "query_alloc_block_size"},
   191  		{Name: "range_alloc_block_size"},
   192  		{Name: "range_optimizer_max_mem_size"},
   193  		{Name: "read_buffer_size"},
   194  		{Name: "read_rnd_buffer_size"},
   195  		{Name: "show_create_table_verbosity", IsBoolean: true},
   196  		{Name: "show_old_temporals", IsBoolean: true},
   197  		{Name: "sort_buffer_size"},
   198  		{Name: "sql_big_selects", IsBoolean: true},
   199  		{Name: "sql_mode"},
   200  		{Name: "sql_notes", IsBoolean: true},
   201  		{Name: "sql_quote_show_create", IsBoolean: true},
   202  		{Name: "sql_safe_updates", IsBoolean: true},
   203  		{Name: "sql_warnings", IsBoolean: true},
   204  		{Name: "time_zone"},
   205  		{Name: "tmp_table_size"},
   206  		{Name: "transaction_prealloc_size"},
   207  		{Name: "unique_checks", IsBoolean: true},
   208  		{Name: "updatable_views_with_limit", IsBoolean: true},
   209  	}
   210  	CheckAndIgnore = []SystemVariable{
   211  		// TODO: Most of these settings should be moved into SysSetOpAware, and change Vitess behaviour.
   212  		// Until then, SET statements against these settings are allowed
   213  		// as long as they have the same value as the underlying database
   214  		{Name: "binlog_format"},
   215  		{Name: "block_encryption_mode"},
   216  		{Name: "character_set_client"},
   217  		{Name: "character_set_connection"},
   218  		{Name: "character_set_database"},
   219  		{Name: "character_set_filesystem"},
   220  		{Name: "character_set_results"},
   221  		{Name: "character_set_server"},
   222  		{Name: "collation_connection"},
   223  		{Name: "collation_database"},
   224  		{Name: "collation_server"},
   225  		{Name: "completion_type"},
   226  		{Name: "div_precision_increment"},
   227  		{Name: "innodb_lock_wait_timeout"},
   228  		{Name: "interactive_timeout"},
   229  		{Name: "lc_time_names"},
   230  		{Name: "lock_wait_timeout"},
   231  		{Name: "max_allowed_packet"},
   232  		{Name: "max_error_count"},
   233  		{Name: "max_execution_time"},
   234  		{Name: "max_join_size"},
   235  		{Name: "max_length_for_sort_data"},
   236  		{Name: "max_sort_length"},
   237  		{Name: "max_user_connections"},
   238  		{Name: "net_read_timeout"},
   239  		{Name: "net_retry_count"},
   240  		{Name: "net_write_timeout"},
   241  		{Name: "session_track_schema", IsBoolean: true},
   242  		{Name: "session_track_state_change", IsBoolean: true},
   243  		{Name: "session_track_system_variables"},
   244  		{Name: "session_track_transaction_info"},
   245  		{Name: "sql_auto_is_null", IsBoolean: true},
   246  		{Name: "version_tokens_session"},
   247  	}
   248  )
   249  
   250  // GetInterestingVariables is used to return all the variables that may be listed in a SHOW VARIABLES command.
   251  func GetInterestingVariables() []string {
   252  	var res []string
   253  	// Add all the vitess aware variables
   254  	for _, variable := range VitessAware {
   255  		res = append(res, variable.Name)
   256  	}
   257  	// Also add version and version comment
   258  	res = append(res, Version.Name)
   259  	res = append(res, VersionComment.Name)
   260  	res = append(res, Socket.Name)
   261  	return res
   262  }