Skip to content

Commit

Permalink
chunk/codec: adjust decoding offsets in chunk (#7106)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreMouche authored and ngaut committed Jul 19, 2018
1 parent ba5a33f commit 90c721a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/chunk/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (c *Codec) decodeColumn(buffer []byte, col *column, ordinal int) (remained
numDataBytes := numFixedBytes * col.length
if numFixedBytes == -1 {
numOffsetBytes := (col.length + 1) * 4
col.offsets = append(col.offsets[:0], c.bytesToI32Slice(buffer)...)
col.offsets = append(col.offsets[:0], c.bytesToI32Slice(buffer[:numOffsetBytes])...)
buffer = buffer[numOffsetBytes:]
numDataBytes = int(col.offsets[col.length])
} else if cap(col.elemBuf) < numFixedBytes {
Expand Down
33 changes: 33 additions & 0 deletions util/chunk/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,36 @@ func BenchmarkDecodeToChunk(b *testing.B) {
codec.DecodeToChunk(buffer, chk)
}
}

func BenchmarkDecodeToChunkWithVariableType(b *testing.B) {
numCols := 6
numRows := 1024

colTypes := make([]*types.FieldType, 0, numCols)
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeLonglong})
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeLonglong})
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeVarchar})
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeVarchar})
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeNewDecimal})
colTypes = append(colTypes, &types.FieldType{Tp: mysql.TypeJSON})

chk := NewChunkWithCapacity(colTypes, numRows)
for i := 0; i < numRows; i++ {
str := fmt.Sprintf("%d.12345", i)
chk.AppendNull(0)
chk.AppendInt64(1, int64(i))
chk.AppendString(2, str)
chk.AppendString(3, str)
chk.AppendMyDecimal(4, types.NewDecFromStringForTest(str))
chk.AppendJSON(5, json.CreateBinary(str))
}
codec := &Codec{colTypes}
buffer := codec.Encode(chk)

chk.Reset()

b.ResetTimer()
for i := 0; i < b.N; i++ {
codec.DecodeToChunk(buffer, chk)
}
}

0 comments on commit 90c721a

Please sign in to comment.