Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions pkg/common/hashmap/inthashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,6 @@ func (m *IntHashMap) UnmarshalFrom(r io.Reader, mp *mpool.MPool) (int64, error)
return n, nil
}

func (m *IntHashMap) AllGroupHash() []uint64 {
return m.hashMap.AllGroupHash()
func (m *IntHashMap) FillGroupHashes(dst []uint64) []uint64 {
return m.hashMap.FillGroupHashes(dst)
}
4 changes: 2 additions & 2 deletions pkg/common/hashmap/strhashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,6 @@ func (m *StrHashMap) UnmarshalFrom(r io.Reader, mp *mpool.MPool) (int64, error)
return n, nil
}

func (m *StrHashMap) AllGroupHash() []uint64 {
return m.hashMap.AllGroupHash()
func (m *StrHashMap) FillGroupHashes(dst []uint64) []uint64 {
return m.hashMap.FillGroupHashes(dst)
}
4 changes: 2 additions & 2 deletions pkg/common/hashmap/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ type HashMap interface {
WriteTo(w io.Writer) (int64, error)
// UnmarshalFrom deserializes a byte slice from a reader.
UnmarshalFrom(r io.Reader, mp *mpool.MPool) (int64, error)
// Get all (group, hashCode) pairs
AllGroupHash() []uint64
// FillGroupHashes appends all group hash codes into dst and returns the result.
FillGroupHashes(dst []uint64) []uint64
}

// Iterator allows users to do insert or find operations on hash tables in bulk.
Expand Down
8 changes: 4 additions & 4 deletions pkg/container/hashtable/int64_hash_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,14 @@ func (ht *Int64HashMap) UnmarshalFrom(r io.Reader, mp *mpool.MPool) (n int64, er
return
}

func (ht *Int64HashMap) AllGroupHash() []uint64 {
ret := make([]uint64, ht.elemCnt)
func (ht *Int64HashMap) FillGroupHashes(dst []uint64) []uint64 {
dst = dst[:ht.elemCnt]
for i := range ht.cells {
for _, c := range ht.cells[i] {
if c.Mapped != 0 {
ret[c.Mapped-1] = c.Key
dst[c.Mapped-1] = c.Key
}
}
}
return ret
return dst
}
8 changes: 4 additions & 4 deletions pkg/container/hashtable/string_hash_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,14 @@ func (ht *StringHashMap) UnmarshalFrom(r io.Reader, mp *mpool.MPool) (n int64, e
return
}

func (ht *StringHashMap) AllGroupHash() []uint64 {
ret := make([]uint64, ht.elemCnt)
func (ht *StringHashMap) FillGroupHashes(dst []uint64) []uint64 {
dst = dst[:ht.elemCnt]
for i := range ht.cells {
for _, c := range ht.cells[i] {
if c.Mapped != 0 {
ret[c.Mapped-1] = c.HashState[0]
dst[c.Mapped-1] = c.HashState[0]
}
}
}
return ret
return dst
}
99 changes: 56 additions & 43 deletions pkg/container/types/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package types
import (
"bytes"
"encoding"
"encoding/binary"
"fmt"
"io"
"strings"
Expand Down Expand Up @@ -696,121 +697,133 @@ func WriteSizeBytes(bs []byte, w io.Writer) error {
}

func ReadInt64(r io.Reader) (int64, error) {
buf := make([]byte, 8)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [8]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeInt64(buf), nil
return int64(binary.LittleEndian.Uint64(buf[:])), nil
}

func ReadUint64(r io.Reader) (uint64, error) {
buf := make([]byte, 8)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [8]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeUint64(buf), nil
return binary.LittleEndian.Uint64(buf[:]), nil
}

func WriteInt64(w io.Writer, v int64) error {
w.Write(EncodeInt64(&v))
return nil
var buf [8]byte
binary.LittleEndian.PutUint64(buf[:], uint64(v))
_, err := w.Write(buf[:])
return err
}

func WriteUint64(w io.Writer, v uint64) error {
w.Write(EncodeUint64(&v))
return nil
var buf [8]byte
binary.LittleEndian.PutUint64(buf[:], v)
_, err := w.Write(buf[:])
return err
}

func ReadBool(r io.Reader) (bool, error) {
buf := make([]byte, 1)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [1]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return false, err
}
return DecodeBool(buf), nil
return buf[0] != 0, nil
}

func ReadInt16(r io.Reader) (int16, error) {
buf := make([]byte, 2)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [2]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeInt16(buf), nil
return int16(binary.LittleEndian.Uint16(buf[:])), nil
}

func WriteInt16(w io.Writer, v int16) error {
w.Write(EncodeInt16(&v))
return nil
var buf [2]byte
binary.LittleEndian.PutUint16(buf[:], uint16(v))
_, err := w.Write(buf[:])
return err
}

func ReadUint16(r io.Reader) (uint16, error) {
buf := make([]byte, 2)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [2]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeUint16(buf), nil
return binary.LittleEndian.Uint16(buf[:]), nil
}

func WriteUint16(w io.Writer, v uint16) error {
w.Write(EncodeUint16(&v))
return nil
var buf [2]byte
binary.LittleEndian.PutUint16(buf[:], v)
_, err := w.Write(buf[:])
return err
}

func ReadInt32(r io.Reader) (int32, error) {
buf := make([]byte, 4)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [4]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeInt32(buf), nil
return int32(binary.LittleEndian.Uint32(buf[:])), nil
}

func WriteInt32(w io.Writer, v int32) error {
w.Write(EncodeInt32(&v))
return nil
var buf [4]byte
binary.LittleEndian.PutUint32(buf[:], uint32(v))
_, err := w.Write(buf[:])
return err
}

func ReadUint32(r io.Reader) (uint32, error) {
buf := make([]byte, 4)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [4]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return DecodeUint32(buf), nil
return binary.LittleEndian.Uint32(buf[:]), nil
}

func WriteUint32(w io.Writer, v uint32) error {
w.Write(EncodeUint32(&v))
return nil
var buf [4]byte
binary.LittleEndian.PutUint32(buf[:], v)
_, err := w.Write(buf[:])
return err
}

func ReadInt32AsInt(r io.Reader) (int, error) {
buf := make([]byte, 4)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [4]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return int(DecodeInt32(buf)), nil
return int(int32(binary.LittleEndian.Uint32(buf[:]))), nil
}

func ReadByte(r io.Reader) (byte, error) {
buf := make([]byte, 1)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [1]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return buf[0], nil
}

func ReadByteAsInt(r io.Reader) (int, error) {
buf := make([]byte, 1)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [1]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return 0, err
}
return int(buf[0]), nil
}

func ReadType(r io.Reader) (Type, error) {
buf := make([]byte, TSize)
if _, err := io.ReadFull(r, buf); err != nil {
var buf [TSize]byte
if _, err := io.ReadFull(r, buf[:]); err != nil {
return Type{}, err
}
return DecodeType(buf), nil
return DecodeType(buf[:]), nil
}

func ReadSizeBytes(r io.Reader) (int32, []byte, error) {
Expand Down
13 changes: 1 addition & 12 deletions pkg/sql/colexec/aggexec/aggContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (a *AggContext) preAllocate(more int) {
a.groupContext = a.groupContext[:oldLen]
}

func (a *AggContext) growsGroupContext(
func (a *AggContext) growGroupContexts(
more int,
resultType types.Type, parameters ...types.Type) {
if !a.hasGroupContext {
Expand Down Expand Up @@ -96,17 +96,6 @@ func (a *AggContext) getGroupContext(i int) AggGroupExecContext {
return nil
}

func (a *AggContext) getGroupContextEncodings() [][]byte {
if !a.hasGroupContext {
return nil
}
encodings := make([][]byte, len(a.groupContext))
for i := range a.groupContext {
encodings[i] = a.groupContext[i].Marshal()
}
return encodings
}

func (a *AggContext) getGroupContextEncodingsForFlags(cnt int64, flags [][]uint8) [][]byte {
if !a.hasGroupContext {
return nil
Expand Down
18 changes: 0 additions & 18 deletions pkg/sql/colexec/aggexec/aggInformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ func (info singleAggInfo) TypesInfo() ([]types.Type, types.Type) {
return []types.Type{info.argType}, info.retType
}

func (info singleAggInfo) getEncoded() EncodedBasicInfo {
return EncodedBasicInfo{
Id: info.aggID,
IsDistinct: info.distinct,
Args: []types.Type{info.argType},
Ret: info.retType,
}
}

// singleAggExecExtraInformation is the extra information of single column agg to optimize the execution.
type singleAggExecExtraInformation struct {
partialGroup int
Expand Down Expand Up @@ -99,12 +90,3 @@ func (info multiAggInfo) IsDistinct() bool {
func (info multiAggInfo) TypesInfo() ([]types.Type, types.Type) {
return info.argTypes, info.retType
}

func (info multiAggInfo) getEncoded() EncodedBasicInfo {
return EncodedBasicInfo{
Id: info.aggID,
IsDistinct: info.distinct,
Args: info.argTypes,
Ret: info.retType,
}
}
Loading
Loading