Skip to content

planner, sessionctx: remove index join build v1#66871

Open
AilinKid wants to merge 3 commits intopingcap:masterfrom
AilinKid:remove-index-join-build-v1
Open

planner, sessionctx: remove index join build v1#66871
AilinKid wants to merge 3 commits intopingcap:masterfrom
AilinKid:remove-index-join-build-v1

Conversation

@AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Mar 10, 2026

What problem does this PR solve?

Issue Number: ref #65781

Problem Summary:

Index join build v1 and the tidb_opt_index_join_build_v2 switch are still kept in the planner and session variable layer even though the refactored index join build path is already the only path we want to keep. The extra path adds dead code, extra maintenance cost, and one unnecessary user-visible variable.

What changed and how does it work?

  • remove the tidb_opt_index_join_build_v2 sysvar and the matching SessionVars gate
  • keep the refactored index join build path as the single planner implementation
  • delete v1-only planner attach/build helpers and update the regression test to run on the default path

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.

Test commands:

  • make failpoint-enable
  • env GOCACHE=/tmp/codex-go-build GOTMPDIR=/tmp/codex-go-tmp go test -run TestJoinRegression -tags=intest,deadlock ./pkg/planner/core
  • env GOCACHE=/tmp/codex-go-build GOTMPDIR=/tmp/codex-go-tmp go test -run 'TestDefaultValuesAreSettable|TestSysVarNameIsLowerCase|TestSettersandGetters' -tags=intest,deadlock ./pkg/sessionctx/variable/tests
  • env GOCACHE=/tmp/codex-go-build GOTMPDIR=/tmp/codex-go-tmp go test -run TestJoinRegression -tags=intest,deadlock ./pkg/planner/core/casetest/join
  • make failpoint-disable
  • env GOCACHE=/tmp/codex-go-build GOTMPDIR=/tmp/codex-go-tmp GOLANGCI_LINT_CACHE=/tmp/codex-golangci-lint-cache make lint

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.

Remove the deprecated system variable `tidb_opt_index_join_build_v2` and the legacy index join build v1 code path.

Summary by CodeRabbit

  • Improvements
    • Index-join optimization unified to a single, always-enabled implementation for more consistent planning and execution.
  • Behavior Change
    • The index-join build setting is now fixed to ON and cannot be turned off.
  • Tests
    • Added compatibility tests ensuring the index-join build setting remains ON across global/session scopes and rejects attempts to disable it.

@ti-chi-bot ti-chi-bot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Mar 10, 2026
@pantheon-ai
Copy link

pantheon-ai bot commented Mar 10, 2026

Failed to Create Project

We encountered an error while creating your project. Please try again or contact support if the issue persists.

@ti-chi-bot ti-chi-bot bot added sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 10, 2026
@tiprow
Copy link

tiprow bot commented Mar 10, 2026

Hi @AilinKid. 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
Copy link

coderabbitai bot commented Mar 10, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 2c16e8f4-e747-4f07-99d0-cb1733d464e1

📥 Commits

Reviewing files that changed from the base of the PR and between 13b8731 and 56b3ed2.

📒 Files selected for processing (4)
  • pkg/session/test/vars/vars_test.go
  • pkg/sessionctx/vardef/tidb_vars.go
  • pkg/sessionctx/variable/sysvar.go
  • pkg/sessionctx/variable/tests/variable_test.go
 __________________________________________________________________
< Ah yes, the classic pattern: 'parse first, ask questions never'. >
 ------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

✏️ Tip: You can disable in-progress messages and the fortune message in your review settings.

Tip

CodeRabbit can use TruffleHog to scan for secrets in your code with verification capabilities.

Add a TruffleHog config file (e.g. trufflehog-config.yml, trufflehog.yml) to your project to customize detectors and scanning behavior. The tool runs only when a config file is present.

📝 Walkthrough

Walkthrough

This PR consolidates the index join build optimizer by removing the V1/V2 feature flag logic and simplifying plan construction. The V2 approach becomes the default behavior, with conditional enumeration paths unified and index-join runtime details deferred to a single completion function, resulting in substantial code reduction.

Changes

Cohort / File(s) Summary
Session Configuration Cleanup
pkg/sessionctx/vardef/tidb_vars.go, pkg/sessionctx/variable/session.go, pkg/sessionctx/variable/sysvar.go
Removed feature flag session variables: TiDBOptIndexJoinBuild, DefTiDBOptIndexJoinBuild, and EnhanceIndexJoinBuildV2 field, eliminating the V1/V2 conditional logic from session state.
Index Join Planner Refactoring
pkg/planner/core/exhaust_physical_plans.go
Eliminated V1/V2 conditional enumeration paths and large blocks of index-join plan constructors. Simplified enumeration to unconditionally call tryToEnumerateIndexJoin and deferred runtime details to completePhysicalIndexJoin. Removed unused imports (aggregation, mysql).
Index Join Task Attachment
pkg/planner/core/task.go
Replaced separate V1/V2 task attachment implementations with unified indexHashJoinAttach2Task and indexJoinAttach2Task helpers. Updated attach2Task4PhysicalIndexHashJoin and attach2Task4PhysicalIndexJoin to call unified helpers directly, removing conditional logic.
Index Join Path Removal
pkg/planner/core/index_join_path.go
Removed getBestIndexJoinPathResult function that previously enumerated and selected optimal inner-child access paths for index joins, eliminating internal path-building logic.
Comment Clarifications
pkg/planner/core/find_best_task.go, pkg/planner/core/casetest/join/join_test.go
Updated documentation to reflect simplified index-join flow and deferred runtime handling. Removed test configuration that disabled V2 optimizer to run with default settings.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Suggested labels

