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

sessionctx: Change default tidb_partition_prune_mode from static to dynamic #37712

Merged
merged 7 commits into from
Sep 14, 2022
Merged
16 changes: 16 additions & 0 deletions executor/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@ func TestAnalyzeSamplingWorkPanic(t *testing.T) {
}

func TestSmallTableAnalyzeV2(t *testing.T) {
failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`)
defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune")
store := testkit.CreateMockStore(t)

tk := testkit.NewTestKit(t, store)
Expand All @@ -935,6 +937,20 @@ create table small_table_inject_pd_with_partition(
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p1",
"Note 1105 Analyze use auto adjusted sample rate 1.000000 for table test.small_table_inject_pd_with_partition's partition p2",
))
rows := [][]interface{}{
{"global", "a"},
{"p0", "a"},
{"p1", "a"},
{"p2", "a"},
}
tk.MustQuery("show column_stats_usage where db_name = 'test' and table_name = 'small_table_inject_pd_with_partition' and last_analyzed_at is not null").Sort().CheckAt([]int{2, 3}, rows)
rows = [][]interface{}{
{"global", "0", "3"},
{"p0", "0", "1"},
{"p1", "0", "1"},
{"p2", "0", "1"},
}
tk.MustQuery("show stats_meta where db_name = 'test' and table_name = 'small_table_inject_pd_with_partition'").Sort().CheckAt([]int{2, 4, 5}, rows)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/calcSampleRateByStorageCount"))
}

Expand Down
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
1 change: 0 additions & 1 deletion infoschema/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,6 @@ func TestVariablesInfo(t *testing.T) {
"tidb_enable_collect_execution_info ON OFF", // for test stability
"tidb_enable_mutation_checker OFF ON", // for new installs
"tidb_mem_oom_action CANCEL LOG", // always changed for tests
"tidb_partition_prune_mode static dynamic", // for new installs
"tidb_row_format_version 1 2", // for new installs
morgo marked this conversation as resolved.
Show resolved Hide resolved
"tidb_txn_assertion_level OFF FAST", // for new installs
"timestamp 0 123456789", // always dynamic
Expand Down
4 changes: 3 additions & 1 deletion planner/core/rule_result_reorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ func TestOrderedResultModeOnPartitionTable(t *testing.T) {
partition p1 values less than (200),
partition p2 values less than (300),
partition p3 values less than (400))`)
tk.MustQuery("select @@tidb_partition_prune_mode").Check(testkit.Rows("static"))
tk.MustExec(`analyze table thash`)
tk.MustExec(`analyze table trange`)
tk.MustQuery("select @@tidb_partition_prune_mode").Check(testkit.Rows("dynamic"))
runTestData(t, tk, "TestOrderedResultModeOnPartitionTable")
}

Expand Down
38 changes: 12 additions & 26 deletions planner/core/testdata/ordered_result_mode_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -439,44 +439,30 @@
"Cases": [
{
"Plan": [
"Sort_10 4.00 root test.thash.a",
"└─PartitionUnion_12 4.00 root ",
" ├─Batch_Point_Get_13 2.00 root table:thash handle:[1 200], keep order:false, desc:false",
" └─Batch_Point_Get_14 2.00 root table:thash handle:[1 200], keep order:false, desc:false"
"Sort_6 2.00 root test.thash.a",
"└─TableReader_9 2.00 root partition:p0,p1 data:TableRangeScan_8",
" └─TableRangeScan_8 2.00 cop[tikv] table:thash range:[1,1], [200,200], keep order:false, stats:pseudo"
]
},
{
"Plan": [
"Sort_12 400.00 root test.thash.a",
"└─PartitionUnion_14 400.00 root ",
" ├─TableReader_16 100.00 root data:TableRangeScan_15",
" │ └─TableRangeScan_15 100.00 cop[tikv] table:thash, partition:p0 range:[50,150], keep order:false, stats:pseudo",
" ├─TableReader_18 100.00 root data:TableRangeScan_17",
" │ └─TableRangeScan_17 100.00 cop[tikv] table:thash, partition:p1 range:[50,150], keep order:false, stats:pseudo",
" ├─TableReader_20 100.00 root data:TableRangeScan_19",
" │ └─TableRangeScan_19 100.00 cop[tikv] table:thash, partition:p2 range:[50,150], keep order:false, stats:pseudo",
" └─TableReader_22 100.00 root data:TableRangeScan_21",
" └─TableRangeScan_21 100.00 cop[tikv] table:thash, partition:p3 range:[50,150], keep order:false, stats:pseudo"
"Sort_6 100.00 root test.thash.a",
"└─TableReader_9 100.00 root partition:all data:TableRangeScan_8",
" └─TableRangeScan_8 100.00 cop[tikv] table:thash range:[50,150], keep order:false, stats:pseudo"
]
},
{
"Plan": [
"Sort_10 4.00 root test.trange.a",
"└─PartitionUnion_12 4.00 root ",
" ├─TableReader_14 2.00 root data:TableRangeScan_13",
" │ └─TableRangeScan_13 2.00 cop[tikv] table:trange, partition:p0 range:[1,1], [200,200], keep order:false, stats:pseudo",
" └─TableReader_16 2.00 root data:TableRangeScan_15",
" └─TableRangeScan_15 2.00 cop[tikv] table:trange, partition:p2 range:[1,1], [200,200], keep order:false, stats:pseudo"
"Sort_6 2.00 root test.trange.a",
"└─TableReader_9 2.00 root partition:p0,p2 data:TableRangeScan_8",
" └─TableRangeScan_8 2.00 cop[tikv] table:trange range:[1,1], [200,200], keep order:false, stats:pseudo"
]
},
{
"Plan": [
"Sort_10 200.00 root test.trange.a",
"└─PartitionUnion_12 200.00 root ",
" ├─TableReader_14 100.00 root data:TableRangeScan_13",
" │ └─TableRangeScan_13 100.00 cop[tikv] table:trange, partition:p0 range:[50,150], keep order:false, stats:pseudo",
" └─TableReader_16 100.00 root data:TableRangeScan_15",
" └─TableRangeScan_15 100.00 cop[tikv] table:trange, partition:p1 range:[50,150], keep order:false, stats:pseudo"
"Sort_6 100.00 root test.trange.a",
"└─TableReader_9 100.00 root partition:p0,p1 data:TableRangeScan_8",
" └─TableRangeScan_8 100.00 cop[tikv] table:trange range:[50,150], keep order:false, stats:pseudo"
]
}
]
Expand Down
4 changes: 0 additions & 4 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -2059,10 +2059,6 @@ func doDMLWorks(s Session) {
if config.GetGlobalConfig().Store == "tikv" {
vVal = variable.On
}
case variable.TiDBPartitionPruneMode:
if inTestSuite() || config.CheckTableBeforeDrop {
vVal = string(variable.Dynamic)
}
case variable.TiDBMemOOMAction:
if inTestSuite() {
vVal = variable.OOMActionLog
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
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ const (
DefTiDBEnableTelemetry = true
DefTiDBEnableParallelApply = false
DefTiDBEnableAmendPessimisticTxn = false
DefTiDBPartitionPruneMode = "static"
DefTiDBPartitionPruneMode = "dynamic"
DefTiDBEnableRateLimitAction = true
DefTiDBEnableAsyncCommit = false
DefTiDBEnable1PC = false
Expand Down