diff --git a/sql-statements/sql-statement-do.md b/sql-statements/sql-statement-do.md index da9c399013e1..2f5c724b2f59 100644 --- a/sql-statements/sql-statement-do.md +++ b/sql-statements/sql-statement-do.md @@ -7,7 +7,13 @@ aliases: ['/docs-cn/dev/reference/sql/statements/do/'] # DO -`DO` 语句用于执行表达式,而不返回结果。在 MySQL 中,`DO` 的一个常见用例是执行存储的程序,而无需处理结果。但是 TiDB 不提供存储例程,因此该功能的使用较为受限。 +`DO` 语句用于执行表达式,但不返回任何结果。大部分情况下,`DO` 相当于不返回结果的 `SELECT expr, ...,`。 + +> **注意:** +> +> `DO` 只能执行表达式,所以不是所有能够用 `SELECT` 的地方都能用 `DO` 替换。例如 `DO id FROM t1` 就是不是合法的 SQL 语句,因为它引用了一张表。 + +`DO` 在 MySQL 中的一个主要应用场景是存储过程或者触发器。因为 TiDB 当前不支持存储过程和触发器,所以 `DO` 的实际使用场景较少。 ## 语法图 @@ -25,6 +31,8 @@ aliases: ['/docs-cn/dev/reference/sql/statements/do/'] ## 示例 +这条 `SELECT` 语句会暂停执行,但同时也会返回一个结果集。 + {{< copyable "sql" >}} ```sql @@ -40,6 +48,8 @@ SELECT SLEEP(5); 1 row in set (5.00 sec) ``` +如果使用 `DO` 的话,语句同样会暂停,但不会返回结果集。 + {{< copyable "sql" >}} ```sql diff --git a/sql-statements/sql-statement-set-variable.md b/sql-statements/sql-statement-set-variable.md index f58be0242c20..c4617343ee32 100644 --- a/sql-statements/sql-statement-set-variable.md +++ b/sql-statements/sql-statement-set-variable.md @@ -7,7 +7,11 @@ aliases: ['/docs-cn/dev/reference/sql/statements/set-variable/'] # SET [GLOBAL|SESSION] -`SET [GLOBAL|SESSION]` 语句用于在 `SESSION` 或 `GLOBAL` 的范围内,对某个 TiDB 的内置变量进行更改。需注意,对 `GLOBAL` 变量的更改不适用于已有连接或本地连接,这与 MySQL 类似。只有新会话才会反映值的变化。 +`SET [GLOBAL|SESSION]` 语句用于在 `SESSION` 或 `GLOBAL` 的范围内,对某个 TiDB 的内置变量进行更改。 + +> **注意:** +> +> 与 MySQL 类似,对 `GLOBAL` 变量的更改不适用于已有连接或本地连接,只有新会话才会反映值的变化。 ## 语法图 @@ -15,8 +19,14 @@ aliases: ['/docs-cn/dev/reference/sql/statements/set-variable/'] ![SetStmt](/media/sqlgram/SetStmt.png) +**VariableAssignment:** + +![VariableAssignment](/media/sqlgram/VariableAssignment.png) + ## 示例 +获取 `sql_mode` 的值: + {{< copyable "sql" >}} ```sql @@ -47,6 +57,8 @@ SHOW SESSION VARIABLES LIKE 'sql_mode'; 1 row in set (0.00 sec) ``` +更新全局的 `sql_mode`: + {{< copyable "sql" >}} ```sql @@ -57,6 +69,8 @@ SET GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER'; Query OK, 0 rows affected (0.03 sec) ``` +检查更新之后的 `sql_mode` 的取值,可以看到 SESSION 级别的值没有更新: + {{< copyable "sql" >}} ```sql @@ -87,6 +101,8 @@ SHOW SESSION VARIABLES LIKE 'sql_mode'; 1 row in set (0.00 sec) ``` +`SET SESSION` 则可以立即生效: + {{< copyable "sql" >}} ```sql diff --git a/sql-statements/sql-statement-show-variables.md b/sql-statements/sql-statement-show-variables.md index a86d2b07b479..79388003c4d3 100644 --- a/sql-statements/sql-statement-show-variables.md +++ b/sql-statements/sql-statement-show-variables.md @@ -25,90 +25,128 @@ aliases: ['/docs-cn/dev/reference/sql/statements/show-variables/'] ## 示例 +查看 TiDB 定义的专用系统变量,关于这些变量的含义参见 [TiDB 专用系统变量和语法](/tidb-specific-system-variables.md)。 + {{< copyable "sql" >}} ```sql SHOW GLOBAL VARIABLES LIKE 'tidb%'; ``` -``` -+-------------------------------------+---------------+ -| Variable_name | Value | -+-------------------------------------+---------------+ -| tidb_ddl_error_count_limit | 512 | -| tidb_dml_batch_size | 20000 | -| tidb_force_priority | NO_PRIORITY | -| tidb_batch_insert | 0 | -| tidb_skip_utf8_check | 0 | -| tidb_backoff_lock_fast | 100 | -| tidb_opt_join_reorder_threshold | 0 | -| tidb_auto_analyze_end_time | 23:59 +0000 | -| tidb_slow_log_threshold | 300 | -| tidb_opt_correlation_exp_factor | 1 | -| tidb_mem_quota_sort | 1073741824 | -| tidb_current_ts | 0 | -| tidb_ddl_reorg_batch_size | 256 | -| tidb_checksum_table_concurrency | 4 | -| tidb_check_mb4_value_in_utf8 | 1 | -| tidb_distsql_scan_concurrency | 15 | -| tidb_optimizer_selectivity_level | 0 | -| tidb_opt_agg_push_down | 0 | -| tidb_max_chunk_size | 1024 | -| tidb_low_resolution_tso | 0 | -| tidb_index_lookup_size | 20000 | -| tidb_skip_isolation_level_check | 0 | -| tidb_opt_write_row_id | 0 | -| tidb_wait_split_region_finish | 1 | -| tidb_index_lookup_join_concurrency | 4 | -| tidb_mem_quota_indexlookupjoin | 34359738368 | -| tidb_replica_read | leader | -| tidb_ddl_reorg_priority | PRIORITY_LOW | -| tidb_batch_commit | 0 | -| tidb_mem_quota_mergejoin | 34359738368 | -| tidb_mem_quota_query | 34359738368 | -| tidb_batch_delete | 0 | -| tidb_build_stats_concurrency | 4 | -| tidb_enable_index_merge | 0 | -| tidb_enable_radix_join | 0 | -| tidb_retry_limit | 10 | -| tidb_query_log_max_len | 2048 | -| tidb_config | | -| tidb_ddl_reorg_worker_cnt | 4 | -| tidb_opt_insubq_to_join_and_agg | 1 | -| tidb_enable_vectorized_expression | 1 | -| tidb_mem_quota_hashjoin | 34359738368 | -| tidb_disable_txn_auto_retry | 1 | -| tidb_enable_window_function | 1 | -| tidb_init_chunk_size | 32 | -| tidb_constraint_check_in_place | 0 | -| tidb_wait_split_region_timeout | 300 | -| tidb_hash_join_concurrency | 5 | -| tidb_enable_fast_analyze | 0 | -| tidb_enable_cascades_planner | 0 | -| tidb_txn_mode | | -| tidb_index_serial_scan_concurrency | 1 | -| tidb_projection_concurrency | 4 | -| tidb_enable_noop_functions | 0 | -| tidb_index_lookup_concurrency | 4 | -| tidb_hashagg_partial_concurrency | 4 | -| tidb_general_log | 0 | -| tidb_enable_streaming | 0 | -| tidb_backoff_weight | 2 | -| tidb_mem_quota_topn | 34359738368 | -| tidb_scatter_region | 0 | -| tidb_index_join_batch_size | 25000 | -| tidb_snapshot | | -| tidb_expensive_query_time_threshold | 60 | -| tidb_slow_query_file | tidb-slow.log | -| tidb_auto_analyze_ratio | 0.5 | -| tidb_enable_table_partition | auto | -| tidb_auto_analyze_start_time | 00:00 +0000 | -| tidb_mem_quota_nestedloopapply | 34359738368 | -| tidb_mem_quota_indexlookupreader | 34359738368 | -| tidb_hashagg_final_concurrency | 4 | -| tidb_opt_correlation_threshold | 0.9 | -+-------------------------------------+---------------+ -68 rows in set (0.01 sec) +```sql ++-------------------------------------+---------------------+ +| Variable_name | Value | ++-------------------------------------+---------------------+ +| tidb_allow_batch_cop | 0 | +| tidb_allow_remove_auto_inc | 0 | +| tidb_auto_analyze_end_time | 23:59 +0000 | +| tidb_auto_analyze_ratio | 0.5 | +| tidb_auto_analyze_start_time | 00:00 +0000 | +| tidb_backoff_lock_fast | 100 | +| tidb_backoff_weight | 2 | +| tidb_batch_commit | 0 | +| tidb_batch_delete | 0 | +| tidb_batch_insert | 0 | +| tidb_build_stats_concurrency | 4 | +| tidb_capture_plan_baselines | off | +| tidb_check_mb4_value_in_utf8 | 1 | +| tidb_checksum_table_concurrency | 4 | +| tidb_config | | +| tidb_constraint_check_in_place | 0 | +| tidb_current_ts | 0 | +| tidb_ddl_error_count_limit | 512 | +| tidb_ddl_reorg_batch_size | 256 | +| tidb_ddl_reorg_priority | PRIORITY_LOW | +| tidb_ddl_reorg_worker_cnt | 4 | +| tidb_disable_txn_auto_retry | 1 | +| tidb_distsql_scan_concurrency | 15 | +| tidb_dml_batch_size | 20000 | +| tidb_enable_cascades_planner | 0 | +| tidb_enable_chunk_rpc | 1 | +| tidb_enable_collect_execution_info | 1 | +| tidb_enable_fast_analyze | 0 | +| tidb_enable_index_merge | 0 | +| tidb_enable_noop_functions | 0 | +| tidb_enable_radix_join | 0 | +| tidb_enable_slow_log | 1 | +| tidb_enable_stmt_summary | 1 | +| tidb_enable_streaming | 0 | +| tidb_enable_table_partition | on | +| tidb_enable_vectorized_expression | 1 | +| tidb_enable_window_function | 1 | +| tidb_evolve_plan_baselines | off | +| tidb_evolve_plan_task_end_time | 23:59 +0000 | +| tidb_evolve_plan_task_max_time | 600 | +| tidb_evolve_plan_task_start_time | 00:00 +0000 | +| tidb_expensive_query_time_threshold | 60 | +| tidb_force_priority | NO_PRIORITY | +| tidb_general_log | 0 | +| tidb_hash_join_concurrency | 5 | +| tidb_hashagg_final_concurrency | 4 | +| tidb_hashagg_partial_concurrency | 4 | +| tidb_index_join_batch_size | 25000 | +| tidb_index_lookup_concurrency | 4 | +| tidb_index_lookup_join_concurrency | 4 | +| tidb_index_lookup_size | 20000 | +| tidb_index_serial_scan_concurrency | 1 | +| tidb_init_chunk_size | 32 | +| tidb_isolation_read_engines | tikv, tiflash, tidb | +| tidb_low_resolution_tso | 0 | +| tidb_max_chunk_size | 1024 | +| tidb_max_delta_schema_count | 1024 | +| tidb_mem_quota_hashjoin | 34359738368 | +| tidb_mem_quota_indexlookupjoin | 34359738368 | +| tidb_mem_quota_indexlookupreader | 34359738368 | +| tidb_mem_quota_mergejoin | 34359738368 | +| tidb_mem_quota_nestedloopapply | 34359738368 | +| tidb_mem_quota_query | 1073741824 | +| tidb_mem_quota_sort | 34359738368 | +| tidb_mem_quota_topn | 34359738368 | +| tidb_metric_query_range_duration | 60 | +| tidb_metric_query_step | 60 | +| tidb_opt_agg_push_down | 0 | +| 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_distinct_agg_push_down | 0 | +| tidb_opt_insubq_to_join_and_agg | 1 | +| tidb_opt_join_reorder_threshold | 0 | +| tidb_opt_memory_factor | 0.001 | +| tidb_opt_network_factor | 1 | +| tidb_opt_scan_factor | 1.5 | +| tidb_opt_seek_factor | 20 | +| tidb_opt_write_row_id | 0 | +| tidb_optimizer_selectivity_level | 0 | +| tidb_pprof_sql_cpu | 0 | +| tidb_projection_concurrency | 4 | +| tidb_query_log_max_len | 4096 | +| tidb_record_plan_in_slow_log | 1 | +| tidb_replica_read | leader | +| tidb_retry_limit | 10 | +| tidb_row_format_version | 2 | +| tidb_scatter_region | 0 | +| tidb_skip_isolation_level_check | 0 | +| tidb_skip_utf8_check | 0 | +| tidb_slow_log_threshold | 300 | +| tidb_slow_query_file | tidb-slow.log | +| tidb_snapshot | | +| tidb_stmt_summary_history_size | 24 | +| tidb_stmt_summary_internal_query | 0 | +| tidb_stmt_summary_max_sql_length | 4096 | +| tidb_stmt_summary_max_stmt_count | 200 | +| tidb_stmt_summary_refresh_interval | 1800 | +| tidb_store_limit | 0 | +| tidb_txn_mode | | +| tidb_use_plan_baselines | on | +| tidb_wait_split_region_finish | 1 | +| tidb_wait_split_region_timeout | 300 | +| tidb_window_concurrency | 4 | ++-------------------------------------+---------------------+ +108 rows in set (0.01 sec) ``` {{< copyable "sql" >}}