size/XL, ok-to-test

Suggested reviewers

  • qw4990
  • guo-shaoge
  • winoros

Poem

🐰 The V2 path now shines alone,
Feature flags have flown,
Eight hundred lines of branching gone,
Unified flows carry on! ✨
Simpler plans, cleaner code shown.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.83% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: removal of the legacy index join build v1 code path and system variable.
Description check ✅ Passed The description follows the required template, includes issue reference, problem summary, detailed changes explanation, test commands, side effect disclosure, and release notes.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

ti-chi-bot bot commented Mar 10, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-03-10 08:18:45.000317489 +0000 UTC m=+338156.512375150: ☑️ agreed by hawkingrei.

@hawkingrei
Copy link
Member

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Mar 10, 2026
@AilinKid
Copy link
Contributor Author

/ok-to-test

Copy link
Member

@0xPoe 0xPoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

s.AnalyzeVersion = tidbOptPositiveInt32(val, vardef.DefTiDBAnalyzeVersion)
return nil
}},
{Scope: vardef.ScopeGlobal | vardef.ScopeSession, Name: vardef.TiDBOptIndexJoinBuild, Value: BoolToOnOff(vardef.DefTiDBOptIndexJoinBuild), Type: vardef.TypeBool, SetSession: func(s *SessionVars, val string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that when users try to set it, they will see a message indicating it doesn't exist? Typically, we don't directly remove the variable I guess, we could report an error stating that it is always on?

Copy link
Member

@0xPoe 0xPoe Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also means that once a user upgrades from the default disabled version, they will observe a change in behavior. I'm not sure if this is an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does analyze v1 did, it the old variable is still there and settable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also means that once a user upgrades from the default disabled version, they will observe a change in behavior. I'm not sure if this is an issue.

This could be included in our release notes document to notify the user, I suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, addressed

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/planner/core/find_best_task.go (1)

692-694: Move this rationale next to the enumerationContainIndexJoin(...) guard.

The note explains why index-join candidates must keep the enforced branch alive, but it currently sits inside the branch that only runs after both enumerations are known not to contain index joins. Rewording or moving it closer to Lines 681-688 would make the condition much easier to follow. As per coding guidelines, "Comments SHOULD explain non-obvious intent, constraints, invariants, concurrency guarantees, SQL/compatibility contracts, or important performance trade-offs, and SHOULD NOT restate what the code already makes clear".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/planner/core/find_best_task.go` around lines 692 - 694, Move and reword
the current rationale comment so it sits immediately adjacent to the
enumerationContainIndexJoin(...) guard (near the code that checks whether either
enumeration contains an index-join) instead of inside the later branch where
both enumerations are known not to contain index joins; update the text to
explain concisely that when an enumeration may contain an index-join the
enforced branch must be preserved because emptying the sort item can enable
additional index-join candidates or make hints applicable only after the inner
plan is built, and remove any redundancy with the surrounding code so the
comment documents the intent/constraint (enumerationContainIndexJoin, enforced
branch, sort item, index-join candidates) rather than restating obvious
implementation details.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/planner/core/find_best_task.go`:
- Around line 692-694: Move and reword the current rationale comment so it sits
immediately adjacent to the enumerationContainIndexJoin(...) guard (near the
code that checks whether either enumeration contains an index-join) instead of
inside the later branch where both enumerations are known not to contain index
joins; update the text to explain concisely that when an enumeration may contain
an index-join the enforced branch must be preserved because emptying the sort
item can enable additional index-join candidates or make hints applicable only
after the inner plan is built, and remove any redundancy with the surrounding
code so the comment documents the intent/constraint
(enumerationContainIndexJoin, enforced branch, sort item, index-join candidates)
rather than restating obvious implementation details.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a13c294a-58d7-4a71-adc6-ad696537123e

📥 Commits

Reviewing files that changed from the base of the PR and between 88db262 and 13b8731.

📒 Files selected for processing (8)
  • pkg/planner/core/casetest/join/join_test.go
  • pkg/planner/core/exhaust_physical_plans.go
  • pkg/planner/core/find_best_task.go
  • pkg/planner/core/index_join_path.go
  • pkg/planner/core/task.go
  • pkg/sessionctx/vardef/tidb_vars.go
  • pkg/sessionctx/variable/session.go
  • pkg/sessionctx/variable/sysvar.go
💤 Files with no reviewable changes (5)
  • pkg/planner/core/casetest/join/join_test.go
  • pkg/sessionctx/variable/session.go
  • pkg/sessionctx/vardef/tidb_vars.go
  • pkg/sessionctx/variable/sysvar.go
  • pkg/planner/core/index_join_path.go

@hawkingrei
Copy link
Member

/retest

2 similar comments
@hawkingrei
Copy link
Member

/retest

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 10, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hawkingrei
Once this PR has been reviewed and has the lgtm label, please assign benmeadowcroft 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

@hawkingrei
Copy link
Member

/retest

@ti-chi-bot
Copy link

ti-chi-bot bot commented Mar 10, 2026

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

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/build 13b8731 link true /test build
idc-jenkins-ci-tidb/check_dev 56b3ed2 link true /test check-dev

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.

@hawkingrei
Copy link
Member

/retest

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

Labels

needs-1-more-lgtm Indicates a PR needs 1 more LGTM. ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants