planner: support using nested IN to build IndexMerge path#68962
Conversation
|
@time-and-fate 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. |
📝 WalkthroughWalkthroughRecognize scalar ChangesIndex Merge IN-Predicate Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
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)
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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #68962 +/- ##
================================================
- Coverage 76.3186% 75.0967% -1.2220%
================================================
Files 2041 2028 -13
Lines 562849 570593 +7744
================================================
- Hits 429559 428497 -1062
- Misses 132377 141917 +9540
+ Partials 913 179 -734
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
IN to build IndexMerge path
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qw4990, winoros 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 |
|
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: ref #65822
Problem Summary:
For queries like
SELECT * FROM t1 WHERE e = 1 AND (a IN (1,2,3) OR b IN (2,3,4) OR c IN (3,4,5)), TiDB previously could not build an IndexMerge path when there are IN expressions in the nested OR list. The query would fall back to a plain IndexLookUp with a residual Selection, which is much less efficient.This is the first optimization described in the issue.
What changed and how does it work?
checkAccessFilter4IdxCol()(pkg/planner/core/indexmerge_path.go): Add support forast.Inexpressions in the non-virtual column branch. Previously onlyast.EQwas recognized, so IN expressions likea IN (1,2,3)could not be collected as partial access filters in the "gradual collection" path (case 3 ininitUnfinishedPathsFromExpr()). Now they are collected and later combined with top-level AND conditions (e.g.,e = 1) byhandleTopLevelANDList()to build valid ranges for composite indexes.eqOnNonMVColTptoeqOrInOnNonMVColTpto reflect that it now covers both EQ and IN expressions.After this fix, the plan becomes:
Check List
Tests
Side effects
Documentation
Release note
Summary by CodeRabbit
Performance Improvements
Behavior Changes
Testing