Skip to content

Conversation

@dveeden
Copy link
Contributor

@dveeden dveeden commented Dec 31, 2025

What problem does this PR solve?

Issue Number: close #65364

Problem Summary:

result.ReserveString(n) reserves space for a string, but doesn't take into account that UUID(), UUID_V4() and UUID_V7() all create 36-byte text format UUIDs.

What changed and how does it work?

With a t1 table with 36 rows:

select uuid() from t1;
(dlv) b (*builtinUUIDSig).vecEvalString
Breakpoint 1 set at 0x563f173 for github.com/pingcap/tidb/pkg/expression.(*builtinUUIDSig).vecEvalString() ./pkg/expression/builtin_miscellaneous_vec.go:210
(dlv) c
(dlv) p n
36
(dlv) p result
("*github.com/pingcap/tidb/pkg/util/chunk.Column")(0xc015480070)
*github.com/pingcap/tidb/pkg/util/chunk.Column {
	length: 0,
	nullBitmap: []uint8 len: 0, cap: 4, [],
	offsets: []int64 len: 1, cap: 33, [0],
	data: []uint8 len: 0, cap: 256, [],
	elemBuf: []uint8 len: 0, cap: 0, nil,
	avoidReusing: false,}

So we have n=36 for 36 rows. And data has a capacity of 256 before calling result.ReserveStringWithSizeHint(n, UUID_STR_LEN)

(dlv) n
> github.com/pingcap/tidb/pkg/expression.(*builtinUUIDSig).vecEvalString() ./pkg/expression/builtin_miscellaneous_vec.go:213 (PC: 0x563f1d2)
   208:	}
   209:	
   210:	func (b *builtinUUIDSig) vecEvalString(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
   211:		n := input.NumRows()
   212:		result.ReserveStringWithSizeHint(n, UUID_STR_LEN)
=> 213:		var id uuid.UUID
   214:		var err error
   215:		for range n {
   216:			id, err = uuid.NewUUID()
   217:			if err != nil {
   218:				return err
(dlv) p result
("*github.com/pingcap/tidb/pkg/util/chunk.Column")(0xc015480070)
*github.com/pingcap/tidb/pkg/util/chunk.Column {
	length: 0,
	nullBitmap: []uint8 len: 0, cap: 5, [],
	offsets: []int64 len: 1, cap: 37, [0],
	data: []uint8 len: 0, cap: 1296, [],
	elemBuf: []uint8 len: 0, cap: 0, nil,
	avoidReusing: false,}
(dlv) p 36*36
1296

So after the call to ReserveStringWithSizeHint() (with (36, 36) as arguments for 36 rows of 36 bytes/chars) we have a data with a capacity of 1296 (= 36*36).

Now let's set a breakpoint at the line where we return form this function.

(dlv) b builtin_miscellaneous_vec.go:222
Breakpoint 2 set at 0x563f2dd for github.com/pingcap/tidb/pkg/expression.(*builtinUUIDSig).vecEvalString() ./pkg/expression/builtin_miscellaneous_vec.go:222
(dlv) c
[2025/12/31 09:44:25.576 +01:00] [ERROR] [syncer.go:314] ["reload schema in loop failed"] [error="[tikv:9001]PD server timeout: start timestamp may fall behind safe point"]
> [Breakpoint 2] github.com/pingcap/tidb/pkg/expression.(*builtinUUIDSig).vecEvalString() ./pkg/expression/builtin_miscellaneous_vec.go:222 (hits goroutine(2075):1 total:1) (PC: 0x563f2dd)
Warning: listing may not match stale executable
   217:			if err != nil {
   218:				return err
   219:			}
   220:			result.AppendString(id.String())
   221:		}
=> 222:		return nil
   223:	}
   224:	
   225:	func (b *builtinUUIDv4Sig) vectorized() bool {
   226:		return true
   227:	}
(dlv) p result
("*github.com/pingcap/tidb/pkg/util/chunk.Column")(0xc015480070)
*github.com/pingcap/tidb/pkg/util/chunk.Column {
	length: 36,
	nullBitmap: []uint8 len: 5, cap: 5, [255,255,255,255,15],
	offsets: []int64 len: 37, cap: 37, [0,36,72,108,144,180,216,252,288,324,360,396,432,468,504,540,576,612,648,684,720,756,792,828,864,900,936,972,1008,1044,1080,1116,1152,1188,1224,1260,1296],
	data: []uint8 len: 1296, cap: 1296, [101,57,52,98,100,52,101,97,45,101,54,50,52,45,49,49,102,48,45,98,99,99,97,45,50,50,50,50,50,100,51,52,100,52,49,49,101,57,52,98,101,51,54,97,45,101,54,50,52,45,49,49,102,48,45,98,99,99,97,45,50,50,50,50,...+1232 more],
	elemBuf: []uint8 len: 0, cap: 0, nil,
	avoidReusing: false,}
(dlv) 

So after getting 36 UUID's we do see a data with a capacity of 1296 and a length of 1296.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link

ti-chi-bot bot commented Dec 31, 2025

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 31, 2025
@tiprow
Copy link

tiprow bot commented Dec 31, 2025

Hi @dveeden. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@dveeden
Copy link
Contributor Author

dveeden commented Dec 31, 2025

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Dec 31, 2025
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 6, 2026
@dveeden dveeden marked this pull request as ready for review January 6, 2026 20:19
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 6, 2026
@codecov
Copy link

codecov bot commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.5455%. Comparing base (2114fbf) to head (9976715).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65365        +/-   ##
================================================
- Coverage   78.3390%   76.5455%   -1.7936%     
================================================
  Files          1940       1953        +13     
  Lines        535314     539223      +3909     
================================================
- Hits         419360     412751      -6609     
- Misses       114433     125663     +11230     
+ Partials       1521        809       -712     
Flag Coverage Δ
integration 41.5622% <100.0000%> (-6.6225%) ⬇️
unit 76.7752% <0.0000%> (+0.2882%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 56.6191% <ø> (ø)
parser ∅ <ø> (∅)
br 49.5181% <ø> (-15.3681%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 7, 2026
Copy link
Contributor

@zanmato1984 zanmato1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 7, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: windtalker, zanmato1984

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 7, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 7, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-01-07 02:59:43.007296904 +0000 UTC m=+757538.825605336: ☑️ agreed by windtalker.
  • 2026-01-07 06:27:07.11475104 +0000 UTC m=+769982.933059471: ☑️ agreed by zanmato1984.

@dveeden
Copy link
Contributor Author

dveeden commented Jan 7, 2026

/retest

@dveeden
Copy link
Contributor Author

dveeden commented Jan 7, 2026

/retest

1 similar comment
@dveeden
Copy link
Contributor Author

dveeden commented Jan 7, 2026

/retest

@ti-chi-bot ti-chi-bot bot merged commit 34db659 into pingcap:master Jan 7, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Precise space reservation for UUID generation

3 participants