From ba510b97eb12d853f0ac8df242ec58b797106d24 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 7 Dec 2021 23:15:01 +0100 Subject: [PATCH] Disable dynamic partition prune mode for all non-autocommit --- planner/core/integration_partition_test.go | 19 +++++++++++++++++++ sessionctx/variable/session.go | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/planner/core/integration_partition_test.go b/planner/core/integration_partition_test.go index 33e4fb214ba81..b4faf61f64bcb 100644 --- a/planner/core/integration_partition_test.go +++ b/planner/core/integration_partition_test.go @@ -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`) +} diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 057ba9a6dcdff..680e6f2c1367b 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -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