planner, executor: code preparation for supporting access path keep order with IN Conditions using merge sort#66713
Conversation
…order` with `IN` Conditions using merge sort (pingcap#63457) ref pingcap#63449
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds runtime validation that ByItems are Column expressions in multiple executor readers, extracts merge-sort decision logic into a shared helper used by index readers, replaces boolean property-matching with an explicit enum result, and adds extensive integration tests for grouped range order-by scenarios. Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pkg/planner/core/find_best_task.go (1)
883-886: Remove unreachable nil-check in vector property matching.
Line 883already guaranteespath.Indexandpath.Index.VectorInfoare non-nil, so the guard atLine 884can never execute. This dead branch makes future vector-path edits harder to reason about.♻️ Proposed cleanup
- if prop.VectorProp.VectorHelper != nil && path.Index != nil && path.Index.VectorInfo != nil { - if path.Index == nil || path.Index.VectorInfo == nil { - return property.PropNotMatched - } + if prop.VectorProp.VectorHelper != nil && path.Index != nil && path.Index.VectorInfo != nil {🤖 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 883 - 886, The inner nil-check is unreachable because the outer condition already ensures prop.VectorProp.VectorHelper != nil && path.Index != nil && path.Index.VectorInfo != nil; remove the redundant guard that checks "if path.Index == nil || path.Index.VectorInfo == nil" and its early return of property.PropNotMatched from the block in find_best_task.go so the vector property matching branch is simplified (identify the block by the symbols prop.VectorProp.VectorHelper, path.Index, path.Index.VectorInfo, and the return property.PropNotMatched).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/executor/builder.go`:
- Around line 1377-1392: The function collectColIdxFromByItems currently builds
colIdxs but silently ignores ByItems whose column IDs aren't found in cols;
change it to fail fast by detecting when a column from byItems (item.Expr as
*expression.Column) has no matching c.ID in cols and immediately return an error
(include the missing column ID or another identifying detail in the message)
instead of returning a partial colIdxs; update the loop in
collectColIdxFromByItems to check after scanning cols and return an
errors.Errorf when not found.
In `@tests/integrationtest/t/planner/core/grouped_ranges_order_by.test`:
- Around line 63-70: The EXPLAIN queries reference table t2 but the subsequent
SELECTs query table t, breaking the plan/result pairing; update the three SELECT
statements that currently use "from t" to use "from t2" so each "explain format
= 'brief' select ... from t2 ..." is executed against the same table (e.g.
change the SELECTs for "select a,c from t", "select a,c from t" (with d > 60)
and "select b,c from t" to use t2).
---
Nitpick comments:
In `@pkg/planner/core/find_best_task.go`:
- Around line 883-886: The inner nil-check is unreachable because the outer
condition already ensures prop.VectorProp.VectorHelper != nil && path.Index !=
nil && path.Index.VectorInfo != nil; remove the redundant guard that checks "if
path.Index == nil || path.Index.VectorInfo == nil" and its early return of
property.PropNotMatched from the block in find_best_task.go so the vector
property matching branch is simplified (identify the block by the symbols
prop.VectorProp.VectorHelper, path.Index, path.Index.VectorInfo, and the return
property.PropNotMatched).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a38ba854-a5f7-48cc-99c0-d2013be66cdb
📒 Files selected for processing (6)
pkg/executor/builder.gopkg/executor/distsql.gopkg/planner/core/find_best_task.gopkg/planner/property/physical_property.gotests/integrationtest/r/planner/core/grouped_ranges_order_by.resulttests/integrationtest/t/planner/core/grouped_ranges_order_by.test
| func collectColIdxFromByItems(byItems []*plannerutil.ByItems, cols []*model.ColumnInfo) ([]int, error) { | ||
| var colIdxs []int | ||
| for _, item := range byItems { | ||
| col, ok := item.Expr.(*expression.Column) | ||
| if !ok { | ||
| return nil, errors.Errorf("Not support non-column in orderBy pushed down") | ||
| } | ||
| for i, c := range cols { | ||
| if c.ID == col.ID { | ||
| colIdxs = append(colIdxs, i) | ||
| break | ||
| } | ||
| } | ||
| } | ||
| return colIdxs, nil | ||
| } |
There was a problem hiding this comment.
Fail fast when a ByItems column ID is not present in cols.
This helper currently returns partial colIdxs if a column is not found, which can silently degrade ordering (downstream compare iterates usedIndex, see pkg/executor/union_scan.go Line 305). Return an explicit error on the first missing mapping.
💡 Proposed fix
func collectColIdxFromByItems(byItems []*plannerutil.ByItems, cols []*model.ColumnInfo) ([]int, error) {
- var colIdxs []int
+ colIdxs := make([]int, 0, len(byItems))
for _, item := range byItems {
col, ok := item.Expr.(*expression.Column)
if !ok {
return nil, errors.Errorf("Not support non-column in orderBy pushed down")
}
+ found := false
for i, c := range cols {
if c.ID == col.ID {
colIdxs = append(colIdxs, i)
+ found = true
break
}
}
+ if !found {
+ return nil, errors.Errorf("Not found order by related columns in indexMerge.columns")
+ }
}
return colIdxs, nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| func collectColIdxFromByItems(byItems []*plannerutil.ByItems, cols []*model.ColumnInfo) ([]int, error) { | |
| var colIdxs []int | |
| for _, item := range byItems { | |
| col, ok := item.Expr.(*expression.Column) | |
| if !ok { | |
| return nil, errors.Errorf("Not support non-column in orderBy pushed down") | |
| } | |
| for i, c := range cols { | |
| if c.ID == col.ID { | |
| colIdxs = append(colIdxs, i) | |
| break | |
| } | |
| } | |
| } | |
| return colIdxs, nil | |
| } | |
| func collectColIdxFromByItems(byItems []*plannerutil.ByItems, cols []*model.ColumnInfo) ([]int, error) { | |
| colIdxs := make([]int, 0, len(byItems)) | |
| for _, item := range byItems { | |
| col, ok := item.Expr.(*expression.Column) | |
| if !ok { | |
| return nil, errors.Errorf("Not support non-column in orderBy pushed down") | |
| } | |
| found := false | |
| for i, c := range cols { | |
| if c.ID == col.ID { | |
| colIdxs = append(colIdxs, i) | |
| found = true | |
| break | |
| } | |
| } | |
| if !found { | |
| return nil, errors.Errorf("Not found order by related columns in indexMerge.columns") | |
| } | |
| } | |
| return colIdxs, nil | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@pkg/executor/builder.go` around lines 1377 - 1392, The function
collectColIdxFromByItems currently builds colIdxs but silently ignores ByItems
whose column IDs aren't found in cols; change it to fail fast by detecting when
a column from byItems (item.Expr as *expression.Column) has no matching c.ID in
cols and immediately return an error (include the missing column ID or another
identifying detail in the message) instead of returning a partial colIdxs;
update the loop in collectColIdxFromByItems to check after scanning cols and
return an errors.Errorf when not found.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release-8.5 #66713 +/- ##
================================================
Coverage ? 55.1250%
================================================
Files ? 1819
Lines ? 653808
Branches ? 0
================================================
Hits ? 360412
Misses ? 266697
Partials ? 26699
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
/retest |
5 similar comments
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
/retest |
|
[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 |
Manual cherry-pick of #63457
What problem does this PR solve?
Issue Number: ref #63449
Problem Summary:
This PR doesn't contain actual logic changes. It's for reducing modifications for the next PR.
What changed and how does it work?
isMatchProp()(pkg/planner/core/find_best_task.go)matchProperty()booltoPhysicalPropMatchResult, which is a newly introducedenum.PhysicalPropMatchResult(pkg/planner/property/physical_property.go)PropNotMatched: corresponds to previousisMatchProp() == false.PropMatched: corresponds to previousisMatchProp() == true.collectColIdxFromByItems()for later use.ByItemsmust beColumns.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
Summary by CodeRabbit
Bug Fixes
Performance
Refactor
Tests