executor: fix INSERT regression for tables without generated columns - #68187
Conversation
…ingcap#68129) When PR pingcap#67917 hoisted MutRowFromDatums(row) outside the generated-column evaluation loop to avoid O(G×C) allocations, the call became unconditional. For tables with no generated columns (the common case — e.g. YCSB usertable), MutRowFromDatums is now called on every INSERT row, allocating a full Chunk with N Column objects and copying all datums, all for zero benefit since the loop body never executes. This is the root cause of the ~20% YCSB Workload A regression reported in issue pingcap#68129. Fix: guard the MutRowFromDatums call with an early return when gCols is empty, restoring zero overhead for the common case while preserving the O(G×C)→O(C) optimization for tables that actually have generated columns. Also change the gCols slice initializer from make([]*table.Column, 0) to var gCols []*table.Column to avoid the small slice header allocation when no generated columns are present. Fixes pingcap#68129
|
@bb7133 I've received your pull request and will start the review. I'll conduct a thorough review covering code quality, potential issues, and implementation details. ⏳ This process typically takes 10-30 minutes depending on the complexity of the changes. ℹ️ Learn more details on Pantheon AI. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughfillRow now builds a generated-column slice lazily and returns immediately when no generated columns exist; a new YCSB-like INSERT benchmark was added to exercise the insert path. ChangesGenerated Column Precomputation
Sequence Diagram(s)(Skipped — conditions for diagram generation not met.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.1)Command failed Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #68187 +/- ##
================================================
- Coverage 77.7559% 76.8981% -0.8578%
================================================
Files 1990 1973 -17
Lines 551769 556868 +5099
================================================
- Hits 429033 428221 -812
- Misses 121816 128402 +6586
+ Partials 920 245 -675
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…SERT path Adds a benchmark reproducing the regression from pingcap#68129: an 11-column table (1 VARCHAR PK + 10 VARCHAR fields, no generated columns) modelling the YCSB usertable schema. This exercises the MutRowFromDatums fast-path guard added in the fix and will catch any future regression on plain tables.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cfzjywxk, tiancaiamao The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
|
/retest |
494845e to
09434ba
Compare
|
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: close #68129
Problem Summary:
PR #67917 introduced a performance regression in
INSERTstatements. InfillRow()insideinsert_common.go, the code unconditionally callsMutRowFromDatums(row)— which allocates aChunkplus N*Columnobjects — even when the table has zero virtual generated columns (gColsis empty). This causes unnecessary heap allocations on every single inserted row, increasing GC pressure and reducing throughput.For YCSB Workload A (mixed read/write) against an 11-column table with no generated columns (the typical
usertableschema), this regression measured at −23.8% OPS compared to the pre-PR baseline.What changed and how does it work?
Two minimal changes in
pkg/executor/insert_common.go:Lazy slice initialization: Changed
gCols := make([]*table.Column, 0)tovar gCols []*table.Column, avoiding an unnecessary heap allocation of an empty slice header on every call.Early return when no generated columns: Added a fast path immediately before the
MutRowFromDatumscall:When
gColsis empty (the common case for tables without virtual generated columns), we skipMutRowFromDatumsentirely and return the row directly.These changes restore pre-regression performance for the common case while leaving the generated-column path fully intact.
Check List
Tests
BenchmarkInsertYCSBLikeinpkg/executor/bench_gencol_test.go)Benchmark results (go-ycsb Workload A, 8 threads, 30 s,
tidb-server --store=unistore):Side effects:
Documentation:
Release note
Summary by CodeRabbit