diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 59a058746a..9ee43476be 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1406,6 +1406,7 @@ var defaultSysVars = []*SysVar{ newMode := strings.ToLower(strings.TrimSpace(val)) if PartitionPruneMode(s.PartitionPruneMode.Load()) == Static && PartitionPruneMode(newMode) == Dynamic { s.StmtCtx.AppendWarning(errors.New("Please analyze all partition tables again for consistency between partition and global stats")) + s.StmtCtx.AppendWarning(errors.New("Please avoid setting partition prune mode to dynamic at session level and set partition prune mode to dynamic at global level")) } s.PartitionPruneMode.Store(newMode) return nil diff --git a/table/tables/partition_test.go b/table/tables/partition_test.go index 8f3f9b6e2b..970a479aaa 100644 --- a/table/tables/partition_test.go +++ b/table/tables/partition_test.go @@ -729,3 +729,17 @@ func TestIssue31721(t *testing.T) { tk.MustExec("insert into t_31721 values ('1')") tk.MustExec("select * from t_31721 partition(p0, p1) where col1 != 2;") } + +func TestPruneModeWarningInfo(t *testing.T) { + store, _, clean := testkit.CreateMockStoreAndDomain(t) + defer clean() + + tk := testkit.NewTestKit(t, store) + tk.MustExec("set @@tidb_partition_prune_mode = 'static'") + tk.MustQuery("show warnings").Check(testkit.Rows()) + tk.MustExec("set session tidb_partition_prune_mode = 'dynamic'") + tk.MustQuery("show warnings").Sort().Check(testkit.Rows("Warning 1105 Please analyze all partition tables again for consistency between partition and global stats", + "Warning 1105 Please avoid setting partition prune mode to dynamic at session level and set partition prune mode to dynamic at global level")) + tk.MustExec("set global tidb_partition_prune_mode = 'dynamic'") + tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Please analyze all partition tables again for consistency between partition and global stats")) +}