From dbe97ac39686fc8b4c25b56abd5dd8c6eba3fca3 Mon Sep 17 00:00:00 2001 From: dbsid Date: Tue, 24 Dec 2024 18:39:09 +0800 Subject: [PATCH] add tidb_analyze_column_options to avoid bad plan (#19783) --- tidb-performance-tuning-config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tidb-performance-tuning-config.md b/tidb-performance-tuning-config.md index ba6c490a28668..234bbbd731386 100644 --- a/tidb-performance-tuning-config.md +++ b/tidb-performance-tuning-config.md @@ -41,6 +41,7 @@ SET GLOBAL tidb_enable_instance_plan_cache=on; SET GLOBAL tidb_instance_plan_cache_max_size=2GiB; SET GLOBAL tidb_enable_non_prepared_plan_cache=on; SET GLOBAL tidb_ignore_prepared_cache_close_stmt=on; +SET GLOBAL tidb_analyze_column_options='ALL'; SET GLOBAL tidb_enable_inl_join_inner_multi_pattern=on; SET GLOBAL tidb_opt_derive_topn=on; SET GLOBAL tidb_runtime_filter_mode=LOCAL; @@ -58,6 +59,7 @@ The following table outlines the impact of specific system variable configuratio | [`tidb_enable_instance_plan_cache`](/system-variables.md#tidb_enable_instance_plan_cache-new-in-v840) and [`tidb_instance_plan_cache_max_size`](/system-variables.md#tidb_instance_plan_cache_max_size-new-in-v840)| Use instance-level plan cache instead of session-level caching. This significantly improves performance for workloads with high connection counts or frequent prepared statement usage. | This is an experimental feature. Test in non-production environments first and monitor memory usage as the plan cache size increases. | | [`tidb_enable_non_prepared_plan_cache`](/system-variables.md#tidb_enable_non_prepared_plan_cache)| Enable the [Non-prepared plan cache](/sql-non-prepared-plan-cache.md) feature to reduce compile costs for applications that do not use prepared statements. | N/A | | [`tidb_ignore_prepared_cache_close_stmt`](/system-variables.md#tidb_ignore_prepared_cache_close_stmt-new-in-v600)| Cache plans for applications that use prepared statements but close the plan after each execution. | N/A | +| [`tidb_analyze_column_options`](/system-variables.md#tidb_analyze_column_options-new-in-v830)| Collect statistics for all columns to avoid suboptimal execution plans due to missing column statistics. By default, TiDB only collects statistics for [predicate columns](/statistics.md#collect-statistics-on-some-columns). | Setting this variable to `'ALL'` can cause more resource usage for the `ANALYZE TABLE` operation compared with the default value `'PREDICATE'`. | | [`tidb_enable_inl_join_inner_multi_pattern`](/system-variables.md#tidb_enable_inl_join_inner_multi_pattern-new-in-v700)| Enable Index Join support when the inner table has `Selection` or `Projection` operators on it. | N/A | | [`tidb_opt_derive_topn`](/system-variables.md#tidb_opt_derive_topn-new-in-v700)| Enable the optimization rule of [Deriving TopN or Limit from window functions](/derive-topn-from-window.md). | This is limited to the `ROW_NUMBER()` window function. | | [`tidb_runtime_filter_mode`](/system-variables.md#tidb_runtime_filter_mode-new-in-v720)| Enable [Runtime Filter](/runtime-filter.md#runtime-filter-mode) in the local mode to improve hash join efficiency. | The variable is introduced in v7.2.0 and is disabled by default for safety. |