From f0932bb6f953477bd80a0bdd8ba162127779c154 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Mon, 12 Jun 2023 11:13:45 -0700 Subject: [PATCH 1/2] stats: clarify configuration persistence of analyze statement Signed-off-by: Jack Yu --- statistics.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/statistics.md b/statistics.md index 99f549fbedf1d..644b0ee64e1a7 100644 --- a/statistics.md +++ b/statistics.md @@ -470,7 +470,13 @@ The `ANALYZE` configuration persistence feature is disabled by default. To enabl You can use this feature to record the persistence configurations specified in the `ANALYZE` statement when executing the statement manually. Once recorded, the next time TiDB automatically updates statistics or you manually collect statistics without specifying these configuration, TiDB will collect statistics according to the recorded configurations. -When you manually execute the `ANALYZE` statement multiple times with persistence configurations specified, TiDB overwrites the previously recorded persistent configuration using the new configurations specified by the latest `ANALYZE` statement. +You can use the following SQL to query the configuration used by auto-analyze that is persisted on a certain table. + +```sql +select sample_num, sample_rate, buckets, topn, column_choice, column_ids from mysql.analyze_options opt join information_schema.tables tbl on opt.table_id = tbl.tidb_table_id where tbl.table_schema = '{db_name}' and tbl.table_name = '{table_name}'; +``` + +TiDB will overwrite the previously recorded persistent configuration using the new configurations specified by the latest `ANALYZE` statement. For instance, if you run "analyze table t with 200 topn;", it will set the 200 topn values in `ANALYZE` statement. Then, executing "analyze table t with 0.1 samplerate;" will set both 200 topn values and a sampling rate of 0.1 for auto `ANALYZE` statement, like "analyze table t with 200 topn, 0.1 samplerate;". #### Disable ANALYZE configuration persistence From fb3c43ab63feb0510b21d29311c0246d0d89f1ab Mon Sep 17 00:00:00 2001 From: Ran Date: Wed, 20 Dec 2023 09:01:42 +0800 Subject: [PATCH 2/2] Apply suggestions from code review --- statistics.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/statistics.md b/statistics.md index 644b0ee64e1a7..a9412448f049b 100644 --- a/statistics.md +++ b/statistics.md @@ -470,13 +470,13 @@ The `ANALYZE` configuration persistence feature is disabled by default. To enabl You can use this feature to record the persistence configurations specified in the `ANALYZE` statement when executing the statement manually. Once recorded, the next time TiDB automatically updates statistics or you manually collect statistics without specifying these configuration, TiDB will collect statistics according to the recorded configurations. -You can use the following SQL to query the configuration used by auto-analyze that is persisted on a certain table. +To query the configuration persisted on a specific table used for auto analyze operations, you can use the following SQL statement: ```sql -select sample_num, sample_rate, buckets, topn, column_choice, column_ids from mysql.analyze_options opt join information_schema.tables tbl on opt.table_id = tbl.tidb_table_id where tbl.table_schema = '{db_name}' and tbl.table_name = '{table_name}'; +SELECT sample_num, sample_rate, buckets, topn, column_choice, column_ids FROM mysql.analyze_options opt JOIN information_schema.tables tbl ON opt.table_id = tbl.tidb_table_id WHERE tbl.table_schema = '{db_name}' AND tbl.table_name = '{table_name}'; ``` -TiDB will overwrite the previously recorded persistent configuration using the new configurations specified by the latest `ANALYZE` statement. For instance, if you run "analyze table t with 200 topn;", it will set the 200 topn values in `ANALYZE` statement. Then, executing "analyze table t with 0.1 samplerate;" will set both 200 topn values and a sampling rate of 0.1 for auto `ANALYZE` statement, like "analyze table t with 200 topn, 0.1 samplerate;". +TiDB will overwrite the previously recorded persistent configuration using the new configurations specified by the latest `ANALYZE` statement. For example, if you run `ANALYZE TABLE t WITH 200 TOPN;`, it will set the top 200 values in the `ANALYZE` statement. Subsequently, executing `ANALYZE TABLE t WITH 0.1 SAMPLERATE;` will set both the top 200 values and a sampling rate of 0.1 for auto `ANALYZE` statements, similar to `ANALYZE TABLE t WITH 200 TOPN, 0.1 SAMPLERATE;`. #### Disable ANALYZE configuration persistence