Skip to content

planner: allow partial indexes for index join#69604

Open
winoros wants to merge 2 commits into
pingcap:masterfrom
winoros:fix-partial-index-indexjoin
Open

planner: allow partial indexes for index join#69604
winoros wants to merge 2 commits into
pingcap:masterfrom
winoros:fix-partial-index-indexjoin

Conversation

@winoros

@winoros winoros commented Jul 2, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #69524

Problem Summary:

IndexJoin rejected every partial index because partial indexes were treated as undetermined paths. As a result, even when the partial-index predicate was already proven by pushed-down join conditions, IndexJoin could not choose that index.

What changed and how does it work?

This PR allows IndexJoin path construction to consider partial indexes after partial-index predicate checking/pruning has already run. MV indexes remain rejected.

The added tests cover:

  • ordinary partial-index rejection when the predicate is not implied by the join condition
  • IndexJoin using a safe a IS NOT NULL partial index for inner join and left outer join
  • NULL-safe equality (<=>) not using the partial index
  • prepared plan cache correctness with partial index and IndexJoin

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.

Commands:

make bazel_prepare
./tools/check/failpoint-go-test.sh pkg/planner/core/casetest/index -run TestPartialIndexWithPlanCache -count=1
./run-tests.sh -r planner/core/casetest/index/partialindex
make lint
git diff --check

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 an issue that IndexJoin cannot choose a usable partial index.

Summary by CodeRabbit

  • Bug Fixes
    • Improved join planning for queries using partial indexes, including better handling of IndexJoin with prepared statements and cached plans.
    • Fixed planner behavior for cases where partial-index conditions are not proven by the join predicate, while still allowing valid non-partial index use.
    • Added coverage for regular, left, and NULL-safe joins to ensure correct plan selection and query results.

@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

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 do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 2, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 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 ailinkid 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

@ti-chi-bot ti-chi-bot Bot added the sig/planner SIG: Planner label Jul 2, 2026
@winoros winoros marked this pull request as ready for review July 2, 2026 21:31
@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 Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR narrows AccessPath.IsIndexJoinUnapplicable() to reject only MV indexes instead of all "undetermined" paths, enabling partial indexes to be used as IndexJoin inner paths when the join predicate proves the partial-index condition. Tests and fixtures were updated accordingly.

Changes

Partial Index IndexJoin Applicability

Layer / File(s) Summary
Narrowed IsIndexJoinUnapplicable predicate
pkg/planner/util/path.go, pkg/planner/core/exhaust_physical_plans.go
IsIndexJoinUnapplicable() now returns true only for non-table paths with a non-nil MV index, replacing the broader IsUndetermined() check; related comments in exhaust_physical_plans.go updated with no functional change.
Integration test coverage for partial-index IndexJoin
tests/integrationtest/t/planner/core/casetest/index/partialindex.test, tests/integrationtest/r/.../partialindex.result
New plan_tree-based tests verify IndexJoin rejects partial indexes when predicates aren't proven, and allows them for issue 69524 scenarios (inner/left join, = and <=>), with updated expected plan/result fixtures.
Plan cache regression test
pkg/planner/core/casetest/index/index_test.go
Adds a prepared-statement scenario with INL_JOIN over a partial-index inner table, verifying cached plan uses IndexJoin/idx_a and @@last_plan_from_cache equals 1.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • pingcap/tidb#68832: Introduced the partial-index support that this PR further refines by adjusting AccessPath.IsIndexJoinUnapplicable() and related tests.

Suggested labels: approved, lgtm

Suggested reviewers: YangKeao, yudongusa

Poem

A partial index, once shunned and shy,
Now hops the IndexJoin, no longer passed by,
With IS NOT NULL proven true,
The rabbit joins tables, old meets new,
🐇 Hop, hop, plan_tree — the query's in view!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #69524 by allowing proven partial indexes in IndexJoin, covering the positive outer-join case and the negative <=> case.
Out of Scope Changes check ✅ Passed The code and tests stay within the stated planner fix and regression coverage, with no clear unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title is concise and accurately summarizes the main change: enabling partial indexes for IndexJoin.
Description check ✅ Passed The description covers the problem, fix, tests, issue reference, and release note required by the template.
✨ 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.

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.2219%. Comparing base (d5729fb) to head (3dc02cb).
⚠️ Report is 29 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #69604        +/-   ##
================================================
- Coverage   76.3258%   74.2219%   -2.1040%     
================================================
  Files          2041       2049         +8     
  Lines        561051     580361     +19310     
================================================
+ Hits         428227     430755      +2528     
- Misses       131923     148881     +16958     
+ Partials        901        725       -176     
Flag Coverage Δ
integration 41.0505% <100.0000%> (+1.4224%) ⬆️

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

Components Coverage Δ
dumpling 60.4610% <ø> (ø)
parser ∅ <ø> (∅)
br 47.2083% <ø> (-15.5428%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ti-chi-bot

ti-chi-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

@winoros: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-integration-realcluster-test-next-gen 3dc02cb link true /test pull-integration-realcluster-test-next-gen

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner 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.

Partial Index is execluded from IndexJoin's choice

1 participant