Skip to content

Commit

Permalink
Added tests (from #35085)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss committed Sep 14, 2022
1 parent 9ac1c88 commit 45e7f33
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
30 changes: 30 additions & 0 deletions executor/partition_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ import (
"github.com/stretchr/testify/require"
)

func TestSetPartitionPruneMode(t *testing.T) {
store := testkit.CreateMockStore(t)

tkInit := testkit.NewTestKit(t, store)
tkInit.MustExec(`set @@session.tidb_partition_prune_mode = DEFAULT`)
tkInit.MustQuery("show warnings").Check(testkit.Rows())
tkInit.MustExec(`set @@global.tidb_partition_prune_mode = DEFAULT`)
tkInit.MustQuery("show warnings").Check(testkit.Rows("Warning 1105 Please analyze all partition tables again for consistency between partition and global stats"))
tk := testkit.NewTestKit(t, store)
tk.MustQuery("select @@global.tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
tk.MustQuery("select @@session.tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
tk.MustExec(`set @@session.tidb_partition_prune_mode = "static"`)
tk.MustQuery("show warnings").Check(testkit.Rows())
tk.MustExec(`set @@global.tidb_partition_prune_mode = "static"`)
tk.MustQuery("show warnings").Check(testkit.Rows())
tk2 := testkit.NewTestKit(t, store)
tk2.MustQuery("select @@session.tidb_partition_prune_mode").Check(testkit.Rows("static"))
tk2.MustQuery("show warnings").Check(testkit.Rows())
tk2.MustQuery("select @@global.tidb_partition_prune_mode").Check(testkit.Rows("static"))
tk2.MustExec(`set @@session.tidb_partition_prune_mode = "dynamic"`)
tk2.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`))
tk2.MustExec(`set @@global.tidb_partition_prune_mode = "dynamic"`)
tk2.MustQuery("show warnings").Check(testkit.Rows(`Warning 1105 Please analyze all partition tables again for consistency between partition and global stats`))
tk3 := testkit.NewTestKit(t, store)
tk3.MustQuery("select @@global.tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
tk3.MustQuery("select @@session.tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
}

func TestFourReader(t *testing.T) {
failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`)
defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune")
Expand Down
11 changes: 11 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,17 @@ func TestDefaultMemoryDebugModeValue(t *testing.T) {
require.Equal(t, val, "0")
}

func TestDefaultPartitionPruneMode(t *testing.T) {
vars := NewSessionVars()
mock := NewMockGlobalAccessor4Tests()
mock.SessionVars = vars
vars.GlobalVarsAccessor = mock
val, err := vars.GetSessionOrGlobalSystemVar(TiDBPartitionPruneMode)
require.NoError(t, err)
require.Equal(t, "dynamic", val)
require.Equal(t, "dynamic", DefTiDBPartitionPruneMode)
}

func TestSetTIDBFastDDL(t *testing.T) {
vars := NewSessionVars()
mock := NewMockGlobalAccessor4Tests()
Expand Down

0 comments on commit 45e7f33

Please sign in to comment.