diff --git a/executor/write_test.go b/executor/write_test.go index a5ef9da73ce00..ab3ec6813f5c7 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -1192,6 +1192,8 @@ func TestGeneratedColumnForInsert(t *testing.T) { } func TestPartitionedTableReplace(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) tk.MustExec("use test") @@ -1450,6 +1452,8 @@ func TestHashPartitionedTableReplace(t *testing.T) { } func TestPartitionedTableUpdate(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) tk.MustExec("use test") @@ -1720,6 +1724,8 @@ func TestDelete(t *testing.T) { } func TestPartitionedTableDelete(t *testing.T) { + failpoint.Enable("github.com/pingcap/tidb/planner/core/forceDynamicPrune", `return(true)`) + defer failpoint.Disable("github.com/pingcap/tidb/planner/core/forceDynamicPrune") createTable := `CREATE TABLE test.t (id int not null default 1, name varchar(255), index(id)) PARTITION BY RANGE ( id ) ( PARTITION p0 VALUES LESS THAN (6), @@ -3935,6 +3941,8 @@ func testEqualDatumsAsBinary(t *testing.T, a []interface{}, b []interface{}, sam } func TestUpdate(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) tk.MustExec("use test") diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 7b2beb83ebd21..ee26d299a6043 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -5034,6 +5034,8 @@ func TestIncrementalAnalyzeStatsVer2(t *testing.T) { } func TestConflictReadFromStorage(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) tk.MustExec("use test") diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 70248a7a20e36..e59985c8e1e12 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -4408,6 +4408,10 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as if usePartitionProcessor { b.optFlag = b.optFlag | flagPartitionProcessor b.ctx.GetSessionVars().StmtCtx.UseDynamicPruneMode = false + if isDynamicEnabled { + b.ctx.GetSessionVars().StmtCtx.AppendWarning( + fmt.Errorf("disable dynamic pruning due to %s has no global stats", tableInfo.Name.String())) + } } pt := tbl.(table.PartitionedTable)