Skip to content

Conversation

@wddevries
Copy link
Contributor

What problem does this PR solve?

Issue Number: ref #65895
Problem Summary:

There is no universal way to disable the plan cache for a query during optimization. The two existing methods have limitations:

  1. SetSkipPlanCache disables the plan cache preemptively, even if the problematic plan is not ultimately selected.
  2. isPhysicalPlanCacheable walks the final plan to check cacheability, but not all conditions can be discovered at this stage since context from earlier optimization phases may be lost.

What changed and how does it work?

This PR introduces a general framework for tracking and propagating non-cacheable reasons through the planner:

  1. Plan interface changes (pkg/planner/core/base/plan_base.go): Added SetNoncacheableReason and GetNoncacheableReason methods to the Plan interface. Any component in the planner can now mark a plan as non-cacheable with a specific reason.
  2. Base Plan implementation (pkg/planner/core/operator/baseimpl/plan.go): Added NotCachableReason field to the base Plan struct with getter/setter implementations. The setter only sets the reason if one isn't already set, preserving the first/root cause.
  3. AccessPath support (pkg/planner/util/path.go): Added NoncacheableReason field to AccessPath as one source of non-cacheable reasons, allowing path-level decisions to propagate to plans.
  4. Propagation during plan building: Updated plan building functions to propagate NoncacheableReason from AccessPath to resulting physical plans (index scans, point gets, index merge paths, etc.).
  5. Plan cache check (pkg/planner/core/plan_cacheable_checker.go): Added check in isPhysicalPlanCacheable to return false with the specific reason if a plan has a non-cacheable reason set.
  6. Refactoring (pkg/planner/core/indexmerge_unfinished_path.go): Changed unfinishedAccessPath to store the full AccessPath instead of just the index, enabling NoncacheableReason to flow through index merge path building.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
  • This is framework/infrastructure code that will be exercised by follow-up PRs that set actual non-cacheable reasons

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 (​https://pingcap.github.io/tidb-dev-guide/contribute-to-tidb/release-notes-style-guide.html​) 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. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 29, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jan 29, 2026

[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 elsa0520 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
Copy link

tiprow bot commented Jan 29, 2026

Hi @wddevries. 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 Jan 29, 2026

Codecov Report

❌ Patch coverage is 85.41667% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.7216%. Comparing base (245c8e1) to head (ac8a886).
⚠️ Report is 23 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #65896        +/-   ##
================================================
- Coverage   77.7927%   77.7216%   -0.0712%     
================================================
  Files          2001       1923        -78     
  Lines        545191     534877     -10314     
================================================
- Hits         424119     415715      -8404     
+ Misses       119410     119138       -272     
+ Partials       1662         24      -1638     
Flag Coverage Δ
integration 41.4777% <74.4680%> (-6.6918%) ⬇️
unit 76.8050% <85.4166%> (+0.3755%) ⬆️

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

Components Coverage Δ
dumpling 56.7974% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8701% <ø> (-12.1038%) ⬇️
🚀 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.
@wddevries
Copy link
Contributor Author

/test unit-test

@tiprow
Copy link

tiprow bot commented Jan 29, 2026

@wddevries: 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:

/test unit-test

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.

@wddevries
Copy link
Contributor Author

/test unit-test

@tiprow
Copy link

tiprow bot commented Jan 29, 2026

@wddevries: 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:

/test unit-test

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.

@wddevries
Copy link
Contributor Author

/test unit-test

@tiprow
Copy link

tiprow bot commented Jan 29, 2026

@wddevries: 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:

/test unit-test

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

1 participant