diff --git a/pkg/ddl/backfilling_scheduler.go b/pkg/ddl/backfilling_scheduler.go index cda50fd6be8cc..eca0b9a7c71e8 100644 --- a/pkg/ddl/backfilling_scheduler.go +++ b/pkg/ddl/backfilling_scheduler.go @@ -37,7 +37,6 @@ import ( "github.com/pingcap/tidb/pkg/util/dbterror" "github.com/pingcap/tidb/pkg/util/intest" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" decoder "github.com/pingcap/tidb/pkg/util/rowDecoder" "go.uber.org/zap" ) @@ -175,7 +174,7 @@ func initSessCtx( func (*txnBackfillScheduler) expectedWorkerSize() (size int) { workerCnt := int(variable.GetDDLReorgWorkerCounter()) - return mathutil.Min(workerCnt, maxBackfillWorkerSize) + return min(workerCnt, maxBackfillWorkerSize) } func (b *txnBackfillScheduler) currentWorkerSize() int { @@ -465,9 +464,9 @@ func (*ingestBackfillScheduler) expectedWorkerSize() (readerSize int, writerSize func expectedIngestWorkerCnt() (readerCnt, writerCnt int) { workerCnt := int(variable.GetDDLReorgWorkerCounter()) - readerCnt = mathutil.Min(workerCnt/2, maxBackfillWorkerSize) - readerCnt = mathutil.Max(readerCnt, 1) - writerCnt = mathutil.Min(workerCnt/2+2, maxBackfillWorkerSize) + readerCnt = min(workerCnt/2, maxBackfillWorkerSize) + readerCnt = max(readerCnt, 1) + writerCnt = min(workerCnt/2+2, maxBackfillWorkerSize) return readerCnt, writerCnt } diff --git a/pkg/ddl/partition.go b/pkg/ddl/partition.go index ac141e49054ba..721d257c03798 100644 --- a/pkg/ddl/partition.go +++ b/pkg/ddl/partition.go @@ -866,7 +866,7 @@ func getLowerBoundInt(partCols ...*model.ColumnInfo) int64 { if mysql.HasUnsignedFlag(col.FieldType.GetFlag()) { return 0 } - ret = mathutil.Min(ret, types.IntergerSignedLowerBound(col.GetType())) + ret = min(ret, types.IntergerSignedLowerBound(col.GetType())) } return ret } diff --git a/pkg/ddl/sequence.go b/pkg/ddl/sequence.go index 9772322d90f06..e60043be6efe1 100644 --- a/pkg/ddl/sequence.go +++ b/pkg/ddl/sequence.go @@ -132,7 +132,7 @@ func handleSequenceOptions(seqOptions []*ast.SequenceOption, sequenceInfo *model sequenceInfo.MaxValue = model.DefaultNegativeSequenceMaxValue } if !startSetFlag { - sequenceInfo.Start = mathutil.Min(sequenceInfo.MaxValue, model.DefaultNegativeSequenceStartValue) + sequenceInfo.Start = min(sequenceInfo.MaxValue, model.DefaultNegativeSequenceStartValue) } if !minSetFlag { sequenceInfo.MinValue = model.DefaultNegativeSequenceMinValue diff --git a/pkg/distsql/BUILD.bazel b/pkg/distsql/BUILD.bazel index e6acd81c960b6..64a0f10eb10e7 100644 --- a/pkg/distsql/BUILD.bazel +++ b/pkg/distsql/BUILD.bazel @@ -83,7 +83,6 @@ go_test( "//pkg/util/collate", "//pkg/util/disk", "//pkg/util/execdetails", - "//pkg/util/mathutil", "//pkg/util/memory", "//pkg/util/mock", "//pkg/util/paging", diff --git a/pkg/distsql/distsql_test.go b/pkg/distsql/distsql_test.go index b49a99accd2f6..461b29285d11d 100644 --- a/pkg/distsql/distsql_test.go +++ b/pkg/distsql/distsql_test.go @@ -31,7 +31,6 @@ import ( "github.com/pingcap/tidb/pkg/util/codec" "github.com/pingcap/tidb/pkg/util/disk" "github.com/pingcap/tidb/pkg/util/execdetails" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/memory" "github.com/pingcap/tidb/pkg/util/mock" "github.com/pingcap/tipb/go-tipb" @@ -228,7 +227,7 @@ func (resp *mockResponse) Next(context.Context) (kv.ResultSubset, error) { if resp.count >= resp.total { return nil, nil } - numRows := mathutil.Min(resp.batch, resp.total-resp.count) + numRows := min(resp.batch, resp.total-resp.count) resp.count += numRows var chunks []tipb.Chunk @@ -245,7 +244,7 @@ func (resp *mockResponse) Next(context.Context) (kv.ResultSubset, error) { } else { chunks = make([]tipb.Chunk, 0) for numRows > 0 { - rows := mathutil.Min(numRows, 1024) + rows := min(numRows, 1024) numRows -= rows colTypes := make([]*types.FieldType, 4) diff --git a/pkg/infoschema/BUILD.bazel b/pkg/infoschema/BUILD.bazel index a1984931d77b8..0e62ee3953ca7 100644 --- a/pkg/infoschema/BUILD.bazel +++ b/pkg/infoschema/BUILD.bazel @@ -42,7 +42,6 @@ go_library( "//pkg/util/domainutil", "//pkg/util/execdetails", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/mock", "//pkg/util/pdapi", "//pkg/util/sem", diff --git a/pkg/infoschema/builder.go b/pkg/infoschema/builder.go index 3b030b5b1ad25..54f8d8a85dc58 100644 --- a/pkg/infoschema/builder.go +++ b/pkg/infoschema/builder.go @@ -35,7 +35,6 @@ import ( "github.com/pingcap/tidb/pkg/table/tables" "github.com/pingcap/tidb/pkg/util/domainutil" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/sqlexec" "go.uber.org/zap" ) @@ -420,9 +419,9 @@ func updateAutoIDForExchangePartition(store kv.Storage, ptSchemaID, ptID, ntSche // Set both tables to the maximum auto IDs between normal table and partitioned table. newAutoIDs := meta.AutoIDGroup{ - RowID: mathutil.Max(ptAutoIDs.RowID, ntAutoIDs.RowID), - IncrementID: mathutil.Max(ptAutoIDs.IncrementID, ntAutoIDs.IncrementID), - RandomID: mathutil.Max(ptAutoIDs.RandomID, ntAutoIDs.RandomID), + RowID: max(ptAutoIDs.RowID, ntAutoIDs.RowID), + IncrementID: max(ptAutoIDs.IncrementID, ntAutoIDs.IncrementID), + RandomID: max(ptAutoIDs.RandomID, ntAutoIDs.RandomID), } err = t.GetAutoIDAccessors(ptSchemaID, ptID).Put(newAutoIDs) if err != nil { diff --git a/pkg/meta/autoid/BUILD.bazel b/pkg/meta/autoid/BUILD.bazel index 107f9f46cf768..523258d50b831 100644 --- a/pkg/meta/autoid/BUILD.bazel +++ b/pkg/meta/autoid/BUILD.bazel @@ -24,7 +24,6 @@ go_library( "//pkg/util/etcd", "//pkg/util/execdetails", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/tracing", "@com_github_pingcap_errors//:errors", "@com_github_pingcap_failpoint//:failpoint", diff --git a/pkg/meta/autoid/autoid.go b/pkg/meta/autoid/autoid.go index 0555868a52cb7..6a3d9f94bc27d 100644 --- a/pkg/meta/autoid/autoid.go +++ b/pkg/meta/autoid/autoid.go @@ -37,7 +37,6 @@ import ( "github.com/pingcap/tidb/pkg/util/etcd" "github.com/pingcap/tidb/pkg/util/execdetails" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/tracing" "github.com/tikv/client-go/v2/txnkv/txnsnapshot" tikvutil "github.com/tikv/client-go/v2/util" @@ -353,8 +352,8 @@ func (alloc *allocator) rebase4Unsigned(ctx context.Context, requiredBase uint64 } uCurrentEnd := uint64(currentEnd) if allocIDs { - newBase = mathutil.Max(uCurrentEnd, requiredBase) - newEnd = mathutil.Min(math.MaxUint64-uint64(alloc.step), newBase) + uint64(alloc.step) + newBase = max(uCurrentEnd, requiredBase) + newEnd = min(math.MaxUint64-uint64(alloc.step), newBase) + uint64(alloc.step) } else { if uCurrentEnd >= requiredBase { newBase = uCurrentEnd @@ -412,8 +411,8 @@ func (alloc *allocator) rebase4Signed(ctx context.Context, requiredBase int64, a return err1 } if allocIDs { - newBase = mathutil.Max(currentEnd, requiredBase) - newEnd = mathutil.Min(math.MaxInt64-alloc.step, newBase) + alloc.step + newBase = max(currentEnd, requiredBase) + newEnd = min(math.MaxInt64-alloc.step, newBase) + alloc.step } else { if currentEnd >= requiredBase { newBase = currentEnd @@ -872,7 +871,7 @@ func SeekToFirstAutoIDUnSigned(base, increment, offset uint64) uint64 { return nr } -func (alloc *allocator) alloc4Signed(ctx context.Context, n uint64, increment, offset int64) (min int64, max int64, err error) { +func (alloc *allocator) alloc4Signed(ctx context.Context, n uint64, increment, offset int64) (mini int64, max int64, err error) { // Check offset rebase if necessary. if offset-1 > alloc.base { if err := alloc.rebase4Signed(ctx, offset-1, true); err != nil { @@ -926,7 +925,7 @@ func (alloc *allocator) alloc4Signed(ctx context.Context, n uint64, increment, o if nextStep < n1 { nextStep = n1 } - tmpStep := mathutil.Min(math.MaxInt64-newBase, nextStep) + tmpStep := min(math.MaxInt64-newBase, nextStep) // The global rest is not enough for alloc. if tmpStep < n1 { return ErrAutoincReadFailed @@ -953,12 +952,12 @@ func (alloc *allocator) alloc4Signed(ctx context.Context, n uint64, increment, o zap.Uint64("to ID", uint64(alloc.base+n1)), zap.Int64("table ID", alloc.tbID), zap.Int64("database ID", alloc.dbID)) - min = alloc.base + mini = alloc.base alloc.base += n1 - return min, alloc.base, nil + return mini, alloc.base, nil } -func (alloc *allocator) alloc4Unsigned(ctx context.Context, n uint64, increment, offset int64) (min int64, max int64, err error) { +func (alloc *allocator) alloc4Unsigned(ctx context.Context, n uint64, increment, offset int64) (mini int64, max int64, err error) { // Check offset rebase if necessary. if uint64(offset-1) > uint64(alloc.base) { if err := alloc.rebase4Unsigned(ctx, uint64(offset-1), true); err != nil { @@ -1017,7 +1016,7 @@ func (alloc *allocator) alloc4Unsigned(ctx context.Context, n uint64, increment, if nextStep < n1 { nextStep = n1 } - tmpStep := int64(mathutil.Min(math.MaxUint64-uint64(newBase), uint64(nextStep))) + tmpStep := int64(min(math.MaxUint64-uint64(newBase), uint64(nextStep))) // The global rest is not enough for alloc. if tmpStep < n1 { return ErrAutoincReadFailed @@ -1044,10 +1043,10 @@ func (alloc *allocator) alloc4Unsigned(ctx context.Context, n uint64, increment, zap.Uint64("to ID", uint64(alloc.base+n1)), zap.Int64("table ID", alloc.tbID), zap.Int64("database ID", alloc.dbID)) - min = alloc.base + mini = alloc.base // Use uint64 n directly. alloc.base = int64(uint64(alloc.base) + uint64(n1)) - return min, alloc.base, nil + return mini, alloc.base, nil } func getAllocatorStatsFromCtx(ctx context.Context) (context.Context, *AllocatorRuntimeStats, **tikvutil.CommitDetails) { diff --git a/pkg/metrics/BUILD.bazel b/pkg/metrics/BUILD.bazel index d302f1bbd7ea4..135275718bd93 100644 --- a/pkg/metrics/BUILD.bazel +++ b/pkg/metrics/BUILD.bazel @@ -35,7 +35,6 @@ go_library( "//pkg/parser/terror", "//pkg/timer/metrics", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/promutil", "@com_github_pingcap_errors//:errors", "@com_github_prometheus_client_golang//prometheus", diff --git a/pkg/metrics/telemetry.go b/pkg/metrics/telemetry.go index 0cb6439053eec..ea07b9b83e520 100644 --- a/pkg/metrics/telemetry.go +++ b/pkg/metrics/telemetry.go @@ -15,7 +15,6 @@ package metrics import ( - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" ) @@ -402,7 +401,7 @@ func (c TablePartitionUsageCounter) Cal(rhs TablePartitionUsageCounter) TablePar TablePartitionRangeColumnsGt2Cnt: c.TablePartitionRangeColumnsGt2Cnt - rhs.TablePartitionRangeColumnsGt2Cnt, TablePartitionRangeColumnsGt3Cnt: c.TablePartitionRangeColumnsGt3Cnt - rhs.TablePartitionRangeColumnsGt3Cnt, TablePartitionListColumnsCnt: c.TablePartitionListColumnsCnt - rhs.TablePartitionListColumnsCnt, - TablePartitionMaxPartitionsCnt: mathutil.Max(c.TablePartitionMaxPartitionsCnt-rhs.TablePartitionMaxPartitionsCnt, rhs.TablePartitionMaxPartitionsCnt), + TablePartitionMaxPartitionsCnt: max(c.TablePartitionMaxPartitionsCnt-rhs.TablePartitionMaxPartitionsCnt, rhs.TablePartitionMaxPartitionsCnt), TablePartitionCreateIntervalPartitionsCnt: c.TablePartitionCreateIntervalPartitionsCnt - rhs.TablePartitionCreateIntervalPartitionsCnt, TablePartitionAddIntervalPartitionsCnt: c.TablePartitionAddIntervalPartitionsCnt - rhs.TablePartitionAddIntervalPartitionsCnt, TablePartitionDropIntervalPartitionsCnt: c.TablePartitionDropIntervalPartitionsCnt - rhs.TablePartitionDropIntervalPartitionsCnt, @@ -423,7 +422,7 @@ func ResetTablePartitionCounter(pre TablePartitionUsageCounter) TablePartitionUs TablePartitionRangeColumnsGt2Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt2Cnt), TablePartitionRangeColumnsGt3Cnt: readCounter(TelemetryTablePartitionRangeColumnsGt3Cnt), TablePartitionListColumnsCnt: readCounter(TelemetryTablePartitionListColumnsCnt), - TablePartitionMaxPartitionsCnt: mathutil.Max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsCnt, pre.TablePartitionMaxPartitionsCnt), + TablePartitionMaxPartitionsCnt: max(readCounter(TelemetryTablePartitionMaxPartitionsCnt)-pre.TablePartitionMaxPartitionsCnt, pre.TablePartitionMaxPartitionsCnt), TablePartitionReorganizePartitionCnt: readCounter(TelemetryReorganizePartitionCnt), } } diff --git a/pkg/privilege/privileges/privileges.go b/pkg/privilege/privileges/privileges.go index d394bacdb69ae..1fe786399f0dd 100644 --- a/pkg/privilege/privileges/privileges.go +++ b/pkg/privilege/privileges/privileges.go @@ -984,7 +984,7 @@ func (passwordLocking *PasswordLocking) ParseJSON(passwordLockingJSON types.Bina if err != nil { return err } - passwordLocking.FailedLoginAttempts = mathutil.Min(passwordLocking.FailedLoginAttempts, math.MaxInt16) + passwordLocking.FailedLoginAttempts = min(passwordLocking.FailedLoginAttempts, math.MaxInt16) passwordLocking.FailedLoginAttempts = mathutil.Max(passwordLocking.FailedLoginAttempts, 0) passwordLocking.PasswordLockTimeDays, err = @@ -992,7 +992,7 @@ func (passwordLocking *PasswordLocking) ParseJSON(passwordLockingJSON types.Bina if err != nil { return err } - passwordLocking.PasswordLockTimeDays = mathutil.Min(passwordLocking.PasswordLockTimeDays, math.MaxInt16) + passwordLocking.PasswordLockTimeDays = min(passwordLocking.PasswordLockTimeDays, math.MaxInt16) passwordLocking.PasswordLockTimeDays = mathutil.Max(passwordLocking.PasswordLockTimeDays, -1) passwordLocking.FailedLoginCount, err = diff --git a/pkg/resourcemanager/pool/spool/BUILD.bazel b/pkg/resourcemanager/pool/spool/BUILD.bazel index 03bec05e729c0..6fa13aa8492ad 100644 --- a/pkg/resourcemanager/pool/spool/BUILD.bazel +++ b/pkg/resourcemanager/pool/spool/BUILD.bazel @@ -15,7 +15,6 @@ go_library( "//pkg/resourcemanager/poolmanager", "//pkg/resourcemanager/util", "//pkg/util/logutil", - "//pkg/util/mathutil", "@com_github_prometheus_client_golang//prometheus", "@com_github_sasha_s_go_deadlock//:go-deadlock", "@org_uber_go_zap//:zap", diff --git a/pkg/resourcemanager/pool/spool/spool.go b/pkg/resourcemanager/pool/spool/spool.go index 0982d1f85893f..699860de5db54 100644 --- a/pkg/resourcemanager/pool/spool/spool.go +++ b/pkg/resourcemanager/pool/spool/spool.go @@ -25,7 +25,6 @@ import ( "github.com/pingcap/tidb/pkg/resourcemanager/poolmanager" "github.com/pingcap/tidb/pkg/resourcemanager/util" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/prometheus/client_golang/prometheus" "github.com/sasha-s/go-deadlock" "go.uber.org/zap" @@ -197,7 +196,7 @@ func (p *Pool) checkAndAddRunningInternal(concurrency int32) (conc int32, run bo } // if concurrency is 1 , we must return a goroutine // if concurrency is more than 1, we must return at least one goroutine. - result := mathutil.Min(n, concurrency) + result := min(n, concurrency) p.running.Add(result) return result, true } diff --git a/pkg/session/BUILD.bazel b/pkg/session/BUILD.bazel index 2454f7028edfb..d653018239d85 100644 --- a/pkg/session/BUILD.bazel +++ b/pkg/session/BUILD.bazel @@ -85,7 +85,6 @@ go_library( "//pkg/util/kvcache", "//pkg/util/logutil", "//pkg/util/logutil/consistency", - "//pkg/util/mathutil", "//pkg/util/memory", "//pkg/util/parser", "//pkg/util/sem", diff --git a/pkg/session/nontransactional.go b/pkg/session/nontransactional.go index 05cedbb096f34..b9f150529ce39 100644 --- a/pkg/session/nontransactional.go +++ b/pkg/session/nontransactional.go @@ -40,7 +40,6 @@ import ( "github.com/pingcap/tidb/pkg/util/collate" "github.com/pingcap/tidb/pkg/util/dbterror" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/memory" "github.com/pingcap/tidb/pkg/util/sqlexec" "go.uber.org/zap" @@ -850,5 +849,5 @@ func buildExecuteResults(ctx context.Context, jobs []job, maxChunkSize int, reda zap.Int("num_failed_jobs", len(failedJobs)), zap.String("failed_jobs", errStr)) return nil, fmt.Errorf("%d/%d jobs failed in the non-transactional DML: %s, ...(more in logs)", - len(failedJobs), len(jobs), errStr[:mathutil.Min(500, len(errStr)-1)]) + len(failedJobs), len(jobs), errStr[:min(500, len(errStr)-1)]) } diff --git a/pkg/session/session.go b/pkg/session/session.go index 4fc30d8786929..45c9673b862c0 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -94,7 +94,6 @@ import ( "github.com/pingcap/tidb/pkg/util/kvcache" "github.com/pingcap/tidb/pkg/util/logutil" "github.com/pingcap/tidb/pkg/util/logutil/consistency" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/memory" "github.com/pingcap/tidb/pkg/util/sem" "github.com/pingcap/tidb/pkg/util/sli" @@ -1742,7 +1741,7 @@ func (s *session) ParseWithParams(ctx context.Context, sql string, args ...inter } if err != nil { s.rollbackOnError(ctx) - logSQL := sql[:mathutil.Min(500, len(sql))] + logSQL := sql[:min(500, len(sql))] if s.sessionVars.EnableRedactLog { logutil.Logger(ctx).Debug("parse SQL failed", zap.Error(err), zap.String("SQL", logSQL)) } else { diff --git a/pkg/store/copr/BUILD.bazel b/pkg/store/copr/BUILD.bazel index 9ad1a7250ccac..673cbffce8ade 100644 --- a/pkg/store/copr/BUILD.bazel +++ b/pkg/store/copr/BUILD.bazel @@ -33,7 +33,6 @@ go_library( "//pkg/util/execdetails", "//pkg/util/intest", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/memory", "//pkg/util/paging", "//pkg/util/tiflash", diff --git a/pkg/store/copr/coprocessor.go b/pkg/store/copr/coprocessor.go index 3b3456be0f8e7..8f5f55444897c 100644 --- a/pkg/store/copr/coprocessor.go +++ b/pkg/store/copr/coprocessor.go @@ -48,7 +48,6 @@ import ( util2 "github.com/pingcap/tidb/pkg/util" "github.com/pingcap/tidb/pkg/util/execdetails" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/memory" "github.com/pingcap/tidb/pkg/util/paging" "github.com/pingcap/tidb/pkg/util/tracing" @@ -377,7 +376,7 @@ func buildCopTasks(bo *Backoffer, ranges *KeyRanges, opt *buildCopTaskOpt) ([]*c pagingSize = req.Paging.MinPagingSize } for i := 0; i < rLen; { - nextI := mathutil.Min(i+rangesPerTaskLimit, rLen) + nextI := min(i+rangesPerTaskLimit, rLen) hint := -1 // calculate the row count hint if hints != nil { diff --git a/pkg/store/copr/mpp.go b/pkg/store/copr/mpp.go index cd0695a3e0d9d..8998a570f67d6 100644 --- a/pkg/store/copr/mpp.go +++ b/pkg/store/copr/mpp.go @@ -31,7 +31,6 @@ import ( "github.com/pingcap/tidb/pkg/store/driver/backoff" "github.com/pingcap/tidb/pkg/util" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/pingcap/tidb/pkg/util/tiflash" "github.com/pingcap/tidb/pkg/util/tiflashcompute" "github.com/tikv/client-go/v2/tikv" @@ -174,7 +173,7 @@ func (c *MPPClient) DispatchMPPTask(param kv.DispatchMPPTaskParam) (resp *mpp.Di } if len(realResp.RetryRegions) > 0 { - logutil.BgLogger().Info("TiFlash found " + strconv.Itoa(len(realResp.RetryRegions)) + " stale regions. Only first " + strconv.Itoa(mathutil.Min(10, len(realResp.RetryRegions))) + " regions will be logged if the log level is higher than Debug") + logutil.BgLogger().Info("TiFlash found " + strconv.Itoa(len(realResp.RetryRegions)) + " stale regions. Only first " + strconv.Itoa(min(10, len(realResp.RetryRegions))) + " regions will be logged if the log level is higher than Debug") for index, retry := range realResp.RetryRegions { id := tikv.NewRegionVerID(retry.Id, retry.RegionEpoch.ConfVer, retry.RegionEpoch.Version) if index < 10 || log.GetLevel() <= zap.DebugLevel { diff --git a/pkg/store/copr/region_cache.go b/pkg/store/copr/region_cache.go index 14ee9fa8357b6..cf962d9abcd96 100644 --- a/pkg/store/copr/region_cache.go +++ b/pkg/store/copr/region_cache.go @@ -27,7 +27,6 @@ import ( derr "github.com/pingcap/tidb/pkg/store/driver/error" "github.com/pingcap/tidb/pkg/store/driver/options" "github.com/pingcap/tidb/pkg/util/logutil" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/tikv/client-go/v2/metrics" "github.com/tikv/client-go/v2/tikv" "go.uber.org/zap" @@ -202,7 +201,7 @@ func (c *RegionCache) OnSendFailForBatchRegions(bo *Backoffer, store *tikv.Store logutil.Logger(bo.GetCtx()).Info("Should not reach here, OnSendFailForBatchRegions only support TiFlash") return } - logutil.Logger(bo.GetCtx()).Info("Send fail for " + strconv.Itoa(len(regionInfos)) + " regions, will switch region peer for these regions. Only first " + strconv.Itoa(mathutil.Min(10, len(regionInfos))) + " regions will be logged if the log level is higher than Debug") + logutil.Logger(bo.GetCtx()).Info("Send fail for " + strconv.Itoa(len(regionInfos)) + " regions, will switch region peer for these regions. Only first " + strconv.Itoa(min(10, len(regionInfos))) + " regions will be logged if the log level is higher than Debug") for index, ri := range regionInfos { if ri.Meta == nil { continue diff --git a/pkg/store/mockstore/unistore/tikv/BUILD.bazel b/pkg/store/mockstore/unistore/tikv/BUILD.bazel index 793f41ef45357..978b52db23886 100644 --- a/pkg/store/mockstore/unistore/tikv/BUILD.bazel +++ b/pkg/store/mockstore/unistore/tikv/BUILD.bazel @@ -33,7 +33,6 @@ go_library( "//pkg/tablecodec", "//pkg/types", "//pkg/util/codec", - "//pkg/util/mathutil", "//pkg/util/rowcodec", "@com_github_dgryski_go_farm//:go-farm", "@com_github_gogo_protobuf//proto", diff --git a/pkg/store/mockstore/unistore/tikv/write.go b/pkg/store/mockstore/unistore/tikv/write.go index 0d40dd4bb1c80..722eb6fa870d8 100644 --- a/pkg/store/mockstore/unistore/tikv/write.go +++ b/pkg/store/mockstore/unistore/tikv/write.go @@ -27,7 +27,6 @@ import ( "github.com/pingcap/tidb/pkg/store/mockstore/unistore/lockstore" "github.com/pingcap/tidb/pkg/store/mockstore/unistore/tikv/dbreader" "github.com/pingcap/tidb/pkg/store/mockstore/unistore/tikv/mvcc" - "github.com/pingcap/tidb/pkg/util/mathutil" "go.uber.org/zap" ) @@ -332,7 +331,7 @@ func (writer *dbWriter) collectRangeKeys(it *badger.Iterator, startKey, endKey [ func (writer *dbWriter) deleteKeysInBatch(latchHandle mvcc.LatchHandle, keys []y.Key, batchSize int) error { for len(keys) > 0 { - batchSize := mathutil.Min(len(keys), batchSize) + batchSize := min(len(keys), batchSize) batchKeys := keys[:batchSize] keys = keys[batchSize:] hashVals := userKeysToHashVals(batchKeys...) diff --git a/pkg/testkit/testenv/BUILD.bazel b/pkg/testkit/testenv/BUILD.bazel index 970c503ebb732..abf9ab5e003f5 100644 --- a/pkg/testkit/testenv/BUILD.bazel +++ b/pkg/testkit/testenv/BUILD.bazel @@ -5,5 +5,4 @@ go_library( srcs = ["testenv.go"], importpath = "github.com/pingcap/tidb/pkg/testkit/testenv", visibility = ["//visibility:public"], - deps = ["//pkg/util/mathutil"], ) diff --git a/pkg/testkit/testenv/testenv.go b/pkg/testkit/testenv/testenv.go index f75668fd739cf..e0d2da4e856fb 100644 --- a/pkg/testkit/testenv/testenv.go +++ b/pkg/testkit/testenv/testenv.go @@ -16,11 +16,9 @@ package testenv import ( "runtime" - - "github.com/pingcap/tidb/pkg/util/mathutil" ) // SetGOMAXPROCSForTest sets GOMAXPROCS to 16 if it is greater than 16. func SetGOMAXPROCSForTest() { - runtime.GOMAXPROCS(mathutil.Min(16, runtime.GOMAXPROCS(0))) + runtime.GOMAXPROCS(min(16, runtime.GOMAXPROCS(0))) } diff --git a/pkg/ttl/cache/BUILD.bazel b/pkg/ttl/cache/BUILD.bazel index 839c53f1822b2..a9e6b97887d9f 100644 --- a/pkg/ttl/cache/BUILD.bazel +++ b/pkg/ttl/cache/BUILD.bazel @@ -26,7 +26,6 @@ go_library( "//pkg/util/chunk", "//pkg/util/codec", "//pkg/util/logutil", - "//pkg/util/mathutil", "@com_github_pingcap_errors//:errors", "@com_github_tikv_client_go_v2//tikv", "@org_uber_go_zap//:zap", diff --git a/pkg/ttl/cache/table.go b/pkg/ttl/cache/table.go index 1e69faef9d34b..8be33494900b0 100644 --- a/pkg/ttl/cache/table.go +++ b/pkg/ttl/cache/table.go @@ -33,7 +33,6 @@ import ( "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/codec" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/tikv/client-go/v2/tikv" ) @@ -341,7 +340,7 @@ func (t *PhysicalTable) splitRawKeyRanges(ctx context.Context, store tikv.Storag regionsPerRange := len(regionIDs) / splitCnt oversizeCnt := len(regionIDs) % splitCnt - ranges := make([]kv.KeyRange, 0, mathutil.Min(len(regionIDs), splitCnt)) + ranges := make([]kv.KeyRange, 0, min(len(regionIDs), splitCnt)) for len(regionIDs) > 0 { startRegion, err := regionCache.LocateRegionByID(tikv.NewBackofferWithVars(ctx, 20000, nil), regionIDs[0]) diff --git a/pkg/types/datum_eval.go b/pkg/types/datum_eval.go index cb3c0a87148ed..204a873e0e0ad 100644 --- a/pkg/types/datum_eval.go +++ b/pkg/types/datum_eval.go @@ -17,7 +17,6 @@ package types import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/parser/opcode" - "github.com/pingcap/tidb/pkg/util/mathutil" ) // ComputePlus computes the result of a+b. @@ -56,7 +55,7 @@ func ComputePlus(a, b Datum) (d Datum, err error) { r := new(MyDecimal) err = DecimalAdd(a.GetMysqlDecimal(), b.GetMysqlDecimal(), r) d.SetMysqlDecimal(r) - d.SetFrac(mathutil.Max(a.Frac(), b.Frac())) + d.SetFrac(max(a.Frac(), b.Frac())) return d, err } } diff --git a/pkg/types/mydecimal.go b/pkg/types/mydecimal.go index baca38fef4443..f2127bf4fbfe2 100644 --- a/pkg/types/mydecimal.go +++ b/pkg/types/mydecimal.go @@ -24,7 +24,6 @@ import ( "github.com/pingcap/log" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/parser/terror" - "github.com/pingcap/tidb/pkg/util/mathutil" "go.uber.org/zap" ) @@ -354,7 +353,7 @@ func (d *MyDecimal) ToString() (str []byte) { for ; digitsFrac > 0; digitsFrac -= digitsPerWord { x := d.wordBuf[wordIdx] wordIdx++ - for i := mathutil.Min(digitsFrac, digitsPerWord); i > 0; i-- { + for i := min(digitsFrac, digitsPerWord); i > 0; i-- { y := x / digMask str[fracIdx] = byte(y) + '0' fracIdx++ @@ -381,7 +380,7 @@ func (d *MyDecimal) ToString() (str []byte) { for ; digitsInt > 0; digitsInt -= digitsPerWord { wordIdx-- x := d.wordBuf[wordIdx] - for i := mathutil.Min(digitsInt, digitsPerWord); i > 0; i-- { + for i := min(digitsInt, digitsPerWord); i > 0; i-- { y := x / 10 strIdx-- str[strIdx] = '0' + byte(x-y*10) @@ -841,7 +840,7 @@ func (d *MyDecimal) Round(to *MyDecimal, frac int, roundMode RoundMode) (err err if to != d { copy(to.wordBuf[:], d.wordBuf[:]) to.negative = d.negative - to.digitsInt = int8(mathutil.Min(wordsInt, wordBufLen) * digitsPerWord) + to.digitsInt = int8(min(wordsInt, wordBufLen) * digitsPerWord) } if wordsFracTo > wordsFrac { idx := wordsInt + wordsFrac @@ -942,7 +941,7 @@ func (d *MyDecimal) Round(to *MyDecimal, frac int, roundMode RoundMode) (err err frac = wordsFracTo * digitsPerWord err = ErrTruncated } - for toIdx = wordsInt + mathutil.Max(wordsFracTo, 0); toIdx > 0; toIdx-- { + for toIdx = wordsInt + max(wordsFracTo, 0); toIdx > 0; toIdx-- { if toIdx < wordBufLen { to.wordBuf[toIdx] = to.wordBuf[toIdx-1] } else { @@ -966,7 +965,7 @@ func (d *MyDecimal) Round(to *MyDecimal, frac int, roundMode RoundMode) (err err /* making 'zero' with the proper scale */ idx := wordsFracTo + 1 to.digitsInt = 1 - to.digitsFrac = int8(mathutil.Max(frac, 0)) + to.digitsFrac = int8(max(frac, 0)) to.negative = false for toIdx < idx { to.wordBuf[toIdx] = 0 @@ -1603,7 +1602,7 @@ func DecimalNeg(from *MyDecimal) *MyDecimal { // of `to` may be changed during evaluating. func DecimalAdd(from1, from2, to *MyDecimal) error { from1, from2, to = validateArgs(from1, from2, to) - to.resultFrac = mathutil.Max(from1.resultFrac, from2.resultFrac) + to.resultFrac = max(from1.resultFrac, from2.resultFrac) if from1.negative == from2.negative { return doAdd(from1, from2, to) } @@ -1614,7 +1613,7 @@ func DecimalAdd(from1, from2, to *MyDecimal) error { // DecimalSub subs one decimal from another, sets the result to 'to'. func DecimalSub(from1, from2, to *MyDecimal) error { from1, from2, to = validateArgs(from1, from2, to) - to.resultFrac = mathutil.Max(from1.resultFrac, from2.resultFrac) + to.resultFrac = max(from1.resultFrac, from2.resultFrac) if from1.negative == from2.negative { _, err := doSub(from1, from2, to) return err @@ -1650,7 +1649,7 @@ func doSub(from1, from2, to *MyDecimal) (cmp int, err error) { wordsFrac1 = digitsToWords(int(from1.digitsFrac)) wordsInt2 = digitsToWords(int(from2.digitsInt)) wordsFrac2 = digitsToWords(int(from2.digitsFrac)) - wordsFracTo = mathutil.Max(wordsFrac1, wordsFrac2) + wordsFracTo = max(wordsFrac1, wordsFrac2) start1 = 0 stop1 = wordsInt1 @@ -1815,8 +1814,8 @@ func doAdd(from1, from2, to *MyDecimal) error { wordsFrac1 = digitsToWords(int(from1.digitsFrac)) wordsInt2 = digitsToWords(int(from2.digitsInt)) wordsFrac2 = digitsToWords(int(from2.digitsFrac)) - wordsIntTo = mathutil.Max(wordsInt1, wordsInt2) - wordsFracTo = mathutil.Max(wordsFrac1, wordsFrac2) + wordsIntTo = max(wordsInt1, wordsInt2) + wordsFracTo = max(wordsFrac1, wordsFrac2) ) var x int32 @@ -1840,7 +1839,7 @@ func doAdd(from1, from2, to *MyDecimal) error { idxTo := wordsIntTo + wordsFracTo to.negative = from1.negative to.digitsInt = int8(wordsIntTo * digitsPerWord) - to.digitsFrac = mathutil.Max(from1.digitsFrac, from2.digitsFrac) + to.digitsFrac = max(from1.digitsFrac, from2.digitsFrac) if err != nil { if to.digitsFrac > int8(wordsFracTo*digitsPerWord) { @@ -1978,7 +1977,7 @@ func DecimalMul(from1, from2, to *MyDecimal) error { tmp1 = wordsIntTo tmp2 = wordsFracTo ) - to.resultFrac = mathutil.Min(from1.resultFrac+from2.resultFrac, mysql.MaxDecimalScale) + to.resultFrac = min(from1.resultFrac+from2.resultFrac, mysql.MaxDecimalScale) wordsIntTo, wordsFracTo, err = fixWordCntError(wordsIntTo, wordsFracTo) to.negative = from1.negative != from2.negative to.digitsFrac = from1.digitsFrac + from2.digitsFrac @@ -2093,7 +2092,7 @@ func DecimalMul(from1, from2, to *MyDecimal) error { // fracIncr - increment of fraction func DecimalDiv(from1, from2, to *MyDecimal, fracIncr int) error { from1, from2, to = validateArgs(from1, from2, to) - to.resultFrac = mathutil.Min(from1.resultFrac+int8(fracIncr), mysql.MaxDecimalScale) + to.resultFrac = min(from1.resultFrac+int8(fracIncr), mysql.MaxDecimalScale) return doDivMod(from1, from2, to, nil, fracIncr) } @@ -2123,7 +2122,7 @@ DecimalMod does modulus of two decimals. */ func DecimalMod(from1, from2, to *MyDecimal) error { from1, from2, to = validateArgs(from1, from2, to) - to.resultFrac = mathutil.Max(from1.resultFrac, from2.resultFrac) + to.resultFrac = max(from1.resultFrac, from2.resultFrac) return doDivMod(from1, from2, nil, to, 0) } @@ -2191,7 +2190,7 @@ func doDivMod(from1, from2, to, mod *MyDecimal, fracIncr int) error { // digitsFrac=max(frac1, frac2), as for subtraction // digitsInt=from2.digitsInt to.negative = from1.negative - to.digitsFrac = mathutil.Max(from1.digitsFrac, from2.digitsFrac) + to.digitsFrac = max(from1.digitsFrac, from2.digitsFrac) } else { wordsFracTo = digitsToWords(frac1 + frac2 + fracIncr) wordsIntTo, wordsFracTo, err = fixWordCntError(wordsIntTo, wordsFracTo) @@ -2356,7 +2355,7 @@ func doDivMod(from1, from2, to, mod *MyDecimal, fracIncr int) error { return ErrOverflow } stop1 = start1 + wordsIntTo + wordsFracTo - to.digitsInt = int8(mathutil.Min(wordsIntTo*digitsPerWord, int(from2.digitsInt))) + to.digitsInt = int8(min(wordsIntTo*digitsPerWord, int(from2.digitsInt))) } if wordsIntTo+wordsFracTo > wordBufLen { stop1 -= wordsIntTo + wordsFracTo - wordBufLen diff --git a/pkg/types/time.go b/pkg/types/time.go index 012f3c4e27df0..35e11aacacc1c 100644 --- a/pkg/types/time.go +++ b/pkg/types/time.go @@ -2681,7 +2681,7 @@ func ParseTimeFromDecimal(sc *stmtctx.StatementContext, dec *MyDecimal) (t Time, if err != nil && !terror.ErrorEqual(err, ErrTruncated) { return ZeroTime, err } - fsp := mathutil.Min(MaxFsp, int(dec.GetDigitsFrac())) + fsp := min(MaxFsp, int(dec.GetDigitsFrac())) t, err = parseDateTimeFromNum(sc, intPart) if err != nil { return ZeroTime, err diff --git a/pkg/util/chunk/BUILD.bazel b/pkg/util/chunk/BUILD.bazel index e8ee18cba64ea..8aa1fa4f47f36 100644 --- a/pkg/util/chunk/BUILD.bazel +++ b/pkg/util/chunk/BUILD.bazel @@ -30,7 +30,6 @@ go_library( "//pkg/util/encrypt", "//pkg/util/hack", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/memory", "@com_github_pingcap_errors//:errors", "@com_github_pingcap_failpoint//:failpoint", @@ -67,7 +66,6 @@ go_test( "//pkg/testkit/testsetup", "//pkg/types", "//pkg/util/collate", - "//pkg/util/mathutil", "//pkg/util/memory", "@com_github_pingcap_errors//:errors", "@com_github_pingcap_failpoint//:failpoint", diff --git a/pkg/util/chunk/alloc.go b/pkg/util/chunk/alloc.go index 306ca6283897a..ac40309a88c7c 100644 --- a/pkg/util/chunk/alloc.go +++ b/pkg/util/chunk/alloc.go @@ -18,7 +18,6 @@ import ( "math" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" ) // Allocator is an interface defined to reduce object allocation. @@ -101,7 +100,7 @@ func (a *allocator) Alloc(fields []*types.FieldType, capacity, maxChunkSize int) } // Init the chunk fields. - chk.capacity = mathutil.Min(capacity, maxChunkSize) + chk.capacity = min(capacity, maxChunkSize) chk.requiredRows = maxChunkSize // Allocate the chunk columns from the pool column allocator. for _, f := range fields { diff --git a/pkg/util/chunk/chunk.go b/pkg/util/chunk/chunk.go index db1539ed187af..6242de8450633 100644 --- a/pkg/util/chunk/chunk.go +++ b/pkg/util/chunk/chunk.go @@ -19,7 +19,6 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" ) var msgErrSelNotNil = "The selection vector of Chunk is not nil. Please file a bug to the TiDB Team" @@ -67,7 +66,7 @@ func NewChunkWithCapacity(fields []*types.FieldType, capacity int) *Chunk { func New(fields []*types.FieldType, capacity, maxChunkSize int) *Chunk { chk := &Chunk{ columns: make([]*Column, 0, len(fields)), - capacity: mathutil.Min(capacity, maxChunkSize), + capacity: min(capacity, maxChunkSize), // set the default value of requiredRows to maxChunkSize to let chk.IsFull() behave // like how we judge whether a chunk is full now, then the statement // "chk.NumRows() < maxChunkSize" @@ -325,7 +324,7 @@ func reCalcCapacity(c *Chunk, maxChunkSize int) int { if newCapacity == 0 { newCapacity = InitialCapacity } - return mathutil.Min(newCapacity, maxChunkSize) + return min(newCapacity, maxChunkSize) } // Capacity returns the capacity of the Chunk. diff --git a/pkg/util/chunk/chunk_test.go b/pkg/util/chunk/chunk_test.go index 2484f751b472a..4bbb3bc723ed0 100644 --- a/pkg/util/chunk/chunk_test.go +++ b/pkg/util/chunk/chunk_test.go @@ -26,7 +26,6 @@ import ( "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/sessionctx/stmtctx" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/stretchr/testify/require" ) @@ -284,7 +283,7 @@ func TestChunkSizeControl(t *testing.T) { chk.Reset() for i := 1; i < maxChunkSize*2; i++ { chk.SetRequiredRows(i, maxChunkSize) - require.Equal(t, mathutil.Min(maxChunkSize, i), chk.RequiredRows()) + require.Equal(t, min(maxChunkSize, i), chk.RequiredRows()) } chk.SetRequiredRows(1, maxChunkSize). diff --git a/pkg/util/chunk/codec.go b/pkg/util/chunk/codec.go index 3a64e48476e6f..324a90c255a25 100644 --- a/pkg/util/chunk/codec.go +++ b/pkg/util/chunk/codec.go @@ -21,7 +21,6 @@ import ( "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" ) // Codec is used to: @@ -152,7 +151,7 @@ func (*Codec) setAllNotNull(col *Column) { numNullBitmapBytes := (col.length + 7) / 8 col.nullBitmap = col.nullBitmap[:0] for i := 0; i < numNullBitmapBytes; { - numAppendBytes := mathutil.Min(numNullBitmapBytes-i, cap(allNotNullBitmap)) + numAppendBytes := min(numNullBitmapBytes-i, cap(allNotNullBitmap)) col.nullBitmap = append(col.nullBitmap, allNotNullBitmap[:numAppendBytes]...) i += numAppendBytes } diff --git a/pkg/util/chunk/list_test.go b/pkg/util/chunk/list_test.go index df6c29fc3591b..106b9ece6f438 100644 --- a/pkg/util/chunk/list_test.go +++ b/pkg/util/chunk/list_test.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/stretchr/testify/require" ) @@ -164,7 +163,7 @@ func BenchmarkListGetRow(b *testing.B) { } rand.Seed(0) ptrs := make([]RowPtr, 0, b.N) - for i := 0; i < mathutil.Min(b.N, 10000); i++ { + for i := 0; i < min(b.N, 10000); i++ { ptrs = append(ptrs, RowPtr{ ChkIdx: rand.Uint32() % uint32(numChk), RowIdx: rand.Uint32() % uint32(numRow), diff --git a/pkg/util/chunk/row_in_disk_test.go b/pkg/util/chunk/row_in_disk_test.go index 933a30834a779..1c27456a94ea3 100644 --- a/pkg/util/chunk/row_in_disk_test.go +++ b/pkg/util/chunk/row_in_disk_test.go @@ -30,7 +30,6 @@ import ( "github.com/pingcap/tidb/pkg/config" "github.com/pingcap/tidb/pkg/parser/mysql" "github.com/pingcap/tidb/pkg/types" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -121,7 +120,7 @@ func BenchmarkDataInDiskByRowsGetRow(b *testing.B) { } rand.Seed(0) ptrs := make([]RowPtr, 0, b.N) - for i := 0; i < mathutil.Min(b.N, 10000); i++ { + for i := 0; i < min(b.N, 10000); i++ { ptrs = append(ptrs, RowPtr{ ChkIdx: rand.Uint32() % uint32(numChk), RowIdx: rand.Uint32() % uint32(numRow), diff --git a/pkg/util/memory/BUILD.bazel b/pkg/util/memory/BUILD.bazel index 53f33e50054ec..565b1a6567c74 100644 --- a/pkg/util/memory/BUILD.bazel +++ b/pkg/util/memory/BUILD.bazel @@ -17,7 +17,6 @@ go_library( "//pkg/util/cgroup", "//pkg/util/dbterror", "//pkg/util/logutil", - "//pkg/util/mathutil", "//pkg/util/sqlkiller", "@com_github_pingcap_failpoint//:failpoint", "@com_github_pingcap_sysutil//:sysutil", @@ -41,7 +40,6 @@ go_test( "//pkg/errno", "//pkg/parser/terror", "//pkg/testkit/testsetup", - "//pkg/util/mathutil", "@com_github_stretchr_testify//require", "@org_uber_go_goleak//:goleak", ], diff --git a/pkg/util/memory/meminfo.go b/pkg/util/memory/meminfo.go index 8d0e25bcb759e..a9d6aa3733d1b 100644 --- a/pkg/util/memory/meminfo.go +++ b/pkg/util/memory/meminfo.go @@ -22,7 +22,6 @@ import ( "github.com/pingcap/sysutil" "github.com/pingcap/tidb/pkg/parser/terror" "github.com/pingcap/tidb/pkg/util/cgroup" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/shirou/gopsutil/v3/mem" ) @@ -116,7 +115,7 @@ func MemTotalCGroup() (uint64, error) { if err != nil { return 0, err } - memo = mathutil.Min(v.Total, memo) + memo = min(v.Total, memo) memLimit.set(memo, time.Now()) return memo, nil } @@ -135,7 +134,7 @@ func MemUsedCGroup() (uint64, error) { if err != nil { return 0, err } - memo = mathutil.Min(v.Used, memo) + memo = min(v.Used, memo) memUsage.set(memo, time.Now()) return memo, nil } diff --git a/pkg/util/memory/tracker_test.go b/pkg/util/memory/tracker_test.go index ce6d3e3856031..c244b20ad28d2 100644 --- a/pkg/util/memory/tracker_test.go +++ b/pkg/util/memory/tracker_test.go @@ -27,7 +27,6 @@ import ( "github.com/pingcap/tidb/pkg/errno" "github.com/pingcap/tidb/pkg/parser/terror" - "github.com/pingcap/tidb/pkg/util/mathutil" "github.com/stretchr/testify/require" ) @@ -401,7 +400,7 @@ func TestMaxConsumed(t *testing.T) { } consumed += b tracker.Consume(b) - maxConsumed = mathutil.Max(maxConsumed, consumed) + maxConsumed = max(maxConsumed, consumed) require.Equal(t, consumed, r.BytesConsumed()) require.Equal(t, maxConsumed, r.MaxConsumed()) diff --git a/pkg/util/ranger/BUILD.bazel b/pkg/util/ranger/BUILD.bazel index b0e45e7cfca1d..935274ab75cf0 100644 --- a/pkg/util/ranger/BUILD.bazel +++ b/pkg/util/ranger/BUILD.bazel @@ -30,7 +30,6 @@ go_library( "//pkg/util/codec", "//pkg/util/collate", "//pkg/util/dbterror", - "//pkg/util/mathutil", "@com_github_pingcap_errors//:errors", ], ) diff --git a/pkg/util/ranger/detacher.go b/pkg/util/ranger/detacher.go index 954bbcee5254e..071f78a8925c3 100644 --- a/pkg/util/ranger/detacher.go +++ b/pkg/util/ranger/detacher.go @@ -28,7 +28,6 @@ import ( "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/collate" - "github.com/pingcap/tidb/pkg/util/mathutil" ) // detachColumnCNFConditions detaches the condition for calculating range from the other conditions. @@ -207,8 +206,8 @@ func getCNFItemRangeResult(sctx sessionctx.Context, rangeResult *DetachRangeResu maxColNum = len(ran.LowVal) minColNum = len(ran.LowVal) } else { - maxColNum = mathutil.Max(maxColNum, len(ran.LowVal)) - minColNum = mathutil.Min(minColNum, len(ran.LowVal)) + maxColNum = max(maxColNum, len(ran.LowVal)) + minColNum = min(minColNum, len(ran.LowVal)) } } if minColNum != maxColNum {