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

*: use std/slices to replace exp/slices #46169

Closed
wants to merge 4 commits into from
Closed
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
1 change: 0 additions & 1 deletion domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ go_library(
"@org_golang_google_grpc//backoff",
"@org_golang_google_grpc//keepalive",
"@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 domain/schema_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package domain

import (
"slices"
"sync"
"time"

Expand All @@ -26,7 +27,6 @@ import (
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/txnkv/transaction"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

type checkResult int
Expand Down
8 changes: 4 additions & 4 deletions executor/mem_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package executor

import (
"context"
"slices"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/distsql"
Expand All @@ -33,7 +34,6 @@ import (
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/rowcodec"
"github.com/pingcap/tidb/util/tracing"
"golang.org/x/exp/slices"
)

type memReader interface {
Expand Down Expand Up @@ -143,7 +143,7 @@ func (m *memIndexReader) getMemRows(ctx context.Context) ([][]types.Datum, error
}

if m.keepOrder && m.table.GetPartitionInfo() != nil {
slices.SortFunc(m.addedRows, func(a, b []types.Datum) bool {
slices.SortFunc(m.addedRows, func(a, b []types.Datum) int {
ret, err1 := m.compare(m.ctx.GetSessionVars().StmtCtx, a, b)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to add some comments to m.compare to summarize the meaning of return values 😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better change the compare function

func (ce compareExec) compare(sctx *stmtctx.StatementContext, a, b []types.Datum) (ret bool, err error) {

if err1 != nil {
err = err1
Expand Down Expand Up @@ -421,7 +421,7 @@ func (m *memTableReader) getMemRows(ctx context.Context) ([][]types.Datum, error
}

if m.keepOrder && m.table.GetPartitionInfo() != nil {
slices.SortFunc(m.addedRows, func(a, b []types.Datum) bool {
slices.SortFunc(m.addedRows, func(a, b []types.Datum) int {
ret, err1 := m.compare(m.ctx.GetSessionVars().StmtCtx, a, b)
if err1 != nil {
err = err1
Expand Down Expand Up @@ -935,7 +935,7 @@ func (m *memIndexMergeReader) getMemRows(ctx context.Context) ([][]types.Datum,
// Didn't set keepOrder = true for memTblReader,
// In indexMerge, non-partitioned tables are also need reordered.
if m.keepOrder {
slices.SortFunc(rows, func(a, b []types.Datum) bool {
slices.SortFunc(rows, func(a, b []types.Datum) int {
ret, err1 := m.compare(m.ctx.GetSessionVars().StmtCtx, a, b)
if err1 != nil {
err = err1
Expand Down
7 changes: 4 additions & 3 deletions executor/show_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
package executor

import (
"cmp"
"context"
"fmt"
"slices"
"strings"

"github.com/pingcap/errors"
Expand All @@ -28,7 +30,6 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/collate"
"github.com/tikv/client-go/v2/oracle"
"golang.org/x/exp/slices"
)

func (e *ShowExec) fetchShowStatsExtended() error {
Expand Down Expand Up @@ -384,15 +385,15 @@ 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
}

func stableIdxsStats(idxStats map[int64]*statistics.Index) (idxs []*statistics.Index) {
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
}

Expand Down
15 changes: 8 additions & 7 deletions executor/union_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ func (us *UnionScanExec) getOneRow(ctx context.Context) ([]types.Datum, error) {
} else if snapshotRow == nil {
row = addedRow
} else {
isSnapshotRow, err = us.compare(us.Ctx().GetSessionVars().StmtCtx, snapshotRow, addedRow)
isSnapshotRowInt, err := us.compare(us.Ctx().GetSessionVars().StmtCtx, snapshotRow, addedRow)
isSnapshotRow = isSnapshotRowInt > 0
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -292,26 +293,26 @@ type compareExec struct {
handleCols plannercore.HandleCols
}

func (ce compareExec) compare(sctx *stmtctx.StatementContext, a, b []types.Datum) (ret bool, err error) {
func (ce compareExec) compare(sctx *stmtctx.StatementContext, a, b []types.Datum) (ret int, err error) {
var cmp int
for _, colOff := range ce.usedIndex {
aColumn := a[colOff]
bColumn := b[colOff]
cmp, err = aColumn.Compare(sctx, &bColumn, ce.collators[colOff])
if err != nil {
return false, err
return -1, err
}
if cmp == 0 {
continue
}
if cmp > 0 && !ce.desc || cmp < 0 && ce.desc {
return false, nil
return -1, nil
}
return true, nil
return 1, nil
}
cmp, err = ce.handleCols.Compare(a, b, ce.collators)
if cmp > 0 && !ce.desc || cmp < 0 && ce.desc {
return false, err
return -1, err
}
return true, err
return 1, err
}