From 4956a2b9ceebf9c8f1eb0581a298dbcbaf0f4818 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Mon, 29 Jan 2024 09:57:34 +0000 Subject: [PATCH 1/5] Removed the limitation on plan cache for partitioned tables. Both for prepared statements and non-prepared statements. But only for tidb_partition_prune_mode = `dynamic`. --- partitioned-table.md | 2 +- sql-non-prepared-plan-cache.md | 2 +- sql-prepared-plan-cache.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/partitioned-table.md b/partitioned-table.md index 1b80da4c7beb1..51bd1748f0c30 100644 --- a/partitioned-table.md +++ b/partitioned-table.md @@ -1987,7 +1987,7 @@ mysql> explain select /*+ TIDB_INLJ(t1, t2) */ t1.* from t1, t2 where t2.code = From example 2, you can see that in `dynamic` mode, the execution plan with IndexJoin is selected when you execute the query. -Currently, neither `static` nor `dynamic` pruning mode supports prepared statements plan cache. +Currently, `static` pruning mode does not support plan cache, neither for prepared statmements nor non-prepared statements. #### Update statistics of partitioned tables in dynamic pruning mode diff --git a/sql-non-prepared-plan-cache.md b/sql-non-prepared-plan-cache.md index 35eb61467fd5b..1378361f75c97 100644 --- a/sql-non-prepared-plan-cache.md +++ b/sql-non-prepared-plan-cache.md @@ -87,7 +87,7 @@ Due to the preceding risks and the fact that the execution plan cache only provi - Queries that filter on columns of `JSON`, `ENUM`, `SET`, or `BIT` type are not supported, such as `SELECT * FROM t WHERE json_col = '{}'`. - Queries that filter on `NULL` values are not supported, such as `SELECT * FROM t WHERE a is NULL`. - Queries with more than 200 parameters after parameterization are not supported by default, such as `SELECT * FROM t WHERE a in (1, 2, 3, ... 201)`. Starting from v7.3.0, you can modify this limit by setting the [`44823`](/optimizer-fix-controls.md#44823-new-in-v730) fix in the [`tidb_opt_fix_control`](/system-variables.md#tidb_opt_fix_control-new-in-v653-and-v710) system variable. -- Queries that access partitioned tables, virtual columns, temporary tables, views, or memory tables are not supported, such as `SELECT * FROM INFORMATION_SCHEMA.COLUMNS`, where `COLUMNS` is a TiDB memory table. +- Queries that access virtual columns, temporary tables, views, or memory tables are not supported, such as `SELECT * FROM INFORMATION_SCHEMA.COLUMNS`, where `COLUMNS` is a TiDB memory table. - Queries with hints or bindings are not supported. - DML statements or `SELECT` statements with the `FOR UPDATE` clause are not supported by default. To remove this restriction, you can execute `SET tidb_enable_non_prepared_plan_cache_for_dml = ON`. diff --git a/sql-prepared-plan-cache.md b/sql-prepared-plan-cache.md index 2c3bb789993f3..07786ff8d2e05 100644 --- a/sql-prepared-plan-cache.md +++ b/sql-prepared-plan-cache.md @@ -20,7 +20,7 @@ TiDB also supports execution plan caching for some non-`PREPARE` statements, sim In the current version of TiDB, if a `Prepare` statement meets any of the following conditions, the query or the plan is not cached: - The query contains SQL statements other than `SELECT`, `UPDATE`, `INSERT`, `DELETE`, `Union`, `Intersect`, and `Except`. -- The query accesses partitioned tables or temporary tables, or a table that contains generated columns. +- The query accesses temporary tables, or a table that contains generated columns. - The query contains non-correlated sub-queries, such as `SELECT * FROM t1 WHERE t1.a > (SELECT 1 FROM t2 WHERE t2.b < 1)`. - The query contains correlated sub-queries with `PhysicalApply` operators in the execution plan, such as `SELECT * FROM t1 WHERE t1.a > (SELECT a FROM t2 WHERE t1.b > t2.b)`. - The query contains the `ignore_plan_cache` or `set_var` hint, such as `SELECT /*+ ignore_plan_cache() */ * FROM t` or `SELECT /*+ set_var(max_execution_time=1) */ * FROM t`. From 8ce75f9ca244677e7da206b1195b16c02bc97ea7 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Thu, 29 Feb 2024 18:32:42 +0800 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: Aolin --- partitioned-table.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partitioned-table.md b/partitioned-table.md index 51bd1748f0c30..ce0e7d0abb38b 100644 --- a/partitioned-table.md +++ b/partitioned-table.md @@ -1987,7 +1987,7 @@ mysql> explain select /*+ TIDB_INLJ(t1, t2) */ t1.* from t1, t2 where t2.code = From example 2, you can see that in `dynamic` mode, the execution plan with IndexJoin is selected when you execute the query. -Currently, `static` pruning mode does not support plan cache, neither for prepared statmements nor non-prepared statements. +Currently, `static` pruning mode does not support plan cache for both prepared and non-prepared statements. #### Update statistics of partitioned tables in dynamic pruning mode From 30b1d4e3496f173b059f6f0b76f9ed1106c34376 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 12 Mar 2024 10:18:34 +0100 Subject: [PATCH 3/5] Added Fix-control for 33031 --- optimizer-fix-controls.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/optimizer-fix-controls.md b/optimizer-fix-controls.md index de8b98807d664..b5c728d92aafd 100644 --- a/optimizer-fix-controls.md +++ b/optimizer-fix-controls.md @@ -26,6 +26,12 @@ SET SESSION tidb_opt_fix_control = '44262:ON,44389:ON'; ## Optimizer Fix Controls reference +### [`33031`](https://github.com/pingcap/tidb/issues/33031) New in v8.0.0 + +- Default value: `OFF` +- Possible values: `ON`, `OFF` +- This variable controls whether to allow plan cache for partitioned tables. If ON neither [Prepared statement cache](/sql-prepared-plan-cache.md) nor [Non-prepared statement cache](/sql-non-prepared-plan-cache.md) will be enabled for [partitioned tables](/partitioned-table.md). + ### [`44262`](https://github.com/pingcap/tidb/issues/44262) New in v6.5.3 and v7.2.0 - Default value: `OFF` @@ -63,4 +69,4 @@ SET SESSION tidb_opt_fix_control = '44262:ON,44389:ON'; - Default value: `1000` - Possible values: `[0, 2147483647]` - This variable sets the threshold for the optimizer's heuristic strategy to select access paths. If the estimated rows for an access path (such as `Index_A`) is much smaller than that of other access paths (default `1000` times), the optimizer skips the cost comparison and directly selects `Index_A`. -- `0` means to disable this heuristic strategy. \ No newline at end of file +- `0` means to disable this heuristic strategy. From e0364d0a0c1e219281ca876f37442b5ee6393182 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Tue, 19 Mar 2024 10:57:22 +0800 Subject: [PATCH 4/5] Update optimizer-fix-controls.md --- optimizer-fix-controls.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizer-fix-controls.md b/optimizer-fix-controls.md index b5c728d92aafd..de0f2326c2ef1 100644 --- a/optimizer-fix-controls.md +++ b/optimizer-fix-controls.md @@ -30,7 +30,7 @@ SET SESSION tidb_opt_fix_control = '44262:ON,44389:ON'; - Default value: `OFF` - Possible values: `ON`, `OFF` -- This variable controls whether to allow plan cache for partitioned tables. If ON neither [Prepared statement cache](/sql-prepared-plan-cache.md) nor [Non-prepared statement cache](/sql-non-prepared-plan-cache.md) will be enabled for [partitioned tables](/partitioned-table.md). +- This variable controls whether to allow plan cache for partitioned tables. If it is set to `ON`, neither [Prepared statement cache](/sql-prepared-plan-cache.md) nor [Non-prepared statement cache](/sql-non-prepared-plan-cache.md) will be enabled for [partitioned tables](/partitioned-table.md). ### [`44262`](https://github.com/pingcap/tidb/issues/44262) New in v6.5.3 and v7.2.0 From 35d380dd2d979ea29f97c412bccb338fbae57451 Mon Sep 17 00:00:00 2001 From: xixirangrang Date: Tue, 19 Mar 2024 20:35:00 +0800 Subject: [PATCH 5/5] Update optimizer-fix-controls.md --- optimizer-fix-controls.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimizer-fix-controls.md b/optimizer-fix-controls.md index de0f2326c2ef1..e79f2613bb480 100644 --- a/optimizer-fix-controls.md +++ b/optimizer-fix-controls.md @@ -30,7 +30,7 @@ SET SESSION tidb_opt_fix_control = '44262:ON,44389:ON'; - Default value: `OFF` - Possible values: `ON`, `OFF` -- This variable controls whether to allow plan cache for partitioned tables. If it is set to `ON`, neither [Prepared statement cache](/sql-prepared-plan-cache.md) nor [Non-prepared statement cache](/sql-non-prepared-plan-cache.md) will be enabled for [partitioned tables](/partitioned-table.md). +- This variable controls whether to allow plan cache for partitioned tables. If it is set to `ON`, neither [Prepared statement plan cache](/sql-prepared-plan-cache.md) nor [Non-prepared statement plan cache](/sql-non-prepared-plan-cache.md) will be enabled for [partitioned tables](/partitioned-table.md). ### [`44262`](https://github.com/pingcap/tidb/issues/44262) New in v6.5.3 and v7.2.0