From f9d3d923c6554c7a9ca99826be189ff9c1f2b6d3 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 14 Nov 2024 14:34:21 +0800 Subject: [PATCH] update dependencies Signed-off-by: Weizhen Wang --- DEPS.bzl | 123 +++++++++++------- br/pkg/lightning/backend/backend.go | 9 +- br/pkg/lightning/backend/kv/sql2kv.go | 5 +- br/pkg/lightning/backend/local/engine.go | 12 +- br/pkg/lightning/backend/local/localhelper.go | 12 +- br/pkg/lightning/checkpoints/checkpoints.go | 12 +- br/pkg/restore/client.go | 37 ++---- br/pkg/restore/db.go | 5 +- br/pkg/task/stream.go | 4 +- ddl/cluster.go | 5 +- ddl/ddl.go | 9 +- ddl/index.go | 3 +- executor/aggregate.go | 3 +- executor/batch_point_get.go | 18 +-- executor/builder.go | 25 ++-- executor/distsql.go | 8 +- executor/index_lookup_join.go | 6 +- executor/index_lookup_merge_join.go | 22 ++-- executor/index_merge_reader.go | 4 +- executor/infoschema_reader.go | 5 +- executor/inspection_result.go | 23 ++-- executor/memtable_reader.go | 7 +- executor/sample.go | 6 +- executor/show_placement.go | 9 +- executor/show_stats.go | 5 +- executor/slow_query.go | 4 +- executor/sort.go | 22 +++- executor/table_reader.go | 12 +- executor/trace.go | 4 +- go.mod | 29 +++-- go.sum | 27 ++++ infoschema/builder.go | 9 +- infoschema/infoschema.go | 9 +- infoschema/perfschema/tables.go | 3 +- parser/model/model.go | 5 +- planner/core/fragment.go | 5 +- planner/core/hashcode.go | 2 +- planner/core/optimizer.go | 21 +-- planner/core/plan_cache_utils.go | 5 +- planner/core/rule_partition_processor.go | 5 +- privilege/privileges/cache.go | 17 +-- statistics/cmsketch.go | 26 ++-- statistics/feedback.go | 6 +- statistics/handle/update.go | 7 +- statistics/histogram.go | 10 +- statistics/selectivity.go | 7 +- statistics/table.go | 5 +- store/copr/batch_coprocessor.go | 15 ++- store/gcworker/gc_worker.go | 4 +- .../mockstore/unistore/cophandler/analyze.go | 18 +-- store/mockstore/unistore/tikv/mock_region.go | 4 +- store/mockstore/unistore/tikv/mvcc.go | 16 +-- util/memoryusagealarm/memoryusagealarm.go | 9 +- util/ranger/ranger.go | 4 +- 54 files changed, 398 insertions(+), 289 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 3a62ecfb60d86..d5fc2365fa5c5 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -408,22 +408,30 @@ def go_deps(): name = "com_github_azure_azure_sdk_for_go_sdk_azcore", build_file_proto_mode = "disable_global", importpath = "github.com/Azure/azure-sdk-for-go/sdk/azcore", - sum = "h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA=", - version = "v0.20.0", + sum = "h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M=", + version = "v1.16.0", ) go_repository( name = "com_github_azure_azure_sdk_for_go_sdk_azidentity", build_file_proto_mode = "disable_global", importpath = "github.com/Azure/azure-sdk-for-go/sdk/azidentity", - sum = "h1:VBvHGLJbaY0+c66NZHdS9cgjHVYSH6DDa0XJMyrblsI=", - version = "v0.12.0", + sum = "h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g=", + version = "v1.8.0", + ) + go_repository( + name = "com_github_azure_azure_sdk_for_go_sdk_azidentity_cache", + build_file_proto_mode = "disable", + importpath = "github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache", + sum = "h1:+m0M/LFxN43KvULkDNfdXOgrjtg6UYJPFBJyuEcRCAw=", + version = "v0.3.0", ) + go_repository( name = "com_github_azure_azure_sdk_for_go_sdk_internal", build_file_proto_mode = "disable_global", importpath = "github.com/Azure/azure-sdk-for-go/sdk/internal", - sum = "h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc=", - version = "v0.8.1", + sum = "h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=", + version = "v1.10.0", ) go_repository( name = "com_github_azure_azure_sdk_for_go_sdk_resourcemanager_compute_armcompute_v5", @@ -451,12 +459,20 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v4/com_github_azure_azure_sdk_for_go_sdk_resourcemanager_network_armnetwork_v4-v4.3.0.zip", ], ) + go_repository( + name = "com_github_azure_azure_sdk_for_go_sdk_resourcemanager_storage_armstorage", + build_file_proto_mode = "disable", + importpath = "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage", + sum = "h1:PiSrjRPpkQNjrM8H0WwKMnZUdu1RGMtd/LdGKUrOo+c=", + version = "v1.6.0", + ) + go_repository( name = "com_github_azure_azure_sdk_for_go_sdk_storage_azblob", build_file_proto_mode = "disable_global", importpath = "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob", - sum = "h1:62Ew5xXg5UCGIXDOM7+y4IL5/6mQJq1nenhBCJAeGX8=", - version = "v0.2.0", + sum = "h1:mlmW46Q0B79I+Aj4azKC6xDMFN9a9SyZWESlGWYXbFs=", + version = "v1.5.0", ) go_repository( name = "com_github_azure_go_autorest", @@ -479,18 +495,20 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/Azure/go-ntlmssp/com_github_azure_go_ntlmssp-v0.0.0-20221128193559-754e69321358.zip", ], ) + go_repository( + name = "com_github_azuread_microsoft_authentication_extensions_for_go_cache", + build_file_proto_mode = "disable", + importpath = "github.com/AzureAD/microsoft-authentication-extensions-for-go/cache", + sum = "h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM=", + version = "v0.1.1", + ) + go_repository( name = "com_github_azuread_microsoft_authentication_library_for_go", build_file_proto_mode = "disable_global", importpath = "github.com/AzureAD/microsoft-authentication-library-for-go", - sha256 = "895ac3948492180ed21eabe651bebe45c9d99b92c2738206759d6faf4f430d26", - strip_prefix = "github.com/AzureAD/microsoft-authentication-library-for-go@v1.2.2", - urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/AzureAD/microsoft-authentication-library-for-go/com_github_azuread_microsoft_authentication_library_for_go-v1.2.2.zip", - "http://ats.apps.svc/gomod/github.com/AzureAD/microsoft-authentication-library-for-go/com_github_azuread_microsoft_authentication_library_for_go-v1.2.2.zip", - "https://cache.hawkingrei.com/gomod/github.com/AzureAD/microsoft-authentication-library-for-go/com_github_azuread_microsoft_authentication_library_for_go-v1.2.2.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/AzureAD/microsoft-authentication-library-for-go/com_github_azuread_microsoft_authentication_library_for_go-v1.2.2.zip", - ], + sum = "h1:gUDtaZk8heteyfdmv+pcfHvhR9llnh7c7GMwZ8RVG04=", + version = "v1.3.1", ) go_repository( name = "com_github_bazelbuild_buildtools", @@ -1299,6 +1317,14 @@ def go_deps(): sum = "h1:fAjc9m62+UWV/WAFKLNi6ZS0675eEUC9y3AlwSbQu1Y=", version = "v0.0.0-20200201041132-a6ae2369ad13", ) + go_repository( + name = "com_github_dgryski_go_rendezvous", + build_file_proto_mode = "disable", + importpath = "github.com/dgryski/go-rendezvous", + sum = "h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=", + version = "v0.0.0-20200823014737-9f7001d12a5f", + ) + go_repository( name = "com_github_dgryski_go_sip13", build_file_proto_mode = "disable", @@ -2412,14 +2438,8 @@ def go_deps(): name = "com_github_golang_jwt_jwt_v5", build_file_proto_mode = "disable_global", importpath = "github.com/golang-jwt/jwt/v5", - sha256 = "ad5cdc5c6bac562a2b890e96347208ffdb30a940243b558465ab7de90913a180", - strip_prefix = "github.com/golang-jwt/jwt/v5@v5.2.1", - urls = [ - "http://bazel-cache.pingcap.net:8080/gomod/github.com/golang-jwt/jwt/v5/com_github_golang_jwt_jwt_v5-v5.2.1.zip", - "http://ats.apps.svc/gomod/github.com/golang-jwt/jwt/v5/com_github_golang_jwt_jwt_v5-v5.2.1.zip", - "https://cache.hawkingrei.com/gomod/github.com/golang-jwt/jwt/v5/com_github_golang_jwt_jwt_v5-v5.2.1.zip", - "https://storage.googleapis.com/pingcapmirror/gomod/github.com/golang-jwt/jwt/v5/com_github_golang_jwt_jwt_v5-v5.2.1.zip", - ], + sum = "h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=", + version = "v5.2.1", ) go_repository( name = "com_github_golang_mock", @@ -2723,8 +2743,8 @@ def go_deps(): name = "com_github_google_uuid", build_file_proto_mode = "disable_global", importpath = "github.com/google/uuid", - sum = "h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=", - version = "v1.3.1", + sum = "h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=", + version = "v1.6.0", ) go_repository( name = "com_github_googleapis_enterprise_certificate_proxy", @@ -3748,6 +3768,14 @@ def go_deps(): "https://storage.googleapis.com/pingcapmirror/gomod/github.com/kballard/go-shellquote/com_github_kballard_go_shellquote-v0.0.0-20180428030007-95032a82bc51.zip", ], ) + go_repository( + name = "com_github_keybase_go_keychain", + build_file_proto_mode = "disable", + importpath = "github.com/keybase/go-keychain", + sum = "h1:IsMZxCuZqKuao2vNdfD82fjjgPLfyHLpR41Z88viRWs=", + version = "v0.0.0-20231219164618-57a3676c3af6", + ) + go_repository( name = "com_github_kimmachinegun_automemlimit", build_file_proto_mode = "disable_global", @@ -4458,8 +4486,8 @@ def go_deps(): name = "com_github_montanaflynn_stats", build_file_proto_mode = "disable_global", importpath = "github.com/montanaflynn/stats", - sum = "h1:pmpDGKLw4n82EtrNiLqB+xSz/JQwFOaZuMALYUHwX5s=", - version = "v0.0.0-20180911141734-db72e6cae808", + sum = "h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY/JU=", + version = "v0.7.0", ) go_repository( name = "com_github_moricho_tparallel", @@ -4990,8 +5018,8 @@ def go_deps(): name = "com_github_pkg_browser", build_file_proto_mode = "disable_global", importpath = "github.com/pkg/browser", - sum = "h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=", - version = "v0.0.0-20180916011732-0a3d74bf9ce4", + sum = "h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=", + version = "v0.0.0-20240102092130-5ac0b6a4141c", ) go_repository( name = "com_github_pkg_diff", @@ -5253,6 +5281,13 @@ def go_deps(): sum = "h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=", version = "v0.0.0-20201227073835-cf1acfcdf475", ) + go_repository( + name = "com_github_redis_go_redis_v9", + build_file_proto_mode = "disable", + importpath = "github.com/redis/go-redis/v9", + sum = "h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4=", + version = "v9.6.1", + ) go_repository( name = "com_github_remyoudompheng_bigfft", @@ -5300,8 +5335,8 @@ def go_deps(): name = "com_github_rogpeppe_go_internal", build_file_proto_mode = "disable_global", importpath = "github.com/rogpeppe/go-internal", - sum = "h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=", - version = "v1.10.0", + sum = "h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=", + version = "v1.12.0", ) go_repository( name = "com_github_rubyist_circuitbreaker", @@ -7863,8 +7898,8 @@ def go_deps(): name = "org_golang_x_crypto", build_file_proto_mode = "disable_global", importpath = "golang.org/x/crypto", - sum = "h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=", - version = "v0.26.0", + sum = "h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=", + version = "v0.29.0", ) go_repository( name = "org_golang_x_exp", @@ -7912,8 +7947,8 @@ def go_deps(): name = "org_golang_x_net", build_file_proto_mode = "disable_global", importpath = "golang.org/x/net", - sum = "h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=", - version = "v0.28.0", + sum = "h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=", + version = "v0.31.0", ) go_repository( name = "org_golang_x_oauth2", @@ -7939,15 +7974,15 @@ def go_deps(): name = "org_golang_x_sync", build_file_proto_mode = "disable_global", importpath = "golang.org/x/sync", - sum = "h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=", - version = "v0.8.0", + sum = "h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=", + version = "v0.9.0", ) go_repository( name = "org_golang_x_sys", build_file_proto_mode = "disable_global", importpath = "golang.org/x/sys", - sum = "h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=", - version = "v0.23.0", + sum = "h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=", + version = "v0.27.0", ) go_repository( name = "org_golang_x_telemetry", @@ -7960,15 +7995,15 @@ def go_deps(): name = "org_golang_x_term", build_file_proto_mode = "disable_global", importpath = "golang.org/x/term", - sum = "h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=", - version = "v0.23.0", + sum = "h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=", + version = "v0.26.0", ) go_repository( name = "org_golang_x_text", build_file_proto_mode = "disable_global", importpath = "golang.org/x/text", - sum = "h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=", - version = "v0.17.0", + sum = "h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=", + version = "v0.20.0", ) go_repository( name = "org_golang_x_time", diff --git a/br/pkg/lightning/backend/backend.go b/br/pkg/lightning/backend/backend.go index eac01a76662d2..bee8ed8feb429 100644 --- a/br/pkg/lightning/backend/backend.go +++ b/br/pkg/lightning/backend/backend.go @@ -15,6 +15,7 @@ package backend import ( + "cmp" "context" "fmt" "time" @@ -303,11 +304,11 @@ func (be Backend) CheckDiskQuota(quota int64) ( totalMemSize int64, ) { sizes := be.abstract.EngineFileSizes() - slices.SortFunc(sizes, func(i, j EngineFileSize) bool { - if i.IsImporting != j.IsImporting { - return i.IsImporting + slices.SortFunc(sizes, func(i, j EngineFileSize) int { + if i.IsImporting != j.IsImporting && i.IsImporting { + return -1 } - return i.DiskSize+i.MemSize < j.DiskSize+j.MemSize + return cmp.Compare(i.DiskSize+i.MemSize, j.DiskSize+j.MemSize) }) for _, size := range sizes { totalDiskSize += size.DiskSize diff --git a/br/pkg/lightning/backend/kv/sql2kv.go b/br/pkg/lightning/backend/kv/sql2kv.go index 1ff8390f6c564..0877e9015148b 100644 --- a/br/pkg/lightning/backend/kv/sql2kv.go +++ b/br/pkg/lightning/backend/kv/sql2kv.go @@ -17,6 +17,7 @@ package kv import ( + "cmp" "context" "fmt" "math" @@ -186,8 +187,8 @@ func collectGeneratedColumns(se *session, meta *model.TableInfo, cols []*table.C } // order the result by column offset so they match the evaluation order. - slices.SortFunc(genCols, func(i, j genCol) bool { - return cols[i.index].Offset < cols[j.index].Offset + slices.SortFunc(genCols, func(i, j genCol) int { + return cmp.Compare(cols[i.index].Offset, cols[j.index].Offset) }) return genCols, nil } diff --git a/br/pkg/lightning/backend/local/engine.go b/br/pkg/lightning/backend/local/engine.go index 79ef97ddce45e..625fc1b9bc380 100644 --- a/br/pkg/lightning/backend/local/engine.go +++ b/br/pkg/lightning/backend/local/engine.go @@ -752,8 +752,8 @@ func (e *Engine) batchIngestSSTs(metas []*sstMeta) error { if len(metas) == 0 { return nil } - slices.SortFunc(metas, func(i, j *sstMeta) bool { - return bytes.Compare(i.minKey, j.minKey) < 0 + slices.SortFunc(metas, func(i, j *sstMeta) int { + return bytes.Compare(i.minKey, j.minKey) }) metaLevels := make([][]*sstMeta, 0) @@ -914,8 +914,8 @@ func sortAndMergeRanges(ranges []Range) []Range { return ranges } - slices.SortFunc(ranges, func(i, j Range) bool { - return bytes.Compare(i.start, j.start) < 0 + slices.SortFunc(ranges, func(i, j Range) int { + return bytes.Compare(i.start, j.start) }) curEnd := ranges[0].end @@ -1181,8 +1181,8 @@ func (w *Writer) flushKVs(ctx context.Context) error { return errors.Trace(err) } if !w.isWriteBatchSorted { - slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) bool { - return bytes.Compare(i.Key, j.Key) < 0 + slices.SortFunc(w.writeBatch[:w.batchCount], func(i, j common.KvPair) int { + return bytes.Compare(i.Key, j.Key) }) w.isWriteBatchSorted = true } diff --git a/br/pkg/lightning/backend/local/localhelper.go b/br/pkg/lightning/backend/local/localhelper.go index 5c423f8c26cb6..d7a80c2c534c4 100644 --- a/br/pkg/lightning/backend/local/localhelper.go +++ b/br/pkg/lightning/backend/local/localhelper.go @@ -203,8 +203,8 @@ func (local *local) SplitAndScatterRegionByRanges( var err1 error region := sp.region keys := sp.keys - slices.SortFunc(keys, func(i, j []byte) bool { - return bytes.Compare(i, j) < 0 + slices.SortFunc(keys, func(i, j []byte) int { + return bytes.Compare(i, j) }) splitRegion := region startIdx := 0 @@ -247,8 +247,8 @@ func (local *local) SplitAndScatterRegionByRanges( log.FromContext(ctx).Info("batch split region", zap.Uint64("region_id", splitRegion.Region.Id), zap.Int("keys", endIdx-startIdx), zap.Binary("firstKey", keys[startIdx]), zap.Binary("end", keys[endIdx-1])) - slices.SortFunc(newRegions, func(i, j *split.RegionInfo) bool { - return bytes.Compare(i.Region.StartKey, j.Region.StartKey) < 0 + slices.SortFunc(newRegions, func(i, j *split.RegionInfo) int { + return bytes.Compare(i.Region.StartKey, j.Region.StartKey) }) syncLock.Lock() scatterRegions = append(scatterRegions, newRegions...) @@ -293,8 +293,8 @@ func (local *local) SplitAndScatterRegionByRanges( if len(retryKeys) == 0 { break } - slices.SortFunc(retryKeys, func(i, j []byte) bool { - return bytes.Compare(i, j) < 0 + slices.SortFunc(retryKeys, func(i, j []byte) int { + return bytes.Compare(i, j) }) minKey = codec.EncodeBytes([]byte{}, retryKeys[0]) maxKey = codec.EncodeBytes([]byte{}, nextKey(retryKeys[len(retryKeys)-1])) diff --git a/br/pkg/lightning/checkpoints/checkpoints.go b/br/pkg/lightning/checkpoints/checkpoints.go index d20134660de9c..30230fe257923 100644 --- a/br/pkg/lightning/checkpoints/checkpoints.go +++ b/br/pkg/lightning/checkpoints/checkpoints.go @@ -15,6 +15,7 @@ package checkpoints import ( + "cmp" "context" "database/sql" "encoding/json" @@ -229,6 +230,13 @@ func (key *ChunkCheckpointKey) String() string { return fmt.Sprintf("%s:%d", key.Path, key.Offset) } +func (key *ChunkCheckpointKey) compare(other *ChunkCheckpointKey) int { + if c := cmp.Compare(key.Path, other.Path); c != 0 { + return c + } + return cmp.Compare(key.Offset, other.Offset) +} + func (key *ChunkCheckpointKey) less(other *ChunkCheckpointKey) bool { switch { case key.Path < other.Path: @@ -1257,8 +1265,8 @@ func (cpdb *FileCheckpointsDB) Get(_ context.Context, tableName string) (*TableC }) } - slices.SortFunc(engine.Chunks, func(i, j *ChunkCheckpoint) bool { - return i.Key.less(&j.Key) + slices.SortFunc(engine.Chunks, func(i, j *ChunkCheckpoint) int { + return i.Key.compare(&j.Key) }) cp.Engines[engineID] = engine diff --git a/br/pkg/restore/client.go b/br/pkg/restore/client.go index c8f2db94a19f6..a8422c50ed974 100644 --- a/br/pkg/restore/client.go +++ b/br/pkg/restore/client.go @@ -4,6 +4,7 @@ package restore import ( "bytes" + "cmp" "context" "crypto/tls" "encoding/hex" @@ -654,8 +655,8 @@ func (rc *Client) CreateTables( newTables = append(newTables, et.Table) } // Let's ensure that it won't break the original order. - slices.SortFunc(newTables, func(i, j *model.TableInfo) bool { - return tbMapping[i.Name.String()] < tbMapping[j.Name.String()] + slices.SortFunc(newTables, func(i, j *model.TableInfo) int { + return cmp.Compare(tbMapping[i.Name.String()], tbMapping[j.Name.String()]) }) select { @@ -1027,8 +1028,8 @@ func (rc *Client) CheckSysTableCompatibility(dom *domain.Domain, tables []*metau // ExecDDLs executes the queries of the ddl jobs. func (rc *Client) ExecDDLs(ctx context.Context, ddlJobs []*model.Job) error { // Sort the ddl jobs by schema version in ascending order. - slices.SortFunc(ddlJobs, func(i, j *model.Job) bool { - return i.BinlogInfo.SchemaVersion < j.BinlogInfo.SchemaVersion + slices.SortFunc(ddlJobs, func(i, j *model.Job) int { + return cmp.Compare(i.BinlogInfo.SchemaVersion, j.BinlogInfo.SchemaVersion) }) for _, job := range ddlJobs { @@ -2276,26 +2277,14 @@ func (rc *Client) InitSchemasReplaceForDDL( } func SortMetaKVFiles(files []*backuppb.DataFileInfo) []*backuppb.DataFileInfo { - slices.SortFunc(files, func(i, j *backuppb.DataFileInfo) bool { - if i.GetMinTs() < j.GetMinTs() { - return true - } else if i.GetMinTs() > j.GetMinTs() { - return false - } - - if i.GetMaxTs() < j.GetMaxTs() { - return true - } else if i.GetMaxTs() > j.GetMaxTs() { - return false + slices.SortFunc(files, func(i, j *backuppb.DataFileInfo) int { + if c := cmp.Compare(i.GetMinTs(), j.GetMinTs()); c != 0 { + return c } - - if i.GetResolvedTs() < j.GetResolvedTs() { - return true - } else if i.GetResolvedTs() > j.GetResolvedTs() { - return false + if c := cmp.Compare(i.GetMaxTs(), j.GetMaxTs()); c != 0 { + return c } - - return true + return cmp.Compare(i.GetResolvedTs(), j.GetResolvedTs()) }) return files } @@ -2485,8 +2474,8 @@ func (rc *Client) RestoreBatchMetaKVFiles( } // sort these entries. - slices.SortFunc(curKvEntries, func(i, j *KvEntryWithTS) bool { - return i.ts < j.ts + slices.SortFunc(curKvEntries, func(i, j *KvEntryWithTS) int { + return cmp.Compare(i.ts, j.ts) }) // restore these entries with rawPut() method. diff --git a/br/pkg/restore/db.go b/br/pkg/restore/db.go index 132e3294f1617..e3808d9d47670 100644 --- a/br/pkg/restore/db.go +++ b/br/pkg/restore/db.go @@ -3,6 +3,7 @@ package restore import ( + "cmp" "context" "fmt" "sync" @@ -396,8 +397,8 @@ func (db *DB) ensureTablePlacementPolicies(ctx context.Context, tableInfo *model // FilterDDLJobs filters ddl jobs. func FilterDDLJobs(allDDLJobs []*model.Job, tables []*metautil.Table) (ddlJobs []*model.Job) { // Sort the ddl jobs by schema version in descending order. - slices.SortFunc(allDDLJobs, func(i, j *model.Job) bool { - return i.BinlogInfo.SchemaVersion > j.BinlogInfo.SchemaVersion + slices.SortFunc(allDDLJobs, func(i, j *model.Job) int { + return cmp.Compare(j.BinlogInfo.SchemaVersion, i.BinlogInfo.SchemaVersion) }) dbs := getDatabases(tables) for _, db := range dbs { diff --git a/br/pkg/task/stream.go b/br/pkg/task/stream.go index 6f508c9a5bf27..0777828d4bb91 100644 --- a/br/pkg/task/stream.go +++ b/br/pkg/task/stream.go @@ -401,8 +401,8 @@ func (s *streamMgr) buildObserveRanges(ctx context.Context) ([]kv.KeyRange, erro mRange := stream.BuildObserveMetaRange() rs := append([]kv.KeyRange{*mRange}, dRanges...) - slices.SortFunc(rs, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(rs, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) return rs, nil diff --git a/ddl/cluster.go b/ddl/cluster.go index e05964c8826fa..e84828845d433 100644 --- a/ddl/cluster.go +++ b/ddl/cluster.go @@ -16,6 +16,7 @@ package ddl import ( "bytes" + "cmp" "context" "encoding/hex" "fmt" @@ -274,8 +275,8 @@ func GetFlashbackKeyRanges(sess sessionctx.Context) ([]kv.KeyRange, error) { } } - slices.SortFunc(flashbackIDs, func(a, b flashbackID) bool { - return a.id < b.id + slices.SortFunc(flashbackIDs, func(a, b flashbackID) int { + return cmp.Compare(a.id, b.id) }) lastExcludeIdx := -1 diff --git a/ddl/ddl.go b/ddl/ddl.go index ed774c202b14a..b01742a9fd041 100644 --- a/ddl/ddl.go +++ b/ddl/ddl.go @@ -19,6 +19,7 @@ package ddl import ( + "cmp" "context" "encoding/json" "flag" @@ -1699,8 +1700,8 @@ func getDDLJobs(t *meta.Meta) ([]*model.Job, error) { return nil, errors.Trace(err) } jobs := append(generalJobs, addIdxJobs...) - slices.SortFunc(jobs, func(i, j *model.Job) bool { - return i.ID < j.ID + slices.SortFunc(jobs, func(i, j *model.Job) int { + return cmp.Compare(i.ID, j.ID) }) return jobs, nil } @@ -1860,8 +1861,8 @@ func GetAllHistoryDDLJobs(m *meta.Meta) ([]*model.Job, error) { } } // sort job. - slices.SortFunc(allJobs, func(i, j *model.Job) bool { - return i.ID < j.ID + slices.SortFunc(allJobs, func(i, j *model.Job) int { + return cmp.Compare(i.ID, j.ID) }) return allJobs, nil } diff --git a/ddl/index.go b/ddl/index.go index be5ce0df8d495..d7acabdcdd8b7 100644 --- a/ddl/index.go +++ b/ddl/index.go @@ -16,6 +16,7 @@ package ddl import ( "bytes" + "cmp" "context" "encoding/hex" "fmt" @@ -1055,7 +1056,7 @@ func RemoveDependentHiddenColumns(tblInfo *model.TableInfo, idxInfo *model.Index } } // Sort the offset in descending order. - slices.SortFunc(hiddenColOffs, func(a, b int) bool { return a > b }) + slices.SortFunc(hiddenColOffs, func(a, b int) int { return cmp.Compare(a, b) }) // Move all the dependent hidden columns to the end. endOffset := len(tblInfo.Columns) - 1 for _, offset := range hiddenColOffs { diff --git a/executor/aggregate.go b/executor/aggregate.go index 561bd4dcd9502..7520521607e78 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -16,6 +16,7 @@ package executor import ( "bytes" + "cmp" "context" "fmt" "sync" @@ -1188,7 +1189,7 @@ func (*HashAggRuntimeStats) workerString(buf *bytes.Buffer, prefix string, concu time.Duration(wallTime), concurrency, totalTaskNum, time.Duration(totalWait), time.Duration(totalExec), time.Duration(totalTime))) n := len(workerStats) if n > 0 { - slices.SortFunc(workerStats, func(i, j *AggWorkerStat) bool { return i.WorkerTime < j.WorkerTime }) + slices.SortFunc(workerStats, func(i, j *AggWorkerStat) int { return cmp.Compare(i.WorkerTime, j.WorkerTime) }) buf.WriteString(fmt.Sprintf(", max:%v, p95:%v", time.Duration(workerStats[n-1].WorkerTime), time.Duration(workerStats[n*19/20].WorkerTime))) } diff --git a/executor/batch_point_get.go b/executor/batch_point_get.go index 965708073a097..3134d37c0366e 100644 --- a/executor/batch_point_get.go +++ b/executor/batch_point_get.go @@ -250,11 +250,11 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error { toFetchIndexKeys = append(toFetchIndexKeys, idxKey) } if e.keepOrder { - slices.SortFunc(toFetchIndexKeys, func(i, j kv.Key) bool { + slices.SortFunc(toFetchIndexKeys, func(i, j kv.Key) int { if e.desc { - return i.Cmp(j) > 0 + return j.Cmp(i) } - return i.Cmp(j) < 0 + return i.Cmp(j) }) } @@ -318,11 +318,11 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error { failpoint.InjectContext(ctx, "batchPointGetRepeatableReadTest-step2", nil) }) } else if e.keepOrder { - less := func(i, j kv.Handle) bool { + less := func(i, j kv.Handle) int { if e.desc { - return i.Compare(j) > 0 + return j.Compare(i) } - return i.Compare(j) < 0 + return i.Compare(j) } if e.tblInfo.PKIsHandle && mysql.HasUnsignedFlag(e.tblInfo.GetPkColInfo().GetFlag()) { uintComparator := func(i, h kv.Handle) int { @@ -339,11 +339,11 @@ func (e *BatchPointGetExec) initialize(ctx context.Context) error { } return 0 } - less = func(i, j kv.Handle) bool { + less = func(i, j kv.Handle) int { if e.desc { - return uintComparator(i, j) > 0 + return uintComparator(j, i) } - return uintComparator(i, j) < 0 + return uintComparator(i, j) } } slices.SortFunc(e.handles, less) diff --git a/executor/builder.go b/executor/builder.go index 83a932d1e1064..1bb30c9c338f2 100644 --- a/executor/builder.go +++ b/executor/builder.go @@ -16,6 +16,7 @@ package executor import ( "bytes" + "cmp" "context" "math" "strconv" @@ -3521,8 +3522,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, @@ -3641,8 +3642,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 } @@ -4244,8 +4245,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) } @@ -4282,8 +4283,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) } @@ -4403,8 +4404,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 @@ -4658,8 +4659,8 @@ func buildKvRangesForIndexJoin(ctx sessionctx.Context, tableID, indexID int64, l memTracker.Consume(2 * 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 } diff --git a/executor/distsql.go b/executor/distsql.go index ac531a452fb8f..7188b234d48f0 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -325,8 +325,8 @@ func (e *IndexReaderExecutor) open(ctx context.Context, kvRanges *kv.KeyRanges) e.memTracker = memory.NewTracker(e.id, -1) } e.memTracker.AttachTo(e.ctx.GetSessionVars().StmtCtx.MemTracker) - kvRanges.SortByFunc(func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + kvRanges.SortByFunc(func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) var builder distsql.RequestBuilder builder.SetWrappedKeyRanges(kvRanges). @@ -636,8 +636,8 @@ func (e *IndexLookUpExecutor) startIndexWorker(ctx context.Context, workCh chan< // init kvReq, result and worker for this partition // The key ranges should be ordered. - slices.SortFunc(kvRange, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(kvRange, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) kvReq, err := builder.SetKeyRanges(kvRange).Build() if err != nil { diff --git a/executor/index_lookup_join.go b/executor/index_lookup_join.go index ee654b282cfe4..1c6a9cab4aa09 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -655,12 +655,12 @@ func (iw *innerWorker) sortAndDedupLookUpContents(lookUpContents []*indexJoinLoo return lookUpContents } sc := iw.ctx.GetSessionVars().StmtCtx - slices.SortFunc(lookUpContents, func(i, j *indexJoinLookUpContent) bool { + slices.SortFunc(lookUpContents, func(i, j *indexJoinLookUpContent) int { cmp := compareRow(sc, i.keys, j.keys, iw.keyCollators) if cmp != 0 || iw.nextColCompareFilters == nil { - return cmp < 0 + return cmp } - return iw.nextColCompareFilters.CompareRow(i.row, j.row) < 0 + return iw.nextColCompareFilters.CompareRow(i.row, j.row) }) deDupedLookupKeys := lookUpContents[:1] for i := 1; i < len(lookUpContents); i++ { diff --git a/executor/index_lookup_merge_join.go b/executor/index_lookup_merge_join.go index e0fb176fff589..60b9eacd4e73f 100644 --- a/executor/index_lookup_merge_join.go +++ b/executor/index_lookup_merge_join.go @@ -449,23 +449,29 @@ func (imw *innerMergeWorker) handleTask(ctx context.Context, task *lookUpMergeJo // Because the necessary condition of merge join is both outer and inner keep order of join keys. // In this case, we need sort the outer side. if imw.outerMergeCtx.needOuterSort { - slices.SortFunc(task.outerOrderIdx, func(idxI, idxJ chunk.RowPtr) bool { + slices.SortFunc(task.outerOrderIdx, func(idxI, idxJ chunk.RowPtr) int { rowI, rowJ := task.outerResult.GetRow(idxI), task.outerResult.GetRow(idxJ) - var cmp int64 + var c int64 var err error for _, keyOff := range imw.keyOff2KeyOffOrderByIdx { joinKey := imw.outerMergeCtx.joinKeys[keyOff] - cmp, _, err = imw.outerMergeCtx.compareFuncs[keyOff](imw.ctx, joinKey, joinKey, rowI, rowJ) + c, _, err = imw.outerMergeCtx.compareFuncs[keyOff](imw.ctx, joinKey, joinKey, rowI, rowJ) terror.Log(err) - if cmp != 0 { + if c != 0 { break } } - if cmp != 0 || imw.nextColCompareFilters == nil { - return (cmp < 0 && !imw.desc) || (cmp > 0 && imw.desc) + if c != 0 || imw.nextColCompareFilters == nil { + if imw.desc { + return int(-c) + } + return int(c) + } + c = int64(imw.nextColCompareFilters.CompareRow(rowI, rowJ)) + if imw.desc { + return int(-c) } - cmp = int64(imw.nextColCompareFilters.CompareRow(rowI, rowJ)) - return (cmp < 0 && !imw.desc) || (cmp > 0 && imw.desc) + return int(c) }) } dLookUpKeys, err := imw.constructDatumLookupKeys(task) diff --git a/executor/index_merge_reader.go b/executor/index_merge_reader.go index 46b6db3ecf678..20e78ee80f951 100644 --- a/executor/index_merge_reader.go +++ b/executor/index_merge_reader.go @@ -384,8 +384,8 @@ func (e *IndexMergeReaderExecutor) startPartialIndexWorker(ctx context.Context, // init kvReq and worker for this partition // The key ranges should be ordered. - slices.SortFunc(keyRange, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(keyRange, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) kvReq, err := builder.SetKeyRanges(keyRange).Build() if err != nil { diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 786c3aa41dc4a..4dbefb0dca10f 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -16,6 +16,7 @@ package executor import ( "bytes" + "cmp" "context" "encoding/hex" "encoding/json" @@ -3009,8 +3010,8 @@ func (e *hugeMemTableRetriever) retrieve(ctx context.Context, sctx sessionctx.Co if !e.initialized { is := sctx.GetInfoSchema().(infoschema.InfoSchema) dbs := is.AllSchemas() - slices.SortFunc(dbs, func(i, j *model.DBInfo) bool { - return i.Name.L < j.Name.L + slices.SortFunc(dbs, func(i, j *model.DBInfo) int { + return cmp.Compare(i.Name.L, j.Name.L) }) e.dbs = dbs e.initialized = true diff --git a/executor/inspection_result.go b/executor/inspection_result.go index 55793a7729274..e70ef5b5f80e9 100644 --- a/executor/inspection_result.go +++ b/executor/inspection_result.go @@ -15,6 +15,7 @@ package executor import ( + "cmp" "context" "fmt" "math" @@ -169,20 +170,22 @@ func (e *inspectionResultRetriever) retrieve(ctx context.Context, sctx sessionct continue } // make result stable - slices.SortFunc(results, func(i, j inspectionResult) bool { - if i.degree != j.degree { - return i.degree > j.degree + slices.SortFunc(results, func(i, j inspectionResult) int { + if c := cmp.Compare(i.degree, j.degree); c != 0 { + return -c } - if lhs, rhs := i.item, j.item; lhs != rhs { - return lhs < rhs + // lhs and rhs + if c := cmp.Compare(i.item, j.item); c != 0 { + return c } - if i.actual != j.actual { - return i.actual < j.actual + if c := cmp.Compare(i.actual, j.actual); c != 0 { + return c } - if lhs, rhs := i.tp, j.tp; lhs != rhs { - return lhs < rhs + // lhs and rhs + if c := cmp.Compare(i.tp, j.tp); c != 0 { + return c } - return i.instance < j.instance + return cmp.Compare(i.instance, j.instance) }) for _, result := range results { if len(result.instance) == 0 { diff --git a/executor/memtable_reader.go b/executor/memtable_reader.go index dc215e71fe3bb..60c8a798292d8 100644 --- a/executor/memtable_reader.go +++ b/executor/memtable_reader.go @@ -16,6 +16,7 @@ package executor import ( "bytes" + "cmp" "container/heap" "context" "encoding/json" @@ -252,7 +253,7 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String } items = append(items, item{key: key, val: str}) } - slices.SortFunc(items, func(i, j item) bool { return i.key < j.key }) + slices.SortFunc(items, func(i, j item) int { return cmp.Compare(i.key, j.key) }) var rows [][]types.Datum for _, item := range items { rows = append(rows, types.MakeDatums( @@ -279,7 +280,7 @@ func fetchClusterConfig(sctx sessionctx.Context, nodeTypes, nodeAddrs set.String } results = append(results, result) } - slices.SortFunc(results, func(i, j result) bool { return i.idx < j.idx }) + slices.SortFunc(results, func(i, j result) int { return cmp.Compare(i.idx, j.idx) }) for _, result := range results { finalRows = append(finalRows, result.rows...) } @@ -357,7 +358,7 @@ func (e *clusterServerInfoRetriever) retrieve(ctx context.Context, sctx sessionc } results = append(results, result) } - slices.SortFunc(results, func(i, j result) bool { return i.idx < j.idx }) + slices.SortFunc(results, func(i, j result) int { return cmp.Compare(i.idx, j.idx) }) for _, result := range results { finalRows = append(finalRows, result.rows...) } diff --git a/executor/sample.go b/executor/sample.go index e7eb9bd223639..b35d8c5deb4a6 100644 --- a/executor/sample.go +++ b/executor/sample.go @@ -228,12 +228,12 @@ func splitIntoMultiRanges(store kv.Storage, startKey, endKey kv.Key) ([]kv.KeyRa } func sortRanges(ranges []kv.KeyRange, isDesc bool) { - slices.SortFunc(ranges, func(i, j kv.KeyRange) bool { + slices.SortFunc(ranges, func(i, j kv.KeyRange) int { ir, jr := i.StartKey, j.StartKey if !isDesc { - return ir.Cmp(jr) < 0 + return ir.Cmp(jr) } - return ir.Cmp(jr) > 0 + return jr.Cmp(ir) }) } diff --git a/executor/show_placement.go b/executor/show_placement.go index ae562105476be..56e9abc08f6e0 100644 --- a/executor/show_placement.go +++ b/executor/show_placement.go @@ -15,6 +15,7 @@ package executor import ( + "cmp" "context" gjson "encoding/json" "fmt" @@ -251,7 +252,7 @@ func (e *ShowExec) fetchShowPlacement(ctx context.Context) error { func (e *ShowExec) fetchAllPlacementPolicies() error { policies := e.is.AllPlacementPolicies() - slices.SortFunc(policies, func(i, j *model.PolicyInfo) bool { return i.Name.O < j.Name.O }) + slices.SortFunc(policies, func(i, j *model.PolicyInfo) int { return cmp.Compare(i.Name.O, j.Name.O) }) for _, policy := range policies { name := policy.Name settings := policy.PlacementSettings @@ -266,7 +267,7 @@ func (e *ShowExec) fetchAllDBPlacements(ctx context.Context, scheduleState map[i activeRoles := e.ctx.GetSessionVars().ActiveRoles dbs := e.is.AllSchemas() - slices.SortFunc(dbs, func(i, j *model.DBInfo) bool { return i.Name.O < j.Name.O }) + slices.SortFunc(dbs, func(i, j *model.DBInfo) int { return cmp.Compare(i.Name.O, j.Name.O) }) for _, dbInfo := range dbs { if e.ctx.GetSessionVars().User != nil && checker != nil && !checker.DBIsVisible(activeRoles, dbInfo.Name.O) { @@ -300,7 +301,7 @@ func (e *ShowExec) fetchAllTablePlacements(ctx context.Context, scheduleState ma activeRoles := e.ctx.GetSessionVars().ActiveRoles dbs := e.is.AllSchemas() - slices.SortFunc(dbs, func(i, j *model.DBInfo) bool { return i.Name.O < j.Name.O }) + slices.SortFunc(dbs, func(i, j *model.DBInfo) int { return cmp.Compare(i.Name.O, j.Name.O) }) for _, dbInfo := range dbs { tableRowSets := make([]tableRowSet, 0) @@ -359,7 +360,7 @@ func (e *ShowExec) fetchAllTablePlacements(ctx context.Context, scheduleState ma } } - slices.SortFunc(tableRowSets, func(i, j tableRowSet) bool { return i.name < j.name }) + slices.SortFunc(tableRowSets, func(i, j tableRowSet) int { return cmp.Compare(i.name, j.name) }) for _, rowSet := range tableRowSets { for _, row := range rowSet.rows { e.appendRow(row) diff --git a/executor/show_stats.go b/executor/show_stats.go index 6161a173e8fe4..0773fac49565f 100644 --- a/executor/show_stats.go +++ b/executor/show_stats.go @@ -15,6 +15,7 @@ package executor import ( + "cmp" "fmt" "strings" @@ -382,7 +383,7 @@ func stableColsStats(colStats map[int64]*statistics.Column) (cols []*statistics. for _, col := range colStats { cols = append(cols, col) } - slices.SortFunc(cols, func(i, j *statistics.Column) bool { return i.ID < j.ID }) + slices.SortFunc(cols, func(i, j *statistics.Column) int { return cmp.Compare(i.ID, j.ID) }) return } @@ -390,7 +391,7 @@ func stableIdxsStats(idxStats map[int64]*statistics.Index) (idxs []*statistics.I for _, idx := range idxStats { idxs = append(idxs, idx) } - slices.SortFunc(idxs, func(i, j *statistics.Index) bool { return i.ID < j.ID }) + slices.SortFunc(idxs, func(i, j *statistics.Index) int { return cmp.Compare(i.ID, j.ID) }) return } diff --git a/executor/slow_query.go b/executor/slow_query.go index 395d8f4eba8ac..d5d6dad2de313 100644 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -962,8 +962,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 } diff --git a/executor/sort.go b/executor/sort.go index cb2c97e68a8e4..d11e4a7e10fc5 100644 --- a/executor/sort.go +++ b/executor/sort.go @@ -275,6 +275,20 @@ func (e *SortExec) lessRow(rowI, rowJ chunk.Row) bool { return false } +func (e *SortExec) compressRow(rowI, rowJ chunk.Row) int { + for i, colIdx := range e.keyColumns { + cmpFunc := e.keyCmpFuncs[i] + cmp := cmpFunc(rowI, colIdx, rowJ, colIdx) + if e.ByItems[i].Desc { + cmp = -cmp + } + if cmp != 0 { + return cmp + } + } + return 0 +} + type partitionPointer struct { row chunk.Row partitionID int @@ -378,6 +392,12 @@ func (e *TopNExec) keyColumnsLess(i, j chunk.RowPtr) bool { return e.lessRow(rowI, rowJ) } +func (e *TopNExec) keyColumnsCompare(i, j chunk.RowPtr) int { + rowI := e.rowChunks.GetRow(i) + rowJ := e.rowChunks.GetRow(j) + return e.compressRow(rowI, rowJ) +} + func (e *TopNExec) initPointers() { e.rowPtrs = make([]chunk.RowPtr, 0, e.rowChunks.Len()) e.memTracker.Consume(int64(8 * e.rowChunks.Len())) @@ -483,7 +503,7 @@ func (e *TopNExec) executeTopN(ctx context.Context) error { } } } - slices.SortFunc(e.rowPtrs, e.keyColumnsLess) + slices.SortFunc(e.rowPtrs, e.keyColumnsCompare) return nil } diff --git a/executor/table_reader.go b/executor/table_reader.go index aa8fcf910be1b..374f21c805e1c 100644 --- a/executor/table_reader.go +++ b/executor/table_reader.go @@ -16,6 +16,7 @@ package executor import ( "bytes" + "cmp" "context" "time" @@ -318,8 +319,8 @@ func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Ra if err != nil { return nil, err } - kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + kvReq.KeyRanges.SortByFunc(func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) e.kvRanges = kvReq.KeyRanges.AppendSelfTo(e.kvRanges) @@ -457,9 +458,10 @@ 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 } diff --git a/executor/trace.go b/executor/trace.go index d0ffd92677c10..70634a1190ccf 100644 --- a/executor/trace.go +++ b/executor/trace.go @@ -312,7 +312,7 @@ 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() @@ -320,7 +320,7 @@ func dfsTree(t *appdash.Trace, prefix string, isLast bool, chk *chunk.Chunk) { if jevent, err := j.TimespanEvent(); err == nil { jstart = jevent.Start() } - return istart.Before(jstart) + return istart.Compare(jstart) }) for i, sp := range t.Sub { diff --git a/go.mod b/go.mod index 1512c41e84ee9..70754f8effbcc 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,9 @@ go 1.23 require ( cloud.google.com/go/storage v1.30.1 - github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0 - github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.2.0 + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 + github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/IBM/sarama v1.43.3 @@ -47,7 +47,7 @@ require ( github.com/google/btree v1.1.2 github.com/google/pprof v0.0.0-20211122183932-1daafda22083 github.com/google/skylark v0.0.0-20181101142754-a5f7082aabed - github.com/google/uuid v1.3.1 + github.com/google/uuid v1.6.0 github.com/gordonklaus/ineffassign v0.0.0-20210914165742-4cc7213b9bc8 github.com/gorilla/mux v1.8.0 github.com/gostaticanalysis/forcetypeassert v0.1.0 @@ -112,12 +112,12 @@ require ( go.uber.org/multierr v1.8.0 go.uber.org/zap v1.23.0 golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa - golang.org/x/net v0.28.0 + golang.org/x/net v0.31.0 golang.org/x/oauth2 v0.21.0 - golang.org/x/sync v0.8.0 - golang.org/x/sys v0.23.0 - golang.org/x/term v0.23.0 - golang.org/x/text v0.17.0 + golang.org/x/sync v0.9.0 + golang.org/x/sys v0.27.0 + golang.org/x/term v0.26.0 + golang.org/x/text v0.20.0 golang.org/x/time v0.2.0 golang.org/x/tools v0.21.1-0.20240531212143-b6235391adb3 google.golang.org/api v0.128.0 @@ -133,7 +133,8 @@ require ( cloud.google.com/go v0.110.7 // indirect cloud.google.com/go/compute/metadata v0.3.0 // indirect cloud.google.com/go/iam v1.1.1 // indirect - github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.3.1 // indirect github.com/DataDog/zstd v1.4.5 // indirect github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect github.com/VividCortex/ewma v1.2.0 // indirect @@ -166,6 +167,7 @@ require ( github.com/go-ole/go-ole v1.3.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang-jwt/jwt/v4 v4.4.2 // indirect + github.com/golang-jwt/jwt/v5 v5.2.1 // indirect github.com/golang/glog v1.1.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/google/gofuzz v1.1.0 // indirect @@ -195,6 +197,7 @@ require ( github.com/klauspost/cpuid v1.3.1 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect + github.com/kylelemons/godebug v1.1.0 // indirect github.com/lestrrat-go/blackmagic v1.0.2 // indirect github.com/lestrrat-go/httpcc v1.0.1 // indirect github.com/lestrrat-go/httprc v1.0.5 // indirect @@ -215,7 +218,7 @@ require ( github.com/pierrec/lz4/v4 v4.1.21 // indirect github.com/pingcap/check v0.0.0-20200212061837-5e12011dc712 // indirect github.com/pingcap/goleveldb v0.0.0-20191226122134-f82aafb29989 // indirect - github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 // indirect + github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/prometheus/procfs v0.15.1 // indirect @@ -223,7 +226,7 @@ require ( github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect github.com/rivo/uniseg v0.4.2 // indirect - github.com/rogpeppe/go-internal v1.10.0 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/segmentio/asm v1.2.0 // indirect github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect @@ -247,7 +250,7 @@ require ( go.opentelemetry.io/otel/sdk v1.0.1 // indirect go.opentelemetry.io/otel/trace v1.0.1 // indirect go.opentelemetry.io/proto/otlp v0.9.0 // indirect - golang.org/x/crypto v0.26.0 // indirect + golang.org/x/crypto v0.29.0 // indirect golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/go.sum b/go.sum index 9efe272786b80..0a110420227b1 100644 --- a/go.sum +++ b/go.sum @@ -34,13 +34,23 @@ github.com/AndreasBriese/bbloom v0.0.0-20190306092124-e2d15f34fcf9/go.mod h1:bOv github.com/Azure/azure-sdk-for-go v23.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0 h1:JZg6HRh6W6U4OLl6lk7BZ7BLisIzM9dG1R50zUk9C/M= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.16.0/go.mod h1:YL1xnZ6QejvQHWJrX/AvhFl4WW4rqHVoKspWNVwFk0M= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0 h1:VBvHGLJbaY0+c66NZHdS9cgjHVYSH6DDa0XJMyrblsI= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0/go.mod h1:GJzjM4SR9T0KyX5gKCVyz1ytD8FeWeUPCwtFCt1AyfE= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0 h1:B/dfvscEQtew9dVuoxqxrUKKv8Ih2f55PydknDamU+g= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0/go.mod h1:fiPSssYvltE08HJchL04dOy+RD4hgrjph0cwGGMntdI= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc= github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY= github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.2.0 h1:62Ew5xXg5UCGIXDOM7+y4IL5/6mQJq1nenhBCJAeGX8= github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.2.0/go.mod h1:eHWhQKXc1Gv1DvWH//UzgWjWFEo0Pp4pH2vBzjBw8Fc= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0 h1:mlmW46Q0B79I+Aj4azKC6xDMFN9a9SyZWESlGWYXbFs= +github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.5.0/go.mod h1:PXe2h+LKcWTX9afWdZoHyODqR4fBa5boUM/8uJfZ0Jo= github.com/Azure/go-autorest v11.2.8+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24= +github.com/AzureAD/microsoft-authentication-library-for-go v1.3.1 h1:gUDtaZk8heteyfdmv+pcfHvhR9llnh7c7GMwZ8RVG04= +github.com/AzureAD/microsoft-authentication-library-for-go v1.3.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= @@ -342,6 +352,8 @@ github.com/gogo/status v1.1.0/go.mod h1:BFv9nrluPLmrS0EmGVvLaPNmRosr9KapBYd5/hpY github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d/go.mod h1:nnjvkQ9ptGaCkuDUx6wNykzzlUixGxvkme+H/lnzb+A= github.com/golang-jwt/jwt/v4 v4.4.2 h1:rcc4lwaZgFMCZ5jxF9ABolDcIHdBytAFgqFPbSJQAYs= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= +github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= @@ -438,6 +450,8 @@ github.com/google/skylark v0.0.0-20181101142754-a5f7082aabed/go.mod h1:CKSX6SxHW github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.2.4 h1:uGy6JWR/uMIILU8wbf+OkstIrNiMjGpEIyhx8f6W7s4= github.com/googleapis/enterprise-certificate-proxy v0.2.4/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -798,6 +812,8 @@ github.com/pingcap/tipb v0.0.0-20221123081521-2fb828910813 h1:DbmCfCbcavo0JG+gSp github.com/pingcap/tipb v0.0.0-20221123081521-2fb828910813/go.mod h1:A7mrd7WHBl1o63LE2bIBGEJMTNWXqhgmYiOvMLxozfs= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ= +github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -861,6 +877,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rubyist/circuitbreaker v2.2.1+incompatible/go.mod h1:Ycs3JgJADPuzJDwffe12k6BZT8hxVi6lFK+gWYJLN4A= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= @@ -1109,6 +1126,8 @@ golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1202,6 +1221,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo= +golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1221,6 +1242,7 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1293,12 +1315,15 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= +golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1312,6 +1337,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/infoschema/builder.go b/infoschema/builder.go index 30f1a0da8c37e..b09952ed2c3d8 100644 --- a/infoschema/builder.go +++ b/infoschema/builder.go @@ -15,6 +15,7 @@ package infoschema import ( + "cmp" "context" "fmt" "strings" @@ -786,8 +787,8 @@ func (b *Builder) applyCreateTable(m *meta.Meta, dbInfo *model.DBInfo, tableID i bucketIdx := tableBucketIdx(tableID) sortedTbls := b.is.sortedTablesBuckets[bucketIdx] sortedTbls = append(sortedTbls, tbl) - slices.SortFunc(sortedTbls, func(i, j table.Table) bool { - return i.Meta().ID < j.Meta().ID + slices.SortFunc(sortedTbls, func(i, j table.Table) int { + return cmp.Compare(i.Meta().ID, j.Meta().ID) }) b.is.sortedTablesBuckets[bucketIdx] = sortedTbls @@ -981,8 +982,8 @@ func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, policies []*model.Pol // Sort all tables by `ID` for _, v := range info.sortedTablesBuckets { - slices.SortFunc(v, func(a, b table.Table) bool { - return a.Meta().ID < b.Meta().ID + slices.SortFunc(v, func(a, b table.Table) int { + return cmp.Compare(a.Meta().ID, b.Meta().ID) }) } return b, nil diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index 2076d0774a07c..13ff29618c52b 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -15,6 +15,7 @@ package infoschema import ( + "cmp" "fmt" "sort" "sync" @@ -135,8 +136,8 @@ func MockInfoSchema(tbList []*model.TableInfo) InfoSchema { result.sortedTablesBuckets[bucketIdx] = append(result.sortedTablesBuckets[bucketIdx], tbl) } for i := range result.sortedTablesBuckets { - slices.SortFunc(result.sortedTablesBuckets[i], func(i, j table.Table) bool { - return i.Meta().ID < j.Meta().ID + slices.SortFunc(result.sortedTablesBuckets[i], func(i, j table.Table) int { + return cmp.Compare(i.Meta().ID, j.Meta().ID) }) } return result @@ -162,8 +163,8 @@ func MockInfoSchemaWithSchemaVer(tbList []*model.TableInfo, schemaVer int64) Inf result.sortedTablesBuckets[bucketIdx] = append(result.sortedTablesBuckets[bucketIdx], tbl) } for i := range result.sortedTablesBuckets { - slices.SortFunc(result.sortedTablesBuckets[i], func(i, j table.Table) bool { - return i.Meta().ID < j.Meta().ID + slices.SortFunc(result.sortedTablesBuckets[i], func(i, j table.Table) int { + return cmp.Compare(i.Meta().ID, j.Meta().ID) }) } result.schemaMetaVersion = schemaVer diff --git a/infoschema/perfschema/tables.go b/infoschema/perfschema/tables.go index 9a5a36235cfa4..ab6b184388c13 100644 --- a/infoschema/perfschema/tables.go +++ b/infoschema/perfschema/tables.go @@ -15,6 +15,7 @@ package perfschema import ( + "cmp" "context" "fmt" "net/http" @@ -394,7 +395,7 @@ func dataForRemoteProfile(ctx sessionctx.Context, nodeType, uri string, isGorout } results = append(results, result) } - slices.SortFunc(results, func(i, j result) bool { return i.addr < j.addr }) + slices.SortFunc(results, func(i, j result) int { return cmp.Compare(i.addr, j.addr) }) var finalRows [][]types.Datum for _, result := range results { addr := types.NewStringDatum(result.addr) diff --git a/parser/model/model.go b/parser/model/model.go index 89db1169ebc9e..edb76121adab2 100644 --- a/parser/model/model.go +++ b/parser/model/model.go @@ -15,6 +15,7 @@ package model import ( "bytes" + "cmp" "encoding/json" "fmt" "strconv" @@ -1675,8 +1676,8 @@ func (db *DBInfo) Copy() *DBInfo { } // LessDBInfo is used for sorting DBInfo by DBInfo.Name. -func LessDBInfo(a *DBInfo, b *DBInfo) bool { - return a.Name.L < b.Name.L +func LessDBInfo(a *DBInfo, b *DBInfo) int { + return cmp.Compare(a.Name.L, b.Name.L) } // CIStr is case insensitive string. diff --git a/planner/core/fragment.go b/planner/core/fragment.go index 917f4392d9f9e..b374da4e1e6c7 100644 --- a/planner/core/fragment.go +++ b/planner/core/fragment.go @@ -15,6 +15,7 @@ package core import ( + "cmp" "context" "time" "unsafe" @@ -392,8 +393,8 @@ func (e *mppTaskGenerator) constructMPPTasksImpl(ctx context.Context, ts *Physic } func (e *mppTaskGenerator) constructMPPBuildTaskReqForPartitionedTable(ts *PhysicalTableScan, splitedRanges []*ranger.Range, partitions []table.PhysicalTable) (*kv.MPPBuildTasksRequest, []int64, error) { - 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()) }) partitionIDAndRanges := make([]kv.PartitionIDAndRanges, len(partitions)) allPartitionsIDs := make([]int64, len(partitions)) diff --git a/planner/core/hashcode.go b/planner/core/hashcode.go index 41b00de127390..9509483dc5dc1 100644 --- a/planner/core/hashcode.go +++ b/planner/core/hashcode.go @@ -79,7 +79,7 @@ func (p *LogicalSelection) HashCode() []byte { condHashCodes[i] = expr.HashCode(p.ctx.GetSessionVars().StmtCtx) } // Sort the conditions, so `a > 1 and a < 100` can equal to `a < 100 and a > 1`. - slices.SortFunc(condHashCodes, func(i, j []byte) bool { return bytes.Compare(i, j) < 0 }) + slices.SortFunc(condHashCodes, func(i, j []byte) int { return bytes.Compare(i, j) }) for _, condHashCode := range condHashCodes { result = encodeIntAsUint32(result, len(condHashCode)) diff --git a/planner/core/optimizer.go b/planner/core/optimizer.go index 4b30741c26200..2830237a866e4 100644 --- a/planner/core/optimizer.go +++ b/planner/core/optimizer.go @@ -15,6 +15,7 @@ package core import ( + "cmp" "context" "fmt" "math" @@ -319,24 +320,24 @@ func DoOptimize(ctx context.Context, sctx sessionctx.Context, flag uint64, logic func refineCETrace(sctx sessionctx.Context) { stmtCtx := sctx.GetSessionVars().StmtCtx stmtCtx.OptimizerCETrace = tracing.DedupCETrace(stmtCtx.OptimizerCETrace) - slices.SortFunc(stmtCtx.OptimizerCETrace, func(i, j *tracing.CETraceRecord) bool { + slices.SortFunc(stmtCtx.OptimizerCETrace, func(i, j *tracing.CETraceRecord) int { if i == nil && j != nil { - return true + return -1 } if i == nil || j == nil { - return false + return 1 } - if i.TableID != j.TableID { - return i.TableID < j.TableID + if c := cmp.Compare(i.TableID, j.TableID); c != 0 { + return c } - if i.Type != j.Type { - return i.Type < j.Type + if c := cmp.Compare(i.Type, j.Type); c != 0 { + return c } - if i.Expr != j.Expr { - return i.Expr < j.Expr + if c := cmp.Compare(i.Expr, j.Expr); c != 0 { + return c } - return i.RowCount < j.RowCount + return cmp.Compare(i.RowCount, j.RowCount) }) traceRecords := stmtCtx.OptimizerCETrace is := sctx.GetDomainInfoSchema().(infoschema.InfoSchema) diff --git a/planner/core/plan_cache_utils.go b/planner/core/plan_cache_utils.go index c8fbfa4cc6daf..8325849256565 100644 --- a/planner/core/plan_cache_utils.go +++ b/planner/core/plan_cache_utils.go @@ -15,6 +15,7 @@ package core import ( + "cmp" "context" "math" "strconv" @@ -97,8 +98,8 @@ func GeneratePlanCacheStmtWithAST(ctx context.Context, sctx sessionctx.Context, // The parameter markers are appended in visiting order, which may not // be the same as the position order in the query string. We need to // sort it by position. - slices.SortFunc(extractor.markers, func(i, j ast.ParamMarkerExpr) bool { - return i.(*driver.ParamMarkerExpr).Offset < j.(*driver.ParamMarkerExpr).Offset + slices.SortFunc(extractor.markers, func(i, j ast.ParamMarkerExpr) int { + return cmp.Compare(i.(*driver.ParamMarkerExpr).Offset, j.(*driver.ParamMarkerExpr).Offset) }) ParamCount := len(extractor.markers) for i := 0; i < ParamCount; i++ { diff --git a/planner/core/rule_partition_processor.go b/planner/core/rule_partition_processor.go index a5716bf28ded4..21bc732851712 100644 --- a/planner/core/rule_partition_processor.go +++ b/planner/core/rule_partition_processor.go @@ -16,6 +16,7 @@ package core import ( "bytes" + "cmp" "context" "fmt" gomath "math" @@ -1824,8 +1825,8 @@ func appendMakeUnionAllChildrenTranceStep(origin *DataSource, usedMap map[int64] for _, def := range usedMap { used = append(used, def) } - slices.SortFunc(used, func(i, j model.PartitionDefinition) bool { - return i.ID < j.ID + slices.SortFunc(used, func(i, j model.PartitionDefinition) int { + return cmp.Compare(i.ID, j.ID) }) if len(children) == 1 { newDS := plan.(*DataSource) diff --git a/privilege/privileges/cache.go b/privilege/privileges/cache.go index 301f95ef9a1e3..c8932a5c5493c 100644 --- a/privilege/privileges/cache.go +++ b/privilege/privileges/cache.go @@ -16,6 +16,7 @@ package privileges import ( "bytes" + "cmp" "context" "encoding/json" "fmt" @@ -444,21 +445,17 @@ func (p *MySQLPrivilege) buildUserMap() { p.UserMap = userMap } -func compareBaseRecord(x, y *baseRecord) bool { +func compareBaseRecord(x, y *baseRecord) int { // Compare two item by user's host first. c1 := compareHost(x.Host, y.Host) - if c1 < 0 { - return true - } - if c1 > 0 { - return false + if c1 != 0 { + return c1 } - // Then, compare item by user's name value. - return x.User < y.User + return cmp.Compare(x.User, y.User) } -func compareUserRecord(x, y UserRecord) bool { +func compareUserRecord(x, y UserRecord) int { return compareBaseRecord(&x.baseRecord, &y.baseRecord) } @@ -536,7 +533,7 @@ func (p *MySQLPrivilege) LoadDBTable(ctx sessionctx.Context) error { return nil } -func compareDBRecord(x, y dbRecord) bool { +func compareDBRecord(x, y dbRecord) int { return compareBaseRecord(&x.baseRecord, &y.baseRecord) } diff --git a/statistics/cmsketch.go b/statistics/cmsketch.go index 0757e7a0a3d4d..5ac3210696425 100644 --- a/statistics/cmsketch.go +++ b/statistics/cmsketch.go @@ -16,6 +16,7 @@ package statistics import ( "bytes" + "cmp" "fmt" "math" "reflect" @@ -650,8 +651,8 @@ func (c *TopN) Sort() { if c == nil { return } - slices.SortFunc(c.TopN, func(i, j TopNMeta) bool { - return bytes.Compare(i.Encoded, j.Encoded) < 0 + slices.SortFunc(c.TopN, func(i, j TopNMeta) int { + return bytes.Compare(i.Encoded, j.Encoded) }) } @@ -870,26 +871,35 @@ func checkEmptyTopNs(topNs []*TopN) bool { // SortTopnMeta sort topnMeta func SortTopnMeta(topnMetas []TopNMeta) []TopNMeta { - slices.SortFunc(topnMetas, func(i, j TopNMeta) bool { + slices.SortFunc(topnMetas, func(i, j TopNMeta) int { if i.Count != j.Count { - return i.Count > j.Count + return cmp.Compare(j.Count, i.Count) } - return bytes.Compare(i.Encoded, j.Encoded) < 0 + return bytes.Compare(i.Encoded, j.Encoded) }) return topnMetas } +// TopnMetaCompare compare topnMeta +func TopnMetaCompare(i, j TopNMeta) int { + c := cmp.Compare(i.Count, j.Count) + if c == 0 { + return c + } + return bytes.Compare(i.Encoded, j.Encoded) +} + // GetMergedTopNFromSortedSlice returns merged topn func GetMergedTopNFromSortedSlice(sorted []TopNMeta, n uint32) (*TopN, []TopNMeta) { return getMergedTopNFromSortedSlice(sorted, n) } func getMergedTopNFromSortedSlice(sorted []TopNMeta, n uint32) (*TopN, []TopNMeta) { - slices.SortFunc(sorted, func(i, j TopNMeta) bool { + slices.SortFunc(sorted, func(i, j TopNMeta) int { if i.Count != j.Count { - return i.Count > j.Count + return cmp.Compare(j.Count, i.Count) } - return bytes.Compare(i.Encoded, j.Encoded) < 0 + return bytes.Compare(i.Encoded, j.Encoded) }) n = mathutil.Min(uint32(len(sorted)), n) diff --git a/statistics/feedback.go b/statistics/feedback.go index 910d44167a1b0..ddbd688b913bf 100644 --- a/statistics/feedback.go +++ b/statistics/feedback.go @@ -353,19 +353,19 @@ func NonOverlappedFeedbacks(sc *stmtctx.StatementContext, fbs []Feedback) ([]Fee // Sort feedbacks by end point and start point incrementally, then pick every feedback that is not overlapped // with the previous chosen feedbacks. var existsErr bool - slices.SortFunc(fbs, func(i, j Feedback) bool { + slices.SortFunc(fbs, func(i, j Feedback) int { res, err := i.Upper.Compare(sc, j.Upper, collate.GetBinaryCollator()) if err != nil { existsErr = true } if existsErr || res != 0 { - return res < 0 + return res } res, err = i.Lower.Compare(sc, j.Lower, collate.GetBinaryCollator()) if err != nil { existsErr = true } - return res < 0 + return res }) if existsErr { return fbs, false diff --git a/statistics/handle/update.go b/statistics/handle/update.go index 28560ac5878a3..3f4698675fdf0 100644 --- a/statistics/handle/update.go +++ b/statistics/handle/update.go @@ -16,6 +16,7 @@ package handle import ( "bytes" + "cmp" "context" "fmt" "math" @@ -950,11 +951,11 @@ func (h *Handle) DumpColStatsUsageToKV() error { for id, t := range colMap { pairs = append(pairs, pair{tblColID: id, lastUsedAt: t.UTC().Format(types.TimeFormat)}) } - slices.SortFunc(pairs, func(i, j pair) bool { + slices.SortFunc(pairs, func(i, j pair) int { if i.tblColID.TableID == j.tblColID.TableID { - return i.tblColID.ID < j.tblColID.ID + return cmp.Compare(i.tblColID.ID, j.tblColID.ID) } - return i.tblColID.TableID < j.tblColID.TableID + return cmp.Compare(i.tblColID.TableID, j.tblColID.TableID) }) // Use batch insert to reduce cost. for i := 0; i < len(pairs); i += batchInsertSize { diff --git a/statistics/histogram.go b/statistics/histogram.go index a9aedf8a1d247..f1c50774ae578 100644 --- a/statistics/histogram.go +++ b/statistics/histogram.go @@ -347,8 +347,8 @@ func (hg *Histogram) RemoveVals(valCntPairs []TopNMeta) { // AddIdxVals adds the given values to the histogram. func (hg *Histogram) AddIdxVals(idxValCntPairs []TopNMeta) { totalAddCnt := int64(0) - slices.SortFunc(idxValCntPairs, func(i, j TopNMeta) bool { - return bytes.Compare(i.Encoded, j.Encoded) < 0 + slices.SortFunc(idxValCntPairs, func(i, j TopNMeta) int { + return bytes.Compare(i.Encoded, j.Encoded) }) for bktIdx, pairIdx := 0, 0; bktIdx < hg.Len(); bktIdx++ { for pairIdx < len(idxValCntPairs) { @@ -1475,19 +1475,19 @@ func MergePartitionHist2GlobalHist(sc *stmtctx.StatementContext, hists []*Histog buckets = buckets[:tail] var sortError error - slices.SortFunc(buckets, func(i, j *bucket4Merging) bool { + slices.SortFunc(buckets, func(i, j *bucket4Merging) int { res, err := i.upper.Compare(sc, j.upper, collate.GetBinaryCollator()) if err != nil { sortError = err } if res != 0 { - return res < 0 + return res } res, err = i.lower.Compare(sc, j.lower, collate.GetBinaryCollator()) if err != nil { sortError = err } - return res < 0 + return res }) if sortError != nil { return nil, sortError diff --git a/statistics/selectivity.go b/statistics/selectivity.go index 99458cc04bea6..acc6248c10d92 100644 --- a/statistics/selectivity.go +++ b/statistics/selectivity.go @@ -16,6 +16,7 @@ package statistics import ( "bytes" + "cmp" "math" "math/bits" @@ -534,11 +535,11 @@ func getMaskAndRanges(ctx sessionctx.Context, exprs []expression.Expression, ran // GetUsableSetsByGreedy will select the indices and pk used for calculate selectivity by greedy algorithm. func GetUsableSetsByGreedy(nodes []*StatsNode) (newBlocks []*StatsNode) { - slices.SortFunc(nodes, func(i, j *StatsNode) bool { + slices.SortFunc(nodes, func(i, j *StatsNode) int { if r := compareType(i.Tp, j.Tp); r != 0 { - return r < 0 + return r } - return i.ID < j.ID + return cmp.Compare(i.ID, j.ID) }) marked := make([]bool, len(nodes)) mask := int64(math.MaxInt64) diff --git a/statistics/table.go b/statistics/table.go index b9c0bcb5be777..a1f2df0639f39 100644 --- a/statistics/table.go +++ b/statistics/table.go @@ -15,6 +15,7 @@ package statistics import ( + "cmp" "fmt" "math" "strings" @@ -341,7 +342,7 @@ 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()) } @@ -349,7 +350,7 @@ func (t *Table) String() string { 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()) } diff --git a/store/copr/batch_coprocessor.go b/store/copr/batch_coprocessor.go index 3384eccfadaee..17f61e02e0dc8 100644 --- a/store/copr/batch_coprocessor.go +++ b/store/copr/batch_coprocessor.go @@ -16,6 +16,7 @@ package copr import ( "bytes" + "cmp" "context" "fmt" "io" @@ -207,13 +208,13 @@ func balanceBatchCopTaskWithContinuity(storeTaskMap map[uint64]*batchCopTask, ca storeTasks := deepCopyStoreTaskMap(storeTaskMap) // Sort regions by their key ranges. - slices.SortFunc(candidateRegionInfos, func(i, j RegionInfo) bool { + slices.SortFunc(candidateRegionInfos, func(i, j RegionInfo) int { // Special case: Sort empty ranges to the end. if i.Ranges.Len() < 1 || j.Ranges.Len() < 1 { - return i.Ranges.Len() > j.Ranges.Len() + return cmp.Compare(j.Ranges.Len(), i.Ranges.Len()) } // StartKey0 < StartKey1 - return bytes.Compare(i.Ranges.At(0).StartKey, j.Ranges.At(0).StartKey) == -1 + return bytes.Compare(i.Ranges.At(0).StartKey, j.Ranges.At(0).StartKey) }) balanceStart := time.Now() @@ -818,8 +819,8 @@ func (b *batchCopIterator) retryBatchCopTask(ctx context.Context, bo *backoff.Ba }) } // need to make sure the key ranges is sorted - slices.SortFunc(ranges, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(ranges, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) ret, err := buildBatchCopTasksForNonPartitionedTable(bo, b.store, NewKeyRanges(ranges), b.req.StoreType, false, 0, false, 0) return ret, err @@ -839,8 +840,8 @@ func (b *batchCopIterator) retryBatchCopTask(ctx context.Context, bo *backoff.Ba } } // need to make sure the key ranges is sorted - slices.SortFunc(ranges, func(i, j kv.KeyRange) bool { - return bytes.Compare(i.StartKey, j.StartKey) < 0 + slices.SortFunc(ranges, func(i, j kv.KeyRange) int { + return bytes.Compare(i.StartKey, j.StartKey) }) keyRanges = append(keyRanges, NewKeyRanges(ranges)) } diff --git a/store/gcworker/gc_worker.go b/store/gcworker/gc_worker.go index e9365d727777a..15f759d42ca9a 100644 --- a/store/gcworker/gc_worker.go +++ b/store/gcworker/gc_worker.go @@ -1234,8 +1234,8 @@ func (w *GCWorker) checkLockObservers(ctx context.Context, safePoint uint64, sto for i, lockInfo := range respInner.Locks { locks[i] = txnlock.NewLock(lockInfo) } - slices.SortFunc(locks, func(i, j *txnlock.Lock) bool { - return bytes.Compare(i.Key, j.Key) < 0 + slices.SortFunc(locks, func(i, j *txnlock.Lock) int { + return bytes.Compare(i.Key, j.Key) }) err = w.resolveLocksAcrossRegions(ctx, locks) diff --git a/store/mockstore/unistore/cophandler/analyze.go b/store/mockstore/unistore/cophandler/analyze.go index a04b158e4b4a6..3a1ef32414e56 100644 --- a/store/mockstore/unistore/cophandler/analyze.go +++ b/store/mockstore/unistore/cophandler/analyze.go @@ -112,14 +112,7 @@ func handleAnalyzeIndexReq(dbReader *dbreader.DBReader, rans []kv.KeyRange, anal if processor.topNCurValuePair.Count != 0 { processor.topNValuePairs = append(processor.topNValuePairs, processor.topNCurValuePair) } - slices.SortFunc(processor.topNValuePairs, func(i, j statistics.TopNMeta) bool { - if i.Count > j.Count { - return true - } else if i.Count < j.Count { - return false - } - return bytes.Compare(i.Encoded, j.Encoded) < 0 - }) + slices.SortFunc(processor.topNValuePairs, statistics.TopnMetaCompare) if len(processor.topNValuePairs) > int(processor.topNCount) { processor.topNValuePairs = processor.topNValuePairs[:processor.topNCount] } @@ -564,14 +557,7 @@ func handleAnalyzeMixedReq(dbReader *dbreader.DBReader, rans []kv.KeyRange, anal if e.topNCurValuePair.Count != 0 { e.topNValuePairs = append(e.topNValuePairs, e.topNCurValuePair) } - slices.SortFunc(e.topNValuePairs, func(i, j statistics.TopNMeta) bool { - if i.Count > j.Count { - return true - } else if i.Count < j.Count { - return false - } - return bytes.Compare(i.Encoded, j.Encoded) < 0 - }) + slices.SortFunc(e.topNValuePairs, statistics.TopnMetaCompare) if len(e.topNValuePairs) > int(e.topNCount) { e.topNValuePairs = e.topNValuePairs[:e.topNCount] } diff --git a/store/mockstore/unistore/tikv/mock_region.go b/store/mockstore/unistore/tikv/mock_region.go index 2e3e4fa01ddb1..670f2a20b6e76 100644 --- a/store/mockstore/unistore/tikv/mock_region.go +++ b/store/mockstore/unistore/tikv/mock_region.go @@ -401,8 +401,8 @@ func (rm *MockRegionManager) SplitRegion(req *kvrpcpb.SplitRegionRequest) *kvrpc for _, rawKey := range req.SplitKeys { splitKeys = append(splitKeys, codec.EncodeBytes(nil, rawKey)) } - slices.SortFunc(splitKeys, func(i, j []byte) bool { - return bytes.Compare(i, j) < 0 + slices.SortFunc(splitKeys, func(i, j []byte) int { + return bytes.Compare(i, j) }) newRegions, err := rm.splitKeys(splitKeys) diff --git a/store/mockstore/unistore/tikv/mvcc.go b/store/mockstore/unistore/tikv/mvcc.go index 8efd8f26ee75c..672a117ee24df 100644 --- a/store/mockstore/unistore/tikv/mvcc.go +++ b/store/mockstore/unistore/tikv/mvcc.go @@ -17,6 +17,7 @@ package tikv import ( "bufio" "bytes" + "cmp" "context" "fmt" "math" @@ -175,8 +176,8 @@ func (store *MVCCStore) getDBItems(reqCtx *requestCtx, mutations []*kvrpcpb.Muta } func sortMutations(mutations []*kvrpcpb.Mutation) []*kvrpcpb.Mutation { - fn := func(i, j *kvrpcpb.Mutation) bool { - return bytes.Compare(i.Key, j.Key) < 0 + fn := func(i, j *kvrpcpb.Mutation) int { + return bytes.Compare(i.Key, j.Key) } if slices.IsSortedFunc(mutations, fn) { return mutations @@ -215,13 +216,10 @@ func (sorter pessimisticPrewriteSorter) Swap(i, j int) { } func sortKeys(keys [][]byte) [][]byte { - less := func(i, j []byte) bool { - return bytes.Compare(i, j) < 0 - } - if slices.IsSortedFunc(keys, less) { + if slices.IsSortedFunc(keys, bytes.Compare) { return keys } - slices.SortFunc(keys, less) + slices.SortFunc(keys, bytes.Compare) return keys } @@ -1447,8 +1445,8 @@ func (store *MVCCStore) MvccGetByKey(reqCtx *requestCtx, key []byte) (*kvrpcpb.M if err != nil { return nil, err } - slices.SortFunc(mvccInfo.Writes, func(i, j *kvrpcpb.MvccWrite) bool { - return i.CommitTs > j.CommitTs + slices.SortFunc(mvccInfo.Writes, func(i, j *kvrpcpb.MvccWrite) int { + return cmp.Compare(j.CommitTs, i.CommitTs) }) mvccInfo.Values = make([]*kvrpcpb.MvccValue, len(mvccInfo.Writes)) for i := 0; i < len(mvccInfo.Writes); i++ { diff --git a/util/memoryusagealarm/memoryusagealarm.go b/util/memoryusagealarm/memoryusagealarm.go index d81316a0cd6ff..a7df61386548a 100644 --- a/util/memoryusagealarm/memoryusagealarm.go +++ b/util/memoryusagealarm/memoryusagealarm.go @@ -15,6 +15,7 @@ package memoryusagealarm import ( + "cmp" "fmt" "os" "path/filepath" @@ -302,14 +303,14 @@ func (record *memoryUsageAlarm) getTop10SqlInfo(cmp func(i, j *util.ProcessInfo) } func (record *memoryUsageAlarm) getTop10SqlInfoByMemoryUsage(pinfo []*util.ProcessInfo) strings.Builder { - return record.getTop10SqlInfo(func(i, j *util.ProcessInfo) bool { - return i.MemTracker.MaxConsumed() > j.MemTracker.MaxConsumed() + return record.getTop10SqlInfo(func(i, j *util.ProcessInfo) int { + return cmp.Compare(j.MemTracker.MaxConsumed(), i.MemTracker.MaxConsumed()) }, pinfo) } func (record *memoryUsageAlarm) getTop10SqlInfoByCostTime(pinfo []*util.ProcessInfo) strings.Builder { - return record.getTop10SqlInfo(func(i, j *util.ProcessInfo) bool { - return i.Time.Before(j.Time) + return record.getTop10SqlInfo(func(i, j *util.ProcessInfo) int { + return i.Time.Compare(j.Time) }, pinfo) } diff --git a/util/ranger/ranger.go b/util/ranger/ranger.go index ad83f68ebd258..bf43491544a07 100644 --- a/util/ranger/ranger.go +++ b/util/ranger/ranger.go @@ -587,8 +587,8 @@ func UnionRanges(sctx sessionctx.Context, ranges Ranges, mergeConsecutive bool) } objects = append(objects, &sortRange{originalValue: ran, encodedStart: left, encodedEnd: right}) } - slices.SortFunc(objects, func(i, j *sortRange) bool { - return bytes.Compare(i.encodedStart, j.encodedStart) < 0 + slices.SortFunc(objects, func(i, j *sortRange) int { + return bytes.Compare(i.encodedStart, j.encodedStart) }) ranges = ranges[:0] lastRange := objects[0]