Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 committed May 30, 2023
1 parent de911c9 commit 8bb2633
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
29 changes: 29 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7933,6 +7933,35 @@ func TestExplainAnalyzeDMLCommit(t *testing.T) {
tk.MustQuery("select * from t").Check(testkit.Rows())
}

func TestFixControl44262(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`set tidb_partition_prune_mode='dynamic'`)
tk.MustExec(`create table t1 (a int, b int)`)
tk.MustExec(`create table t2_part (a int, b int, key(a)) partition by hash(a) partitions 4`)

testJoin := func(q, join string) {
found := false
for _, x := range tk.MustQuery(`explain ` + q).Rows() {
if strings.Contains(x[0].(string), join) {
found = true
}
}
if !found {
t.Fatal(q, join)
}
}

testJoin(`select /*+ TIDB_INLJ(t2_part@sel_2) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20)`, "HashJoin")
tk.MustQuery(`show warnings`).Sort().Check(testkit.Rows(
`Warning 1105 disable dynamic pruning due to t2_part has no global stats`,
`Warning 1815 Optimizer Hint INL_JOIN or TIDB_INLJ is inapplicable`))
tk.MustExec(`set @@tidb_opt_fix_control = "44262:ON"`)
testJoin(`select /*+ TIDB_INLJ(t2_part@sel_2) */ * from t1 where t1.b<10 and not exists (select 1 from t2_part where t1.a=t2_part.a and t2_part.b<20)`, "IndexJoin")
tk.MustQuery(`show warnings`).Sort().Check(testkit.Rows()) // no warning
}

func TestIndexJoinRangeFallback(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
7 changes: 6 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4464,8 +4464,13 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
tblStats := h.GetTableStats(tableInfo)
isDynamicEnabled := b.ctx.GetSessionVars().IsDynamicPartitionPruneEnabled()
globalStatsReady := tblStats.IsInitialized()
allowDynamicWithoutStats := false
fixValue, ok := b.ctx.GetSessionVars().GetOptimizerFixControlValue(variable.TiDBOptFixControl44262)
if ok && variable.TiDBOptOn(fixValue) {
allowDynamicWithoutStats = true
}
// If dynamic partition prune isn't enabled or global stats is not ready, we won't enable dynamic prune mode in query
usePartitionProcessor := !isDynamicEnabled || !globalStatsReady
usePartitionProcessor := !isDynamicEnabled || (!globalStatsReady && !allowDynamicWithoutStats)

failpoint.Inject("forceDynamicPrune", func(val failpoint.Value) {
if val.(bool) {
Expand Down
16 changes: 16 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,22 @@ type SessionVars struct {
OptimizerFixControl map[uint64]string
}

var (
// variables below are for the optimizer fix control.

// TiDBOptFixControl44262 controls whether to allow to use dynamic-mode to access partitioning tables without global-stats (#44262).
TiDBOptFixControl44262 uint64 = 44262
)

// GetOptimizerFixControlValue returns the specified value of the optimizer fix control.
func (s *SessionVars) GetOptimizerFixControlValue(key uint64) (value string, exist bool) {
if s.OptimizerFixControl == nil {
return "", false
}
value, exist = s.OptimizerFixControl[key]
return
}

// GetNewChunkWithCapacity Attempt to request memory from the chunk pool
// thread safety
func (s *SessionVars) GetNewChunkWithCapacity(fields []*types.FieldType, capacity int, maxCachesize int, pool chunk.Allocator) *chunk.Chunk {
Expand Down

0 comments on commit 8bb2633

Please sign in to comment.