From 3fea65e53973228ce285edfc3d21835ec1a8b344 Mon Sep 17 00:00:00 2001 From: shichun-0415 Date: Mon, 30 Jan 2023 17:16:52 +0800 Subject: [PATCH 1/5] planner: prepared plan cache support limit --- sql-prepared-plan-cache.md | 1 - 1 file changed, 1 deletion(-) diff --git a/sql-prepared-plan-cache.md b/sql-prepared-plan-cache.md index ebfffc30fe440..06d9aee29aca1 100644 --- a/sql-prepared-plan-cache.md +++ b/sql-prepared-plan-cache.md @@ -23,7 +23,6 @@ In the current version of TiDB, if a `Prepare` statement meets any of the follow - The query contains the `ignore_plan_cache` hint, such as `select /*+ ignore_plan_cache() */ * from t`. - The query contains variables other than `?` (including system variables or user-defined variables), such as `select * from t where a>? and b>@x`. - The query contains the functions that cannot be cached: `database()`, `current_user`, `current_role`, `user`, `connection_id`, `last_insert_id`, `row_count`, `version`, and `like`. -- The query contains `?` after `Limit`, such as `Limit ?` and `Limit 10, ?`. Such queries are not cached because the specific value of `?` has a great impact on query performance. - The query contains `?` after `Order By`, such as `Order By ?`. Such queries sort data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Order By a+?`, it is cached. - The query contains `?` after `Group By`, such as `Group By?`. Such queries group data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Group By a+?`, it is cached. - The query contains `?` in the definition of the `Window Frame` window function, such as `(partition by year order by sale rows ? preceding)`. If `?` appears elsewhere in the window function, the query is cached. From 5ae5c040c757add2652e63916690c524b335cab1 Mon Sep 17 00:00:00 2001 From: shichun-0415 Date: Mon, 6 Feb 2023 14:03:32 +0800 Subject: [PATCH 2/5] update according to Chinese --- sql-prepared-plan-cache.md | 1 + system-variables.md | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/sql-prepared-plan-cache.md b/sql-prepared-plan-cache.md index 06d9aee29aca1..c56a492321cc9 100644 --- a/sql-prepared-plan-cache.md +++ b/sql-prepared-plan-cache.md @@ -23,6 +23,7 @@ In the current version of TiDB, if a `Prepare` statement meets any of the follow - The query contains the `ignore_plan_cache` hint, such as `select /*+ ignore_plan_cache() */ * from t`. - The query contains variables other than `?` (including system variables or user-defined variables), such as `select * from t where a>? and b>@x`. - The query contains the functions that cannot be cached: `database()`, `current_user`, `current_role`, `user`, `connection_id`, `last_insert_id`, `row_count`, `version`, and `like`. +- The query with `Count` being `?` after `Limit` and the `Count` value is greater than 10000. - The query contains `?` after `Order By`, such as `Order By ?`. Such queries sort data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Order By a+?`, it is cached. - The query contains `?` after `Group By`, such as `Group By?`. Such queries group data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Group By a+?`, it is cached. - The query contains `?` in the definition of the `Window Frame` window function, such as `(partition by year order by sale rows ? preceding)`. If `?` appears elsewhere in the window function, the query is cached. diff --git a/system-variables.md b/system-variables.md index 6a9034a86cd8e..e3a79ca209184 100644 --- a/system-variables.md +++ b/system-variables.md @@ -1726,7 +1726,15 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a - Persists to cluster: Yes - Type: Boolean - Default value: `ON` -- This variables specifies whether to use the pipeline execution algorithm for window functions. +- This variable specifies whether to use the pipeline execution algorithm for window functions. + +### `tidb_enable_plan_cache_for_param_limit` New in v6.6.0 + +- Scope: SESSION | GLOBAL +- Persists to cluster: Yes +- Type: Boolean +- Default value: `ON` +- This variable controls whether Prepared Plan Cache caches execution plans that contain `count` after `Limit`. The default value is `ON`, which means Prepared Plan Cache supports caching such execution plans. Note that Prepared Plan Cache does not support caching execution plans with a `count` that is greater than 10000. ### tidb_enable_plan_replayer_capture From 09b88c03075e695cd3c718c8d9c7dc813c3fa752 Mon Sep 17 00:00:00 2001 From: shichun-0415 Date: Mon, 6 Feb 2023 14:06:28 +0800 Subject: [PATCH 3/5] fix `count` --- system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-variables.md b/system-variables.md index e3a79ca209184..72e0809b3e7c5 100644 --- a/system-variables.md +++ b/system-variables.md @@ -1734,7 +1734,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a - Persists to cluster: Yes - Type: Boolean - Default value: `ON` -- This variable controls whether Prepared Plan Cache caches execution plans that contain `count` after `Limit`. The default value is `ON`, which means Prepared Plan Cache supports caching such execution plans. Note that Prepared Plan Cache does not support caching execution plans with a `count` that is greater than 10000. +- This variable controls whether Prepared Plan Cache caches execution plans with `Count` being `?` after `Limit`. The default value is `ON`, which means Prepared Plan Cache supports caching such execution plans. Note that Prepared Plan Cache does not support caching execution plans with a `Count` that is greater than 10000. ### tidb_enable_plan_replayer_capture From fdae727c19aa2f527344293623e2070543d32c95 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 16 Feb 2023 18:38:28 +0800 Subject: [PATCH 4/5] Update sql-prepared-plan-cache.md Co-authored-by: Aolin --- sql-prepared-plan-cache.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-prepared-plan-cache.md b/sql-prepared-plan-cache.md index c56a492321cc9..b25f68f981cb3 100644 --- a/sql-prepared-plan-cache.md +++ b/sql-prepared-plan-cache.md @@ -23,7 +23,7 @@ In the current version of TiDB, if a `Prepare` statement meets any of the follow - The query contains the `ignore_plan_cache` hint, such as `select /*+ ignore_plan_cache() */ * from t`. - The query contains variables other than `?` (including system variables or user-defined variables), such as `select * from t where a>? and b>@x`. - The query contains the functions that cannot be cached: `database()`, `current_user`, `current_role`, `user`, `connection_id`, `last_insert_id`, `row_count`, `version`, and `like`. -- The query with `Count` being `?` after `Limit` and the `Count` value is greater than 10000. +- The query with a variable as the `LIMIT` parameter (`LIMIT ?`) and the variable value is greater than 10000. - The query contains `?` after `Order By`, such as `Order By ?`. Such queries sort data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Order By a+?`, it is cached. - The query contains `?` after `Group By`, such as `Group By?`. Such queries group data based on the column specified by `?`. If the queries targeting different columns use the same execution plan, the results will be wrong. Therefore, such queries are not cached. However, if the query is a common one, such as `Group By a+?`, it is cached. - The query contains `?` in the definition of the `Window Frame` window function, such as `(partition by year order by sale rows ? preceding)`. If `?` appears elsewhere in the window function, the query is cached. From c14d31edb4882498a3886e9a6ef06a03259cbde9 Mon Sep 17 00:00:00 2001 From: shichun-0415 <89768198+shichun-0415@users.noreply.github.com> Date: Thu, 16 Feb 2023 18:59:13 +0800 Subject: [PATCH 5/5] Update system-variables.md --- system-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-variables.md b/system-variables.md index 72e0809b3e7c5..bacc74ededf0f 100644 --- a/system-variables.md +++ b/system-variables.md @@ -1734,7 +1734,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a - Persists to cluster: Yes - Type: Boolean - Default value: `ON` -- This variable controls whether Prepared Plan Cache caches execution plans with `Count` being `?` after `Limit`. The default value is `ON`, which means Prepared Plan Cache supports caching such execution plans. Note that Prepared Plan Cache does not support caching execution plans with a `Count` that is greater than 10000. +- This variable controls whether Prepared Plan Cache caches execution plans with a variable as the `LIMIT` parameter (`LIMIT ?`). The default value is `ON`, which means Prepared Plan Cache supports caching such execution plans. Note that Prepared Plan Cache does not support caching execution plans with a variable that is greater than 10000. ### tidb_enable_plan_replayer_capture