Skip to content

Fix/ruv2 executor accounting upstream#68577

Closed
meiking wants to merge 2 commits into
pingcap:feature/from-tidb-csefrom
meiking:fix/ruv2-executor-accounting-upstream
Closed

Fix/ruv2 executor accounting upstream#68577
meiking wants to merge 2 commits into
pingcap:feature/from-tidb-csefrom
meiking:fix/ruv2-executor-accounting-upstream

Conversation

@meiking

@meiking meiking commented May 22, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: ref #68576

Problem Summary:

RU v2 executor accounting may undercount TiDB-side compute cost for some common executors because the executor-level mapping relies on concrete type strings, and some entries no longer match the current executor package/type names. In addition, the insert-specific L5 metric should account for inserted rows multiplied by inserted column count, but the old path used affected rows, which does not match the fitted executor-l5-insert-rows model input.

What changed and how does it work?

  • Update the RU v2 executor type mapping to use the current concrete executor types for projection, sort, TopN, hash join, index lookup joins, select lock, expand, window, and merge join executors.
  • Remove stale executor type keys that no longer match current executor concrete types.
  • Record insert L5 RU v2 accounting from InsertValues as rowCount * len(insertColumns) after successful insert execution, including batched insert and insert-select paths.
  • Remove the old affected-rows based insert L5 accounting path.
  • Clarify the executor-l5-insert-rows config/metric comments to describe row-column multiplication.
  • Add tests covering concrete executor type mapping and insert RowsColMultiply accounting.
  • Update the Bazel shard count for pkg/executor/internal/exec tests.

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.

Fix RU v2 executor accounting for common executors and insert row-column cost.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

## Release Notes

* **Bug Fixes**
  * Refined RU v2 metrics calculation for INSERT operations to account for both row count and inserted column count, providing more accurate resource usage measurement.

* **Documentation**
  * Updated configuration and internal documentation to clarify RU v2 weight calculations for insert operations.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/pingcap/tidb/pull/68577?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@ti-chi-bot

ti-chi-bot Bot commented May 22, 2026

Copy link
Copy Markdown

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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.

@ti-chi-bot ti-chi-bot Bot added do-not-merge/invalid-title do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. contribution This PR is from a community contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. labels May 22, 2026
@ti-chi-bot

ti-chi-bot Bot commented May 22, 2026

Copy link
Copy Markdown

Hi @meiking. Thanks for your PR.

I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@ti-chi-bot

ti-chi-bot Bot commented May 22, 2026

Copy link
Copy Markdown

Welcome @meiking!

It looks like this is your first PR to pingcap/tidb 🎉.

I'm the bot to help you request reviewers, add labels and more, See available commands.

We want to make sure your contribution gets all the attention it needs!



Thank you, and welcome to pingcap/tidb. 😃

@ti-chi-bot ti-chi-bot Bot added the first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. label May 22, 2026
@ti-chi-bot

ti-chi-bot Bot commented May 22, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign terry1purcell for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found 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

@tiprow

tiprow Bot commented May 22, 2026

Copy link
Copy Markdown

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

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

This PR refactors RUv2 insert-row metrics from statement-level idempotent snapshots to delta-based per-batch recording, measuring insert rows multiplied by inserted column count, with updated documentation, new stateless recording helpers, wiring through insert execution paths, and expanded executor type mappings.

Changes

RUv2 Insert-Row Metrics Recording Refactor

Layer / File(s) Summary
Clarify RUv2 insert-row metric definition
pkg/config/config.go, pkg/config/config.toml.example, pkg/util/execdetails/ruv2_metrics.go
Documentation and comments specify ExecutorL5InsertRows as insert rows × inserted column count, replacing prior "affected rows" terminology.
Remove old idempotent snapshot recording and introduce new delta-based helper
pkg/executor/adapter.go, pkg/executor/explain.go, pkg/sessionctx/stmtctx/stmtctx.go
Old recordInsertRows2Metrics() calls are removed from FinishExecuteStmt and ExplainExec, the idempotency field InsertRowsAsRUV2Recorded is deleted, and a new stateless helper recordInsertRowsColMultiply2Metrics() replaces the prior logic.
InsertValues state tracking and delta-recording helpers
pkg/executor/insert_common.go
InsertValues struct gains recordRUV2RowsColMultiply and ruv2RecordedRowsColMultiply fields, plus helpers to compute rows×columns with overflow guarding and record deltas.
Wire metric recording into insert execution paths
pkg/executor/insert.go, pkg/executor/insert_common.go
InsertExec.Next enables recording, and both insertRows and insertRowsFromSelect invoke delta-recording after each base.exec batch and final write.
Test insert-row RUv2 metrics recording
pkg/executor/adapter_test.go, pkg/executor/explain_unit_test.go
New tests validate delta-based metrics across INSERT VALUES, partial columns, INSERT SELECT, and batch DML; existing ExplainAnalyze test updated to verify metrics via new recording path.
Expand executor type coverage in RUv2 metric mappings
pkg/executor/internal/exec/executor.go, pkg/executor/internal/exec/executor_test.go
RU v2 executor-to-metric mappings expanded to include HashJoinV1/V2, IndexLookUp join variants, selection, window, etc., with test validation of new mappings.
Build test shard count adjustment
pkg/executor/internal/exec/BUILD.bazel
Bazel exec_test shard count increased from 7 to 8 for test parallelism.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly Related PRs

  • pingcap/tidb#67379: Both PRs modify RUv2 insert-row metric recording in pkg/executor/adapter.go with overlapping changes to the metrics path and helper functions.
  • pingcap/tidb#67220: Both PRs modify ExplainExec.executeAnalyzeExec in pkg/executor/explain.go for RU metrics registration.
  • pingcap/tidb#67030: Main PR refines RUv2 insert-row accounting to measure rows × inserted column count, directly extending the statement-level metrics system added in #67030.

Suggested Labels

sig/planner, release-note, size/XL, ok-to-test

Suggested Reviewers

  • XuHuaiyu
  • disksing
  • cfzjywxk
  • tiancaiamao

Poem

🐰 Insert rows times columns, now we count,
No more snapshots frozen in snapshot mount!
Each batch records its delta true,
RUv2 metrics measured through and through! 🌾

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix/ruv2 executor accounting upstream' is vague and doesn't clearly convey the main changes; it lacks specificity about what executor accounting issues are being fixed. Provide a clearer, more specific title that describes the key fix, such as 'executor, insert: fix RU v2 accounting for executor types and insert row-column costs' or similar.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is complete with issue number, clear problem statement, detailed changes, relevant tests, and release note following the template structure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ti-chi-bot

ti-chi-bot Bot commented May 22, 2026

Copy link
Copy Markdown

[FORMAT CHECKER NOTIFICATION]

Notice: To remove the do-not-merge/invalid-title label, please follow title format, for example pkg [, pkg2, pkg3]: what is changed or *: what is changed.

📖 For more info, you can check the "Contribute Code" section in the development guide.

@meiking meiking closed this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contribution This PR is from a community contributor. do-not-merge/invalid-title do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. first-time-contributor Indicates that the PR was contributed by an external member and is a first-time contributor. needs-ok-to-test Indicates a PR created by contributors and need ORG member send '/ok-to-test' to start testing. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant