Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: replace exp/slices with std #45978

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"context"
"fmt"
"math"
"slices"
"strconv"
"strings"
"sync/atomic"
Expand Down Expand Up @@ -73,7 +74,6 @@ import (
"github.com/tikv/client-go/v2/oracle"
kvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down
1 change: 0 additions & 1 deletion executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ go_test(
"@com_github_tikv_client_go_v2//tikvrpc",
"@com_github_tikv_client_go_v2//util",
"@org_golang_google_grpc//:grpc",
"@org_golang_x_exp//slices",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_goleak//:goleak",
"@org_uber_go_zap//zapcore",
Expand Down
27 changes: 14 additions & 13 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ package executor

import (
"bytes"
"cmp"
"context"
"fmt"
"math"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -80,7 +82,6 @@ import (
"github.com/tikv/client-go/v2/txnkv"
"github.com/tikv/client-go/v2/txnkv/txnsnapshot"
clientutil "github.com/tikv/client-go/v2/util"
"golang.org/x/exp/slices"
)

// executorBuilder builds an Executor from a Plan.
Expand Down Expand Up @@ -3671,8 +3672,8 @@ func (b *executorBuilder) buildTableReader(v *plannercore.PhysicalTableReader) e
}

// Sort the partition is necessary to make the final multiple partition key ranges ordered.
slices.SortFunc(partitions, func(i, j table.PhysicalTable) bool {
return i.GetPhysicalID() < j.GetPhysicalID()
slices.SortFunc(partitions, func(i, j table.PhysicalTable) int {
return cmp.Compare(i.GetPhysicalID(), j.GetPhysicalID())
})
ret.kvRangeBuilder = kvRangeBuilderFromRangeAndPartition{
sctx: b.ctx,
Expand Down Expand Up @@ -3795,8 +3796,8 @@ func (builder *dataReaderBuilder) prunePartitionForInnerExecutor(tbl table.Table
}

// To make the final key ranges involving multiple partitions ordered.
slices.SortFunc(usedPartition, func(i, j table.PhysicalTable) bool {
return i.GetPhysicalID() < j.GetPhysicalID()
slices.SortFunc(usedPartition, func(i, j table.PhysicalTable) int {
return cmp.Compare(i.GetPhysicalID(), j.GetPhysicalID())
})
return usedPartition, true, contentPos, nil
}
Expand Down Expand Up @@ -4464,8 +4465,8 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
}
}
// The key ranges should be ordered.
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool {
return bytes.Compare(i.StartKey, j.StartKey) < 0
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int {
return bytes.Compare(i.StartKey, j.StartKey)
})
return builder.buildTableReaderFromKvRanges(ctx, e, kvRanges)
}
Expand Down Expand Up @@ -4502,8 +4503,8 @@ func (builder *dataReaderBuilder) buildTableReaderForIndexJoin(ctx context.Conte
}

// The key ranges should be ordered.
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool {
return bytes.Compare(i.StartKey, j.StartKey) < 0
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int {
return bytes.Compare(i.StartKey, j.StartKey)
})
return builder.buildTableReaderFromKvRanges(ctx, e, kvRanges)
}
Expand Down Expand Up @@ -4624,8 +4625,8 @@ func (builder *dataReaderBuilder) buildTableReaderBase(ctx context.Context, e *T

func (builder *dataReaderBuilder) buildTableReaderFromHandles(ctx context.Context, e *TableReaderExecutor, handles []kv.Handle, canReorderHandles bool) (*TableReaderExecutor, error) {
if canReorderHandles {
slices.SortFunc(handles, func(i, j kv.Handle) bool {
return i.Compare(j) < 0
slices.SortFunc(handles, func(i, j kv.Handle) int {
return i.Compare(j)
})
}
var b distsql.RequestBuilder
Expand Down Expand Up @@ -4928,8 +4929,8 @@ func buildKvRangesForIndexJoin(ctx sessionctx.Context, tableID, indexID int64, l
memTracker.Consume(2 * int64(len(tmpDatumRanges)) * types.EstimatedMemUsage(tmpDatumRanges[0].LowVal, len(tmpDatumRanges)))
}
if cwc == nil {
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) bool {
return bytes.Compare(i.StartKey, j.StartKey) < 0
slices.SortFunc(kvRanges, func(i, j kv.KeyRange) int {
return bytes.Compare(i.StartKey, j.StartKey)
})
return kvRanges, nil
}
Expand Down
2 changes: 1 addition & 1 deletion executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package executor_test
import (
"fmt"
"math/rand"
"slices"
"testing"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/types"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestBasicCTE(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions executor/merge_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ func TestShuffleMergeJoinInDisk(t *testing.T) {
}

func TestMergeJoinInDisk(t *testing.T) {
t.Skip("unstable, skip it and fix it before 20210618")
restore := config.RestoreFunc()
defer restore()
defer config.RestoreFunc()()
config.UpdateGlobal(func(conf *config.Config) {
conf.TempStoragePath = t.TempDir()
})
Expand Down
2 changes: 1 addition & 1 deletion executor/metrics_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math"
"slices"
"strings"
"time"

Expand All @@ -36,7 +37,6 @@ import (
"github.com/prometheus/client_golang/api"
promv1 "github.com/prometheus/client_golang/api/prometheus/v1"
pmodel "github.com/prometheus/common/model"
"golang.org/x/exp/slices"
)

const promReadTimeout = time.Second * 10
Expand Down
2 changes: 1 addition & 1 deletion executor/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
gjson "encoding/json"
"fmt"
"math"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -81,7 +82,6 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
"github.com/pingcap/tidb/util/stringutil"
"github.com/tikv/client-go/v2/oracle"
"golang.org/x/exp/slices"
)

var etcdDialTimeout = 5 * time.Second
Expand Down
6 changes: 3 additions & 3 deletions executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"regexp"
"runtime"
"slices"
"strconv"
"strings"
"sync"
Expand All @@ -49,7 +50,6 @@ import (
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/plancodec"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

type signalsKey struct{}
Expand Down Expand Up @@ -941,8 +941,8 @@ func (e *slowQueryRetriever) getAllFiles(ctx context.Context, sctx sessionctx.Co
}
}
// Sort by start time
slices.SortFunc(logFiles, func(i, j logFile) bool {
return i.start.Before(j.start)
slices.SortFunc(logFiles, func(i, j logFile) int {
return i.start.Compare(j.start)
})
return logFiles, err
}
Expand Down
9 changes: 5 additions & 4 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package executor

import (
"bytes"
"cmp"
"context"
"slices"
"time"

"github.com/pingcap/failpoint"
Expand Down Expand Up @@ -44,7 +46,6 @@ import (
"github.com/pingcap/tidb/util/stringutil"
"github.com/pingcap/tidb/util/tracing"
"github.com/pingcap/tipb/go-tipb"
"golang.org/x/exp/slices"
)

// make sure `TableReaderExecutor` implements `Executor`.
Expand Down Expand Up @@ -484,9 +485,9 @@ func buildVirtualColumnIndex(schema *expression.Schema, columns []*model.ColumnI
virtualColumnIndex = append(virtualColumnIndex, i)
}
}
slices.SortFunc(virtualColumnIndex, func(i, j int) bool {
return plannercore.FindColumnInfoByID(columns, schema.Columns[i].ID).Offset <
plannercore.FindColumnInfoByID(columns, schema.Columns[j].ID).Offset
slices.SortFunc(virtualColumnIndex, func(i, j int) int {
return cmp.Compare(plannercore.FindColumnInfoByID(columns, schema.Columns[i].ID).Offset,
plannercore.FindColumnInfoByID(columns, schema.Columns[j].ID).Offset)
})
return virtualColumnIndex
}
Expand Down
1 change: 0 additions & 1 deletion executor/test/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,6 @@ func TestDefaultValForAnalyze(t *testing.T) {
}

func TestAnalyzeFullSamplingOnIndexWithVirtualColumnOrPrefixColumn(t *testing.T) {
t.Skip("unstable, skip it and fix it before 20210624")
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

Expand Down
6 changes: 3 additions & 3 deletions executor/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"time"

Expand All @@ -44,7 +45,6 @@ import (
"github.com/pingcap/tidb/util/sqlexec"
"github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"sourcegraph.com/sourcegraph/appdash"
traceImpl "sourcegraph.com/sourcegraph/appdash/opentracing"
)
Expand Down Expand Up @@ -345,15 +345,15 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, chk *chunk.Chunk) {
chk.AppendString(2, duration.String())

// Sort events by their start time
slices.SortFunc(t.Sub, func(i, j *appdash.Trace) bool {
slices.SortFunc(t.Sub, func(i, j *appdash.Trace) int {
var istart, jstart time.Time
if ievent, err := i.TimespanEvent(); err == nil {
istart = ievent.Start()
}
if jevent, err := j.TimespanEvent(); err == nil {
jstart = jevent.Start()
}
return istart.Before(jstart)
return istart.Compare(jstart)
})

for i, sp := range t.Sub {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package core

import (
"fmt"
"slices"
"sort"
"strings"

Expand All @@ -31,7 +32,6 @@ import (
"github.com/pingcap/tidb/util/mathutil"
"github.com/pingcap/tidb/util/set"
"github.com/pingcap/tidb/util/size"
"golang.org/x/exp/slices"
)

// AggregateFuncExtractor visits Expr tree.
Expand Down
1 change: 0 additions & 1 deletion sessionctx/variable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ go_library(
"@com_github_tikv_client_go_v2//util",
"@com_github_twmb_murmur3//:murmur3",
"@org_golang_x_exp//maps",
"@org_golang_x_exp//slices",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math"
"math/rand"
"net"
"slices"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -65,7 +66,6 @@ import (
"github.com/twmb/murmur3"
atomic2 "go.uber.org/atomic"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"io"
"slices"
"strconv"
"strings"
"sync/atomic"
Expand All @@ -32,7 +33,6 @@ import (
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/timeutil"
"github.com/tikv/client-go/v2/oracle"
"golang.org/x/exp/slices"
)

// secondsPerYear represents seconds in a normal year. Leap year is not considered here.
Expand Down
7 changes: 4 additions & 3 deletions statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package statistics

import (
"cmp"
"fmt"
"math"
"slices"
"strings"
"sync"

Expand All @@ -39,7 +41,6 @@ import (
"github.com/pingcap/tidb/util/tracing"
"go.uber.org/atomic"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

const (
Expand Down Expand Up @@ -323,15 +324,15 @@ func (t *Table) String() string {
for _, col := range t.Columns {
cols = append(cols, col)
}
slices.SortFunc(cols, func(i, j *Column) bool { return i.ID < j.ID })
slices.SortFunc(cols, func(i, j *Column) int { return cmp.Compare(i.ID, j.ID) })
for _, col := range cols {
strs = append(strs, col.String())
}
idxs := make([]*Index, 0, len(t.Indices))
for _, idx := range t.Indices {
idxs = append(idxs, idx)
}
slices.SortFunc(idxs, func(i, j *Index) bool { return i.ID < j.ID })
slices.SortFunc(idxs, func(i, j *Index) int { return cmp.Compare(i.ID, j.ID) })
for _, idx := range idxs {
strs = append(strs, idx.String())
}
Expand Down
1 change: 0 additions & 1 deletion telemetry/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ go_library(
"@com_github_shirou_gopsutil_v3//host",
"@com_github_tikv_client_go_v2//metrics",
"@io_etcd_go_etcd_client_v3//:client",
"@org_golang_x_exp//slices",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
Expand Down
2 changes: 1 addition & 1 deletion telemetry/data_cluster_hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package telemetry
import (
"context"
"regexp"
"slices"
"strings"

"github.com/iancoleman/strcase"
"github.com/pingcap/errors"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/util/sqlexec"
"golang.org/x/exp/slices"
)

var (
Expand Down