table partition: add more warnings to inform the user that setting TiDB partition prune mode to dynamic at session level (#35046)

close pingcap/tidb#35042
This commit is contained in:
Ming Yu
2022-05-31 18:04:27 +08:00
committed by GitHub
parent b965154a44
commit e2fd394fbf
2 changed files with 15 additions and 0 deletions

View File

@ -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

View File

@ -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"))
}