Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sessionctx: support encoding and decoding session variables #4

Merged
merged 1 commit into from
Apr 12, 2022

Conversation

djshow832
Copy link
Owner

@djshow832 djshow832 commented Apr 12, 2022

This PR supports encoding session variables into JSON and decoding JSON back to session variables.

Categories of session variables:

  • Hidden and noop variables won't be encoded.
  • Readonly variables won't be encoded, because the values will be encoded into SessionStates manually.
  • Some non-readonly variables will be encoded and decoded but won't actually work, such as tidb_config.
  • Some variables shouldn't be shown when SEM is enabled, but it involves import cycle currently.
  • Some variables should be handled specially, such as timestamp.

Why I encode all session variables, even if they may not be changed:

  • Default values of session variables may change among TiDB versions.
  • Default values of global variables may change among TiDB versions.
  • Global variables may change during session migration.

Example:

mysql> show session_states;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Session_states                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| {"system-vars": {"allow_auto_random_explicit_insert": "OFF", "auto_increment_increment": "1", "auto_increment_offset": "1", "autocommit": "ON", "block_encryption_mode": "aes-128-ecb", "character_set_client": "utf8mb4", "character_set_connection": "utf8mb4", "character_set_results": "utf8mb4", "character_set_server": "utf8mb4", "collation_connection": "utf8mb4_bin", "collation_server": "utf8mb4_bin", "cte_max_recursion_depth": "1000", "ddl_slow_threshold": "300", "default_week_format": "0", "identity": "0", "innodb_lock_wait_timeout": "50", "interactive_timeout": "28800", "last_insert_id": "0", "max_allowed_packet": "67108864", "max_execution_time": "0", "plugin_dir": "/data/deploy/plugin", "plugin_load": "", "rand_seed1": "0", "rand_seed2": "0", "sql_mode": "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", "sql_select_limit": "18446744073709551615", "tidb_allow_batch_cop": "1", "tidb_allow_fallback_to_tikv": "", "tidb_allow_mpp": "ON", "tidb_analyze_version": "2", "tidb_backoff_lock_fast": "10", "tidb_backoff_weight": "2", "tidb_batch_pending_tiflash_count": "4000", "tidb_broadcast_join_threshold_count": "10240", "tidb_broadcast_join_threshold_size": "104857600", "tidb_check_mb4_value_in_utf8": "ON", "tidb_constraint_check_in_place": "OFF", "tidb_disable_txn_auto_retry": "ON", "tidb_distsql_scan_concurrency": "15", "tidb_dml_batch_size": "0", "tidb_enable_1pc": "OFF", "tidb_enable_amend_pessimistic_txn": "OFF", "tidb_enable_async_commit": "OFF", "tidb_enable_auto_increment_in_generated": "OFF", "tidb_enable_cascades_planner": "OFF", "tidb_enable_chunk_rpc": "1", "tidb_enable_clustered_index": "INT_ONLY", "tidb_enable_collect_execution_info": "ON", "tidb_enable_exchange_partition": "OFF", "tidb_enable_fast_analyze": "OFF", "tidb_enable_index_merge": "ON", "tidb_enable_legacy_instance_scope": "ON", "tidb_enable_list_partition": "OFF", "tidb_enable_new_only_full_group_by_check": "OFF", "tidb_enable_noop_functions": "OFF", "tidb_enable_ordered_result_mode": "OFF", "tidb_enable_parallel_apply": "OFF", "tidb_enable_pipelined_window_function": "ON", "tidb_enable_pseudo_for_outdated_stats": "ON", "tidb_enable_rate_limit_action": "ON", "tidb_enable_slow_log": "ON", "tidb_enable_strict_double_type_check": "ON", "tidb_enable_table_partition": "ON", "tidb_enable_vectorized_expression": "ON", "tidb_enable_window_function": "ON", "tidb_enforce_mpp": "OFF", "tidb_evolve_plan_baselines": "OFF", "tidb_executor_concurrency": "5", "tidb_expensive_query_time_threshold": "60", "tidb_force_priority": "NO_PRIORITY", "tidb_guarantee_linearizability": "ON", "tidb_hash_exchange_with_new_collation": "ON", "tidb_hash_join_concurrency": "-1", "tidb_hashagg_final_concurrency": "-1", "tidb_hashagg_partial_concurrency": "-1", "tidb_ignore_prepared_cache_close_stmt": "OFF", "tidb_index_join_batch_size": "25000", "tidb_index_lookup_concurrency": "-1", "tidb_index_lookup_join_concurrency": "-1", "tidb_index_lookup_size": "20000", "tidb_index_serial_scan_concurrency": "1", "tidb_init_chunk_size": "32", "tidb_isolation_read_engines": "tikv,tiflash,tidb", "tidb_log_file_max_days": "0", "tidb_max_chunk_size": "1024", "tidb_mem_quota_apply_cache": "33554432", "tidb_memory_usage_alarm_ratio": "0.8", "tidb_merge_join_concurrency": "1", "tidb_mpp_store_fail_ttl": "60s", "tidb_multi_statement_mode": "OFF", "tidb_opt_broadcast_cartesian_join": "1", "tidb_opt_concurrency_factor": "3", "tidb_opt_copcpu_factor": "3", "tidb_opt_correlation_exp_factor": "1", "tidb_opt_correlation_threshold": "0.9", "tidb_opt_cpu_factor": "3", "tidb_opt_desc_factor": "3", "tidb_opt_disk_factor": "1.5", "tidb_opt_enable_correlation_adjustment": "ON", "tidb_opt_insubq_to_join_and_agg": "ON", "tidb_opt_limit_push_down_threshold": "100", "tidb_opt_memory_factor": "0.001", "tidb_opt_mpp_outer_join_fixed_build_side": "OFF", "tidb_opt_network_factor": "1", "tidb_opt_prefer_range_scan": "OFF", "tidb_opt_scan_factor": "1.5", "tidb_placement_mode": "STRICT", "tidb_pprof_sql_cpu": "0", "tidb_projection_concurrency": "-1", "tidb_query_log_max_len": "4096", "tidb_rc_read_check_ts": "OFF", "tidb_read_staleness": "", "tidb_record_plan_in_slow_log": "ON", "tidb_redact_log": "OFF", "tidb_regard_null_as_point": "ON", "tidb_remove_orderby_in_subquery": "OFF", "tidb_replica_read": "leader", "tidb_retry_limit": "10", "tidb_shard_allocate_step": "9223372036854775807", "tidb_skip_ascii_check": "OFF", "tidb_skip_isolation_level_check": "OFF", "tidb_skip_utf8_check": "OFF", "tidb_slow_log_threshold": "300", "tidb_streamagg_concurrency": "1", "tidb_sysdate_is_now": "OFF", "tidb_tmp_table_max_size": "67108864", "tidb_track_aggregate_memory_usage": "ON", "tidb_txn_mode": "", "tidb_use_plan_baselines": "ON", "tidb_window_concurrency": "-1", "time_zone": "SYSTEM", "transaction_isolation": "REPEATABLE-READ", "tx_isolation": "REPEATABLE-READ", "wait_timeout": "28800", "windowing_use_high_precision": "ON"}} |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> set @@tidb_window_concurrency=1;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> set session_states '{"system-vars": {"allow_auto_random_explicit_insert": "OFF", "auto_increment_increment": "1", "auto_increment_offset": "1", "autocommit": "ON", "block_encryption_mode": "aes-128-ecb", "character_set_client": "utf8mb4", "character_set_connection": "utf8mb4", "character_set_results": "utf8mb4", "character_set_server": "utf8mb4", "collation_connection": "utf8mb4_bin", "collation_server": "utf8mb4_bin", "cte_max_recursion_depth": "1000", "ddl_slow_threshold": "300", "default_week_format": "0", "identity": "0", "innodb_lock_wait_timeout": "50", "interactive_timeout": "28800", "last_insert_id": "0", "max_allowed_packet": "67108864", "max_execution_time": "0", "plugin_dir": "/data/deploy/plugin", "plugin_load": "", "rand_seed1": "0", "rand_seed2": "0", "sql_mode": "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION", "sql_select_limit": "18446744073709551615", "tidb_allow_batch_cop": "1", "tidb_allow_fallback_to_tikv": "", "tidb_allow_mpp": "ON", "tidb_analyze_version": "2", "tidb_backoff_lock_fast": "10", "tidb_backoff_weight": "2", "tidb_batch_pending_tiflash_count": "4000", "tidb_broadcast_join_threshold_count": "10240", "tidb_broadcast_join_threshold_size": "104857600", "tidb_check_mb4_value_in_utf8": "ON", "tidb_constraint_check_in_place": "OFF", "tidb_disable_txn_auto_retry": "ON", "tidb_distsql_scan_concurrency": "15", "tidb_dml_batch_size": "0", "tidb_enable_1pc": "OFF", "tidb_enable_amend_pessimistic_txn": "OFF", "tidb_enable_async_commit": "OFF", "tidb_enable_auto_increment_in_generated": "OFF", "tidb_enable_cascades_planner": "OFF", "tidb_enable_chunk_rpc": "1", "tidb_enable_clustered_index": "INT_ONLY", "tidb_enable_collect_execution_info": "ON", "tidb_enable_exchange_partition": "OFF", "tidb_enable_fast_analyze": "OFF", "tidb_enable_index_merge": "ON", "tidb_enable_legacy_instance_scope": "ON", "tidb_enable_list_partition": "OFF", "tidb_enable_new_only_full_group_by_check": "OFF", "tidb_enable_noop_functions": "OFF", "tidb_enable_ordered_result_mode": "OFF", "tidb_enable_parallel_apply": "OFF", "tidb_enable_pipelined_window_function": "ON", "tidb_enable_pseudo_for_outdated_stats": "ON", "tidb_enable_rate_limit_action": "ON", "tidb_enable_slow_log": "ON", "tidb_enable_strict_double_type_check": "ON", "tidb_enable_table_partition": "ON", "tidb_enable_vectorized_expression": "ON", "tidb_enable_window_function": "ON", "tidb_enforce_mpp": "OFF", "tidb_evolve_plan_baselines": "OFF", "tidb_executor_concurrency": "5", "tidb_expensive_query_time_threshold": "60", "tidb_force_priority": "NO_PRIORITY", "tidb_guarantee_linearizability": "ON", "tidb_hash_exchange_with_new_collation": "ON", "tidb_hash_join_concurrency": "-1", "tidb_hashagg_final_concurrency": "-1", "tidb_hashagg_partial_concurrency": "-1", "tidb_ignore_prepared_cache_close_stmt": "OFF", "tidb_index_join_batch_size": "25000", "tidb_index_lookup_concurrency": "-1", "tidb_index_lookup_join_concurrency": "-1", "tidb_index_lookup_size": "20000", "tidb_index_serial_scan_concurrency": "1", "tidb_init_chunk_size": "32", "tidb_isolation_read_engines": "tikv,tiflash,tidb", "tidb_log_file_max_days": "0", "tidb_max_chunk_size": "1024", "tidb_mem_quota_apply_cache": "33554432", "tidb_memory_usage_alarm_ratio": "0.8", "tidb_merge_join_concurrency": "1", "tidb_mpp_store_fail_ttl": "60s", "tidb_multi_statement_mode": "OFF", "tidb_opt_broadcast_cartesian_join": "1", "tidb_opt_concurrency_factor": "3", "tidb_opt_copcpu_factor": "3", "tidb_opt_correlation_exp_factor": "1", "tidb_opt_correlation_threshold": "0.9", "tidb_opt_cpu_factor": "3", "tidb_opt_desc_factor": "3", "tidb_opt_disk_factor": "1.5", "tidb_opt_enable_correlation_adjustment": "ON", "tidb_opt_insubq_to_join_and_agg": "ON", "tidb_opt_limit_push_down_threshold": "100", "tidb_opt_memory_factor": "0.001", "tidb_opt_mpp_outer_join_fixed_build_side": "OFF", "tidb_opt_network_factor": "1", "tidb_opt_prefer_range_scan": "OFF", "tidb_opt_scan_factor": "1.5", "tidb_placement_mode": "STRICT", "tidb_pprof_sql_cpu": "0", "tidb_projection_concurrency": "-1", "tidb_query_log_max_len": "4096", "tidb_rc_read_check_ts": "OFF", "tidb_read_staleness": "", "tidb_record_plan_in_slow_log": "ON", "tidb_redact_log": "OFF", "tidb_regard_null_as_point": "ON", "tidb_remove_orderby_in_subquery": "OFF", "tidb_replica_read": "leader", "tidb_retry_limit": "10", "tidb_shard_allocate_step": "9223372036854775807", "tidb_skip_ascii_check": "OFF", "tidb_skip_isolation_level_check": "OFF", "tidb_skip_utf8_check": "OFF", "tidb_slow_log_threshold": "300", "tidb_streamagg_concurrency": "1", "tidb_sysdate_is_now": "OFF", "tidb_tmp_table_max_size": "67108864", "tidb_track_aggregate_memory_usage": "ON", "tidb_txn_mode": "", "tidb_use_plan_baselines": "ON", "tidb_window_concurrency": "-1", "time_zone": "SYSTEM", "transaction_isolation": "REPEATABLE-READ", "tx_isolation": "REPEATABLE-READ", "wait_timeout": "28800", "windowing_use_high_precision": "ON"}}';
Query OK, 0 rows affected, 10 warnings (0.01 sec)

mysql> select @@tidb_window_concurrency;
+---------------------------+
| @@tidb_window_concurrency |
+---------------------------+
| -1                        |
+---------------------------+
1 row in set (0.00 sec)

@djshow832 djshow832 merged commit 9c14891 into session_mgr Apr 12, 2022
@djshow832 djshow832 deleted the sys_vars branch April 12, 2022 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant