Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
Signed-off-by: you06 <[email protected]>
  • Loading branch information
you06 committed Aug 14, 2023
1 parent 57ebcc1 commit 3469f08
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 719 deletions.
9 changes: 0 additions & 9 deletions executor/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,15 @@ go_test(
"main_test.go",
],
flaky = True,
<<<<<<< HEAD:executor/issuetest/BUILD.bazel
shard_count = 50,
=======
shard_count = 13,
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814)):session/test/vars/BUILD.bazel
deps = [
"//config",
"//kv",
"//meta/autoid",
"//parser/auth",
"//parser/charset",
"//parser/mysql",
<<<<<<< HEAD:executor/issuetest/BUILD.bazel
"//session",
=======
"//parser/terror",
"//sessionctx/stmtctx",
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814)):session/test/vars/BUILD.bazel
"//sessionctx/variable",
"//statistics",
"//testkit",
Expand Down
6 changes: 1 addition & 5 deletions planner/core/plan_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,7 @@ func generateNewPlan(ctx context.Context, sctx sessionctx.Context, isGeneralPlan
}
sessVars.IsolationReadEngines[kv.TiFlash] = struct{}{}
}
<<<<<<< HEAD
cached := NewPlanCacheValue(p, names, stmtCtx.TblInfo2UnionScan, paramTypes)
=======
cached := NewPlanCacheValue(p, names, stmtCtx.TblInfo2UnionScan, matchOpts, &stmtCtx.StmtHints)
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814))
cached := NewPlanCacheValue(p, names, stmtCtx.TblInfo2UnionScan, paramTypes, &stmtCtx.StmtHints)
stmt.NormalizedPlan, stmt.PlanDigest = NormalizePlan(p)
stmtCtx.SetPlan(p)
stmtCtx.SetPlanDigest(stmt.NormalizedPlan, stmt.PlanDigest)
Expand Down
19 changes: 3 additions & 16 deletions planner/core/plan_cache_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,17 +349,12 @@ type PlanCacheValue struct {
TblInfo2UnionScan map[*model.TableInfo]bool
ParamTypes FieldSlice
memoryUsage int64
// stmtHints stores the hints which set session variables, because the hints won't be processed using cached plan.
stmtHints *stmtctx.StmtHints
}

<<<<<<< HEAD
func (v *PlanCacheValue) varTypesUnchanged(txtVarTps []*types.FieldType) bool {
return v.ParamTypes.CheckTypesCompatibility4PC(txtVarTps)
=======
// matchOpts stores some fields help to choose a suitable plan
matchOpts *utilpc.PlanCacheMatchOpts
// stmtHints stores the hints which set session variables, because the hints won't be processed using cached plan.
stmtHints *stmtctx.StmtHints
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814))
}

// unKnownMemoryUsage represent the memory usage of uncounted structure, maybe need implement later
Expand Down Expand Up @@ -403,11 +398,7 @@ func (v *PlanCacheValue) MemoryUsage() (sum int64) {

// NewPlanCacheValue creates a SQLCacheValue.
func NewPlanCacheValue(plan Plan, names []*types.FieldName, srcMap map[*model.TableInfo]bool,
<<<<<<< HEAD
paramTypes []*types.FieldType) *PlanCacheValue {
=======
matchOpts *utilpc.PlanCacheMatchOpts, stmtHints *stmtctx.StmtHints) *PlanCacheValue {
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814))
paramTypes []*types.FieldType, stmtHints *stmtctx.StmtHints) *PlanCacheValue {
dstMap := make(map[*model.TableInfo]bool)
for k, v := range srcMap {
dstMap[k] = v
Expand All @@ -420,12 +411,8 @@ func NewPlanCacheValue(plan Plan, names []*types.FieldName, srcMap map[*model.Ta
Plan: plan,
OutPutNames: names,
TblInfo2UnionScan: dstMap,
<<<<<<< HEAD
ParamTypes: userParamTypes,
=======
matchOpts: matchOpts,
stmtHints: stmtHints.Clone(),
>>>>>>> c34f6fc83d6 (planner: store the hints of session variable (#45814))
}
}

Expand Down
1 change: 1 addition & 0 deletions session/session_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_test(
"//privilege/privileges",
"//session",
"//sessionctx",
"//sessionctx/stmtctx",
"//sessionctx/variable",
"//store/copr",
"//store/mockstore",
Expand Down
54 changes: 54 additions & 0 deletions session/session_test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/pingcap/tidb/privilege/privileges"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/copr"
"github.com/pingcap/tidb/store/mockstore"
Expand Down Expand Up @@ -4139,3 +4140,56 @@ func TestSQLModeOp(t *testing.T) {
a = mysql.SetSQLMode(s, mysql.ModeAllowInvalidDates)
require.Equal(t, mysql.ModeNoBackslashEscapes|mysql.ModeOnlyFullGroupBy|mysql.ModeAllowInvalidDates, a)
}

func TestPrepareExecuteWithSQLHints(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
se := tk.Session()
se.SetConnectionID(1)
tk.MustExec("use test")
tk.MustExec("create table t(a int primary key)")

type hintCheck struct {
hint string
check func(*stmtctx.StmtHints)
}

hintChecks := []hintCheck{
{
hint: "MEMORY_QUOTA(1024 MB)",
check: func(stmtHint *stmtctx.StmtHints) {
require.True(t, stmtHint.HasMemQuotaHint)
require.Equal(t, int64(1024*1024*1024), stmtHint.MemQuotaQuery)
},
},
{
hint: "MAX_EXECUTION_TIME(1000)",
check: func(stmtHint *stmtctx.StmtHints) {
require.True(t, stmtHint.HasMaxExecutionTime)
require.Equal(t, uint64(1000), stmtHint.MaxExecutionTime)
},
},
{
hint: "USE_TOJA(TRUE)",
check: func(stmtHint *stmtctx.StmtHints) {
require.True(t, stmtHint.HasAllowInSubqToJoinAndAggHint)
require.True(t, stmtHint.AllowInSubqToJoinAndAgg)
},
},
}

for i, check := range hintChecks {
// common path
tk.MustExec(fmt.Sprintf("prepare stmt%d from 'select /*+ %s */ * from t'", i, check.hint))
for j := 0; j < 10; j++ {
tk.MustQuery(fmt.Sprintf("execute stmt%d", i))
check.check(&tk.Session().GetSessionVars().StmtCtx.StmtHints)
}
// fast path
tk.MustExec(fmt.Sprintf("prepare fast%d from 'select /*+ %s */ * from t where a = 1'", i, check.hint))
for j := 0; j < 10; j++ {
tk.MustQuery(fmt.Sprintf("execute fast%d", i))
check.check(&tk.Session().GetSessionVars().StmtCtx.StmtHints)
}
}
}
Loading

0 comments on commit 3469f08

Please sign in to comment.