Skip to content

Commit

Permalink
*: support makezero via golangci-lint (pingcap#29267)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangggong authored Nov 10, 2021
1 parent 92de9c0 commit 37bfd57
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ linters:
- exportloopref
- rowserrcheck
- unconvert
- makezero

linters-settings:
staticcheck:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
Expand All @@ -36,3 +38,4 @@ issues:
- errcheck
- gosec
- rowserrcheck
- makezero
2 changes: 1 addition & 1 deletion executor/index_lookup_hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func (iw *indexHashJoinInnerWorker) doJoinInOrder(ctx context.Context, task *ind
}
}
// TODO: matchedInnerRowPtrs and matchedInnerRows can be moved to inner worker.
matchedInnerRows := make([]chunk.Row, len(task.matchedInnerRowPtrs))
matchedInnerRows := make([]chunk.Row, 0, len(task.matchedInnerRowPtrs))
var hasMatched, hasNull, ok bool
for chkIdx, innerRowPtrs4Chk := range task.matchedInnerRowPtrs {
for outerRowIdx, innerRowPtrs := range innerRowPtrs4Chk {
Expand Down
4 changes: 2 additions & 2 deletions executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func getOneLine(reader *bufio.Reader) ([]byte, error) {
var tempLine []byte
for isPrefix {
tempLine, isPrefix, err = reader.ReadLine()
resByte = append(resByte, tempLine...)
resByte = append(resByte, tempLine...) // nozero
// Use the max value of max_allowed_packet to check the single line length.
if len(resByte) > int(variable.MaxOfMaxAllowedPacket) {
return resByte, errors.Errorf("single line length exceeds limit: %v", variable.MaxOfMaxAllowedPacket)
Expand Down Expand Up @@ -1050,7 +1050,7 @@ func readLastLines(ctx context.Context, file *os.File, endCursor int64) ([]strin
if err != nil {
return nil, 0, err
}
lines = append(chars, lines...)
lines = append(chars, lines...) // nozero

// find first '\n' or '\r'
for i := 0; i < len(chars); i++ {
Expand Down
2 changes: 1 addition & 1 deletion kv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (k Key) PrefixNext() Key {
}
if i == -1 {
copy(buf, k)
buf = append(buf, 0)
buf = append(buf, 0) // nozero
}
return buf
}
Expand Down
4 changes: 2 additions & 2 deletions planner/cascades/transformation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func (r *pushDownJoin) predicatePushDown(
leftCond = append(join.LeftConditions, derivedLeftJoinCond...)
join.LeftConditions = nil
remainCond = append(expression.ScalarFuncs2Exprs(equalCond), otherCond...)
remainCond = append(remainCond, leftPushCond...)
remainCond = append(remainCond, leftPushCond...) // nozero
} else {
remainCond = expression.ExtractFiltersFromDNFs(join.SCtx(), remainCond)
// Only derive left where condition, because right where condition cannot be pushed down
Expand All @@ -931,7 +931,7 @@ func (r *pushDownJoin) predicatePushDown(
rightCond = append(join.RightConditions, derivedRightJoinCond...)
join.RightConditions = nil
remainCond = append(expression.ScalarFuncs2Exprs(equalCond), otherCond...)
remainCond = append(remainCond, rightPushCond...)
remainCond = append(remainCond, rightPushCond...) // nozero
}
default:
// TODO: Enhance this rule to deal with Semi/SmiAnti Joins.
Expand Down
10 changes: 5 additions & 5 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,11 @@ func (p *LogicalJoin) constructIndexJoin(
}
outerSchema, innerSchema := p.Children()[outerIdx].Schema(), p.Children()[1-outerIdx].Schema()
if outerSchema.Contains(lhs) && innerSchema.Contains(rhs) {
outerHashKeys = append(outerHashKeys, lhs)
innerHashKeys = append(innerHashKeys, rhs)
outerHashKeys = append(outerHashKeys, lhs) // nozero
innerHashKeys = append(innerHashKeys, rhs) // nozero
} else if innerSchema.Contains(lhs) && outerSchema.Contains(rhs) {
outerHashKeys = append(outerHashKeys, rhs)
innerHashKeys = append(innerHashKeys, lhs)
outerHashKeys = append(outerHashKeys, rhs) // nozero
innerHashKeys = append(innerHashKeys, lhs) // nozero
}
newOtherConds = append(newOtherConds[:i], newOtherConds[i+1:]...)
}
Expand Down Expand Up @@ -1203,7 +1203,7 @@ func (cwc *ColWithCmpFuncManager) BuildRangesByRow(ctx sessionctx.Context, row c
if err != nil {
return nil, err
}
exprs = append(exprs, newExpr)
exprs = append(exprs, newExpr) // nozero
}
ranges, err := ranger.BuildColumnRange(exprs, ctx.GetSessionVars().StmtCtx, cwc.TargetCol.RetType, cwc.colLength)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions planner/core/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,13 +579,13 @@ func ExpandVirtualColumn(columns []*model.ColumnInfo, schema *expression.Schema,
for _, baseCol := range baseCols {
if !schema.Contains(baseCol) {
schema.Columns = append(schema.Columns, baseCol)
copyColumn = append(copyColumn, FindColumnInfoByID(colsInfo, baseCol.ID))
copyColumn = append(copyColumn, FindColumnInfoByID(colsInfo, baseCol.ID)) // nozero
}
}
}
if extraColumn != nil {
schema.Columns = append(schema.Columns, extraColumn)
copyColumn = append(copyColumn, extraColumnModel)
copyColumn = append(copyColumn, extraColumnModel) // nozero
}
return copyColumn
}
Expand Down
2 changes: 1 addition & 1 deletion planner/util/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx sessionctx.Context,
}
for i, ok := range used {
if !ok {
remained = append(remained, path.TableFilters[i])
remained = append(remained, path.TableFilters[i]) // nozero
}
}
return access, remained
Expand Down
6 changes: 3 additions & 3 deletions store/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1115,9 +1115,9 @@ retryScanAndResolve:
return stat, errors.Errorf("unexpected scanlock error: %s", locksResp)
}
locksInfo := locksResp.GetLocks()
locks := make([]*txnlock.Lock, len(locksInfo))
for i := range locksInfo {
locks[i] = txnlock.NewLock(locksInfo[i])
locks := make([]*txnlock.Lock, 0, len(locksInfo))
for _, li := range locksInfo {
locks = append(locks, txnlock.NewLock(li))
}
if w.testingKnobs.scanLocks != nil {
locks = append(locks, w.testingKnobs.scanLocks(key, loc.Region.GetID())...)
Expand Down
14 changes: 7 additions & 7 deletions store/mockstore/unistore/tikv/mvcc/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ const (
// EncodeWriteCFValue accepts a write cf parameters and return the encoded bytes data.
// Just like the tikv encoding form. See tikv/src/storage/mvcc/write.rs for more detail.
func EncodeWriteCFValue(t WriteType, startTs uint64, shortVal []byte) []byte {
data := make([]byte, 1)
data[0] = t
data := make([]byte, 0)
data = append(data, t)
data = codec.EncodeUvarint(data, startTs)
if len(shortVal) != 0 {
data = append(data, byte(shortValuePrefix), byte(len(shortVal)))
Expand All @@ -82,16 +82,16 @@ func EncodeWriteCFValue(t WriteType, startTs uint64, shortVal []byte) []byte {

// EncodeLockCFValue encodes the mvcc lock and returns putLock value and putDefault value if exists.
func EncodeLockCFValue(lock *Lock) ([]byte, []byte) {
data := make([]byte, 1)
data := make([]byte, 0)
switch lock.Op {
case byte(kvrpcpb.Op_Put):
data[0] = LockTypePut
data = append(data, LockTypePut)
case byte(kvrpcpb.Op_Del):
data[0] = LockTypeDelete
data = append(data, LockTypeDelete)
case byte(kvrpcpb.Op_Lock):
data[0] = LockTypeLock
data = append(data, LockTypeLock)
case byte(kvrpcpb.Op_PessimisticLock):
data[0] = LockTypePessimistic
data = append(data, LockTypePessimistic)
default:
panic("invalid lock op")
}
Expand Down
6 changes: 4 additions & 2 deletions tablecodec/tablecodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@ func TryGetCommonPkColumnRestoredIds(tbl *model.TableInfo) []int64 {

// GenIndexValueForClusteredIndexVersion1 generates the index value for the clustered index with version 1(New in v5.0.0).
func GenIndexValueForClusteredIndexVersion1(sc *stmtctx.StatementContext, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, IdxValNeedRestoredData bool, distinct bool, untouched bool, indexedValues []types.Datum, h kv.Handle, partitionID int64, handleRestoredData []types.Datum) ([]byte, error) {
idxVal := make([]byte, 1)
idxVal := make([]byte, 0)
idxVal = append(idxVal, 0)
tailLen := 0
// Version info.
idxVal = append(idxVal, IndexVersionFlag)
Expand Down Expand Up @@ -1216,7 +1217,8 @@ func GenIndexValueForClusteredIndexVersion1(sc *stmtctx.StatementContext, tblInf

// genIndexValueVersion0 create index value for both local and global index.
func genIndexValueVersion0(sc *stmtctx.StatementContext, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, IdxValNeedRestoredData bool, distinct bool, untouched bool, indexedValues []types.Datum, h kv.Handle, partitionID int64) ([]byte, error) {
idxVal := make([]byte, 1)
idxVal := make([]byte, 0)
idxVal = append(idxVal, 0)
newEncode := false
tailLen := 0
if !h.IsInt() && distinct {
Expand Down

0 comments on commit 37bfd57

Please sign in to comment.