Skip to content

Commit

Permalink
planner: Disable dynamic partition prune mode for all non-autocommit (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mjonss authored Dec 8, 2021
1 parent 9773f83 commit 6229c89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions planner/core/integration_partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1160,3 +1160,22 @@ func genListPartition(begin, end int) string {
buf.WriteString(fmt.Sprintf("%v)", end-1))
return buf.String()
}

func TestIssue27532(t *testing.T) {
t.Parallel()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("create database issue_27532")
defer tk.MustExec(`drop database issue_27532`)
tk.MustExec("use issue_27532")
tk.MustExec(`set tidb_enable_list_partition = 1`)
tk.MustExec(`create table t2 (c1 int primary key, c2 int, c3 int, c4 int, key k2 (c2), key k3 (c3)) partition by hash(c1) partitions 10`)
tk.MustExec(`insert into t2 values (1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4)`)
tk.MustExec(`set @@tidb_partition_prune_mode="dynamic"`)
tk.MustExec(`set autocommit = 0`)
tk.MustQuery(`select * from t2`).Sort().Check(testkit.Rows("1 1 1 1", "2 2 2 2", "3 3 3 3", "4 4 4 4"))
tk.MustQuery(`select * from t2`).Sort().Check(testkit.Rows("1 1 1 1", "2 2 2 2", "3 3 3 3", "4 4 4 4"))
tk.MustExec(`drop table t2`)
}
2 changes: 1 addition & 1 deletion sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ func (s *SessionVars) CheckAndGetTxnScope() string {

// UseDynamicPartitionPrune indicates whether use new dynamic partition prune.
func (s *SessionVars) UseDynamicPartitionPrune() bool {
if s.InTxn() {
if s.InTxn() || !s.GetStatusFlag(mysql.ServerStatusAutocommit) {
// UnionScan cannot get partition table IDs in dynamic-mode, this is a quick-fix for issues/26719,
// please see it for more details.
return false
Expand Down

0 comments on commit 6229c89

Please sign in to comment.