Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <[email protected]>
  • Loading branch information
hawkingrei committed Jul 17, 2024
1 parent 839dc05 commit a6ae62f
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 19 deletions.
4 changes: 0 additions & 4 deletions pkg/executor/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,6 @@ func (e *AnalyzeExec) handleResultsErrorWithConcurrency(ctx context.Context, sta
panicCnt := 0
var err error
for panicCnt < statsConcurrency {
if err := e.Ctx().GetSessionVars().SQLKiller.HandleSignal(); err != nil {
close(saveResultsCh)
return err
}
results, ok := <-resultsCh
if !ok {
break
Expand Down
15 changes: 13 additions & 2 deletions pkg/planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ func GetMergeJoin(p *LogicalJoin, prop *property.PhysicalProperty, schema *expre
p.SCtx().GetSessionVars().StmtCtx.SetHintWarning(
"Some MERGE_JOIN and NO_MERGE_JOIN hints conflict, NO_MERGE_JOIN is ignored")
}

if !p.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("check here")
}
// If TiDB_SMJ hint is existed, it should consider enforce merge join,
// because we can't trust lhsChildProperty completely.
if (p.PreferJoinType&h.PreferMergeJoin) > 0 ||
Expand Down Expand Up @@ -424,7 +426,9 @@ func getHashJoins(p *LogicalJoin, prop *property.PhysicalProperty) (joins []base
joins = append(joins, getHashJoin(p, prop, 0, false))
}
}

if !p.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("fuck")
}
forced = (p.PreferJoinType&h.PreferHashJoin > 0) || forceLeftToBuild || forceRightToBuild
shouldSkipHashJoin := shouldSkipHashJoin(p)
if !forced && shouldSkipHashJoin {
Expand All @@ -434,6 +438,9 @@ func getHashJoins(p *LogicalJoin, prop *property.PhysicalProperty) (joins []base
"A conflict between the HASH_JOIN hint and the NO_HASH_JOIN hint, " +
"or the tidb_opt_enable_hash_join system variable, the HASH_JOIN hint will take precedence.")
}
if !p.SCtx().GetSessionVars().InRestrictedSQL {
logutil.BgLogger().Info("not bug", zap.Any("joins", joins))
}
return
}

Expand Down Expand Up @@ -2432,6 +2439,10 @@ func (p *LogicalJoin) ExhaustPhysicalPlans(prop *property.PhysicalProperty) ([]b
}

if !p.isNAAJ() {
if !p.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("wwz")
}
logutil.BgLogger().Info("fuckfuck")
// naaj refuse merge join and index join.
mergeJoins := GetMergeJoin(p, prop, p.Schema(), p.StatsInfo(), p.Children()[0].StatsInfo(), p.Children()[1].StatsInfo())
if (p.PreferJoinType&h.PreferMergeJoin) > 0 && len(mergeJoins) > 0 {
Expand Down
50 changes: 43 additions & 7 deletions pkg/planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ func rebuildChildTasks(p *logicalop.BaseLogicalPlan, childTasks *[]base.Task, pp
}
*childTasks = append(*childTasks, childTask)
}
if len(*childTasks) == 0 {
fmt.Println("fuckyou")
}
return nil
}

