Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
May 31, 2022
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is still not clear why one should use global level in the warning. Maybe a link to documentation to explain the reason?

}
s.PartitionPruneMode.Store(newMode)
return nil
Expand Down
11 changes: 11 additions & 0 deletions table/tables/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,3 +729,14 @@ 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 TestPruneMode(t *testing.T) {
ymkzpx marked this conversation as resolved.
Show resolved Hide resolved
store, _, clean := testkit.CreateMockStoreAndDomain(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("set @@tidb_partition_prune_mode = 'static'")
ymkzpx marked this conversation as resolved.
Show resolved Hide resolved
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"))
ymkzpx marked this conversation as resolved.
Show resolved Hide resolved
}