expression: reserve exact space for UUIDs (#65365)

close pingcap/tidb#65364
This commit is contained in:
Daniël van Eeden
2026-01-07 12:07:26 +01:00
committed by GitHub
parent bb3fa45009
commit 34db659899
2 changed files with 14 additions and 3 deletions

View File

@ -30,6 +30,11 @@ import (
"github.com/pingcap/tidb/pkg/util/vitess"
)
// UUIDStrLen is the length of a UUID in string format
// 16 bytes in hex is 32 characters, plus 4 hyphens = 36 characters (hex/ASCII, 1 byte chars)
// https://datatracker.ietf.org/doc/html/rfc9562#name-uuid-format
const UUIDStrLen = 36
func (b *builtinInetNtoaSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get()
@ -207,7 +212,7 @@ func (b *builtinUUIDSig) vectorized() bool {
func (b *builtinUUIDSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
result.ReserveString(n)
result.ReserveStringWithSizeHint(n, UUIDStrLen)
var id uuid.UUID
var err error
for range n {
@ -226,7 +231,7 @@ func (b *builtinUUIDv4Sig) vectorized() bool {
func (b *builtinUUIDv4Sig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
result.ReserveString(n)
result.ReserveStringWithSizeHint(n, UUIDStrLen)
var id uuid.UUID
var err error
for range n {
@ -245,7 +250,7 @@ func (b *builtinUUIDv7Sig) vectorized() bool {
func (b *builtinUUIDv7Sig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
result.ReserveString(n)
result.ReserveStringWithSizeHint(n, UUIDStrLen)
var id uuid.UUID
var err error
for range n {

View File

@ -612,6 +612,12 @@ func (c *Column) ReserveString(n int) {
c.reserve(n, 8)
}
// ReserveStringWithSizeHint changes the column capacity to store n strings of a predetermined size.
// example: a 36 character text format UUID: ReserveStringWithSizeHint(1, 36) for a single entry.
func (c *Column) ReserveStringWithSizeHint(n int, size int) {
c.reserve(n, size)
}
// ReserveBytes changes the column capacity to store n bytes elements and set the length to zero.
func (c *Column) ReserveBytes(n int) {
c.reserve(n, 8)