Skip to content

Conversation

@tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #64256

Problem Summary:

Maybe they are the same leak, but maybe not.

From the Go heap profile, I can see the packet data memory is leak

image-20260127-150307

And using goref https://github.com/cloudwego/goref, stmtsummary is the root refercing data:

image-20260129-140806

What changed and how does it work?

Key path (from packet allocation to being held by stmt summary):

  • pkg/server/internal/packetio.go:178-190
    data := make([]byte, length) allocates the full packet payload.
  • pkg/server/conn.go:1400
    dataStr := string(hack.String(data)) uses unsafe zero-copy to convert []byte to string.
  • pkg/parser/lexer.go:107
    stmtText() takes a substring of the original SQL: text := s.r.s[s.stmtStartPos:endPos], without copying.
  • pkg/parser/ast/base.go:52
    The AST node stores text (still referencing the original underlying array).
  • pkg/executor/select.go:1047
    sc.OriginalSQL = s.Text() puts the AST text into StmtCtx.OriginalSQL.
  • pkg/util/stmtsummary/statement_summary.go:660
    sampleSQL: formatSQL(sei.LazyInfo.GetOriginalSQL())
  • pkg/util/stmtsummary/statement_summary.go:942
    formatSQL returns the original string directly when length <= tidb_stmt_summary_max_sql_length.

Result:

stmt summary keeps the original SQL string, and that string actually points to the packet’s underlying buffer.
For multi-statement or large SQL, even if a single statement is short, the substring still keeps the entire packet alive.

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 ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 2, 2026
@tiprow
Copy link

tiprow bot commented Feb 2, 2026

Hi @tiancaiamao. 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.

@codecov
Copy link

codecov bot commented Feb 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.5191%. Comparing base (c2202e1) to head (2926ec9).
⚠️ Report is 15 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65977        +/-   ##
================================================
- Coverage   77.7795%   77.5191%   -0.2605%     
================================================
  Files          2001       1923        -78     
  Lines        545624     536043      -9581     
================================================
- Hits         424384     415536      -8848     
- Misses       119578     120496       +918     
+ Partials       1662         11      -1651     
Flag Coverage Δ
integration 41.6406% <50.0000%> (-6.5192%) ⬇️
unit 76.7034% <100.0000%> (+0.2916%) ⬆️

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

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8835% <ø> (-12.1072%) ⬇️
🚀 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.

@tiancaiamao
Copy link
Contributor Author

/retest

@tiprow
Copy link

tiprow bot commented Feb 3, 2026

@tiancaiamao: 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.

Details

In response to this:

/retest

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.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 3, 2026
Copy link
Member

@YangKeao YangKeao 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 the lgtm label Feb 3, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 3, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: xhebox, YangKeao

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 removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Feb 3, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 3, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-03 09:06:37.844683742 +0000 UTC m=+171468.946082461: ☑️ agreed by xhebox.
  • 2026-02-03 09:08:25.19805292 +0000 UTC m=+171576.299451635: ☑️ agreed by YangKeao.

@ti-chi-bot ti-chi-bot bot merged commit 72d131e into pingcap:master Feb 3, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm 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.

3 participants