diff --git a/pkg/planner/core/flat_plan.go b/pkg/planner/core/flat_plan.go index 35e46827c2e05..5dc4e4c3170e4 100644 --- a/pkg/planner/core/flat_plan.go +++ b/pkg/planner/core/flat_plan.go @@ -16,7 +16,7 @@ package core import ( "fmt" - "sort" + "slices" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/util/logutil" @@ -456,10 +456,8 @@ func (f *FlatPhysicalPlan) flattenForeignKeyChecksAndCascadesMap(childCtx *opera for tid := range fkChecksMap { tids = append(tids, tid) } - // Sort by table id for explain result stable. - sort.Slice(tids, func(i, j int) bool { - return tids[i] < tids[j] - }) + // sort by table id for explain result stable. + slices.Sort(tids) for i, tid := range tids { target, childIdxs = f.flattenForeignKeyChecksAndCascades(childCtx, target, childIdxs, fkChecksMap[tid], nil, len(fkCascadesMap) == 0 && i == len(tids)-1) } @@ -467,9 +465,7 @@ func (f *FlatPhysicalPlan) flattenForeignKeyChecksAndCascadesMap(childCtx *opera for tid := range fkCascadesMap { tids = append(tids, tid) } - sort.Slice(tids, func(i, j int) bool { - return tids[i] < tids[j] - }) + slices.Sort(tids) for i, tid := range tids { target, childIdxs = f.flattenForeignKeyChecksAndCascades(childCtx, target, childIdxs, nil, fkCascadesMap[tid], i == len(tids)-1) } diff --git a/pkg/planner/core/rule_join_reorder_greedy.go b/pkg/planner/core/rule_join_reorder_greedy.go index 6e20256cdfb4a..b6964ca618bf4 100644 --- a/pkg/planner/core/rule_join_reorder_greedy.go +++ b/pkg/planner/core/rule_join_reorder_greedy.go @@ -15,8 +15,9 @@ package core import ( + "cmp" "math" - "sort" + "slices" "github.com/pingcap/tidb/pkg/expression" ) @@ -57,8 +58,8 @@ func (s *joinReorderGreedySolver) solve(joinNodePlans []LogicalPlan, tracer *joi } } // Sort plans by cost - sort.SliceStable(s.curJoinGroup, func(i, j int) bool { - return s.curJoinGroup[i].cumCost < s.curJoinGroup[j].cumCost + slices.SortStableFunc(s.curJoinGroup, func(i, j *jrNode) int { + return cmp.Compare(i.cumCost, j.cumCost) }) // joinNodeNum indicates the number of join nodes except leading join nodes in the current join group