Expand All @@ -183,13 +186,14 @@ func enumeratePhysicalPlans4Task(
if _, ok := p.Self().(*LogicalSequence); ok {
iteration = iterateChildPlan4LogicalSequence
}
if !p.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("fuck")
}
for _, pp := range physicalPlans {
timeStampNow := p.GetLogicalTS4TaskMap()
savedPlanID := p.SCtx().GetSessionVars().PlanID.Load()

if !p.SCtx().GetSessionVars().InRestrictedSQL {
if len(childTasks) == 1 && childTasks[0] == nil {
logutil.BgLogger().Info("before fuck enumeratePhysicalPlans4Task", zap.Int("len child task", len(childTasks)))
}
}
childTasks, curCntPlan, childCnts, err = iteration(p, pp, childTasks, childCnts, prop, opt)
if err != nil {
return nil, 0, err
Expand All @@ -199,7 +203,11 @@ func enumeratePhysicalPlans4Task(
if len(childTasks) != p.ChildLen() {
continue
}

if !p.SCtx().GetSessionVars().InRestrictedSQL {
if len(childTasks) == 1 && childTasks[0] == nil {
logutil.BgLogger().Info("fuck enumeratePhysicalPlans4Task", zap.Int("len child task", len(childTasks)))
}
}
// If the target plan can be found in this physicalPlan(pp), rebuild childTasks to build the corresponding combination.
if planCounter.IsForce() && int64(*planCounter) <= curCntPlan {
p.SCtx().GetSessionVars().PlanID.Store(savedPlanID)
Expand All @@ -209,6 +217,11 @@ func enumeratePhysicalPlans4Task(
return nil, 0, err
}
}
if !p.SCtx().GetSessionVars().InRestrictedSQL {
if len(childTasks) == 1 && childTasks[0] == nil {
logutil.BgLogger().Info("fuck enumeratePhysicalPlans4Task after ", zap.Int("len child task", len(childTasks)))
}
}

// Combine the best child tasks with parent physical plan.
curTask := pp.Attach2Task(childTasks...)
Expand Down Expand Up @@ -261,22 +274,42 @@ func iteratePhysicalPlan4BaseLogical(
) ([]base.Task, int64, []int64, error) {
// Find best child tasks firstly.
childTasks = childTasks[:0]
if !p.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("check")
}
// The curCntPlan records the number of possible plans for pp
curCntPlan := int64(1)
for j, child := range p.Children() {
//if child == nil {
// logutil.BgLogger().Info("WTF")
//}
//if child.ExplainInfo() == "" {
// logutil.BgLogger().Info("WTF")
//}
childProp := selfPhysicalPlan.GetChildReqProps(j)
//if !p.SCtx().GetSessionVars().InRestrictedSQL {
//logutil.BgLogger().Info("fuck child", zap.String("child.ExplainInfo()", child.ExplainInfo()))
//}
if _, ok := child.(*LogicalCTETable); ok {
fmt.Println("here")
}
childTask, cnt, err := child.FindBestTask(childProp, &PlanCounterDisabled, opt)
childCnts[j] = cnt
if err != nil {
return nil, 0, childCnts, err
}
if childTask == nil {
fmt.Println("???????")
}
curCntPlan = curCntPlan * cnt
if childTask != nil && childTask.Invalid() {
return nil, 0, childCnts, nil
}
childTasks = append(childTasks, childTask)
}

if len(childTasks) == 1 && childTasks[0] == nil {
logutil.BgLogger().Info("iteratePhysicalPlan4BaseLogical meet bug")
}
// This check makes sure that there is no invalid child task.
if len(childTasks) != p.ChildLen() {
return nil, 0, childCnts, nil
Expand Down Expand Up @@ -528,6 +561,9 @@ func findBestTask(lp base.LogicalPlan, prop *property.PhysicalProperty, planCoun
var hintWorksWithProp bool
// Maybe the plan can satisfy the required property,
// so we try to get the task without the enforced sort first.
if !lp.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("here")
}
plansFitsProp, hintWorksWithProp, err = p.Self().ExhaustPhysicalPlans(newProp)
if err != nil {
return nil, 0, err
Expand Down Expand Up @@ -2917,7 +2953,7 @@ func findBestTask4LogicalCTE(p *LogicalCTE, prop *property.PhysicalProperty, cou

func findBestTask4LogicalCTETable(p *LogicalCTETable, prop *property.PhysicalProperty, _ *base.PlanCounterTp, _ *optimizetrace.PhysicalOptimizeOp) (t base.Task, cntPlan int64, err error) {
if !prop.IsSortItemEmpty() {
return nil, 1, nil
return base.InvalidTask, 0, nil
}

pcteTable := PhysicalCTETable{IDForStorage: p.IDForStorage}.Init(p.SCtx(), p.StatsInfo())
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/issuetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_test(
data = glob(["testdata/**"]),
flaky = True,
race = "on",
shard_count = 3,
deps = [
"//pkg/parser",
"//pkg/planner",
Expand Down
1 change: 1 addition & 0 deletions pkg/planner/core/issuetest/planner_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ WHERE
FROM
w
);`)
tk.MustQuery(`show warnings`).Check(testkit.Rows())
}
3 changes: 0 additions & 3 deletions pkg/planner/core/optimizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,6 @@ func physicalOptimize(logic base.LogicalPlan, planCounter *base.PlanCounterTp) (
}
}()
}
if !logic.SCtx().GetSessionVars().InRestrictedSQL {
fmt.Println("fuck")
}
logic.SCtx().GetSessionVars().StmtCtx.TaskMapBakTS = 0
t, _, err := logic.FindBestTask(prop, planCounter, opt)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/planner/core/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,14 +1089,14 @@ func (p *PhysicalUnionAll) Attach2Task(tasks ...base.Task) base.Task {

// Attach2Task implements PhysicalPlan interface.
func (sel *PhysicalSelection) Attach2Task(tasks ...base.Task) base.Task {
if tasks[0] == nil {
fmt.Println("fuck")
}
if mppTask, _ := tasks[0].(*MppTask); mppTask != nil { // always push to mpp task.
if expression.CanExprsPushDown(GetPushDownCtx(sel.SCtx()), sel.Conditions, kv.TiFlash) {
return attachPlan2Task(sel, mppTask.Copy())
}
}
if tasks[0] == nil {
fmt.Println("fuck")
}
t := tasks[0].ConvertToRootTask(sel.SCtx())
return attachPlan2Task(sel, t)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func TestMain(m *testing.M) {

opts := []goleak.Option{
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*defaultPolicy).processItems"),
goleak.IgnoreTopFunction("github.com/dgraph-io/ristretto.(*Cache).processItems"),
goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"),
goleak.IgnoreTopFunction("github.com/bazelbuild/rules_go/go/tools/bzltestutil.RegisterTimeoutHandler.func1"),
goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"),
Expand Down

0 comments on commit a6ae62f

Please sign in to comment.