-
Notifications
You must be signed in to change notification settings - Fork 6.1k
planner: add the prefix index as candidate for topn optimization #65533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Skipping CI for Draft Pull Request. |
|
Hi @elsa0520. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. DetailsInstructions 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. |
|
/ok-to-test |
| type PartialOrderInfo struct { | ||
| // SortItems are the ORDER BY columns from TopN | ||
| SortItems []*SortItem | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type PartialOrderInfo []*SortItem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, it maybe need to add a new field named "limit number" inside of struct PartialOrderInfo.
Because we need to know which is order by column , also we need to know What number of the limit N we can short cut.
So I keep the struct instead of use []*sortItem directly
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the case where there's a projection?
And, I think that we can not support the partial order with txn's dirty writes in the first implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, projection is possible. Is it expected that we bail out for Projection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dirty write already fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that we bail out for Projection?
There can indeed be projection between top and ds. However, the presence of projection doesn't necessarily guarantee the use of a prefix index.
For example, consider the query select fn(a) as a1 from t order by fn(a) limit 10.
In this case, whether an order-preserving index can be used depends entirely on the scalar function of fn(a). Our current code doesn't actually have this capability.
In other words, this query can't even use the index a, let alone the prefix (a).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if select a+b, a, b from t order by a,b limit 10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already tried this case. The topn is under the projection because we have a rule named "PushDownTopN(topN)"
pkg/planner/core/find_best_task.go
Outdated
| continue | ||
| } | ||
| // Check if candidate path need to consider partial order optimization | ||
| considerPartialOrderIndex := ds.SCtx().GetSessionVars().OptPartialOrderedIndexForTopN && prop.PartialOrderInfo != nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make the judge here more precise? For example, just call matchPartialOrderProperty to check whether the index can match the partial order property, matchPartialOrderIndex := ds.SCtx().GetSessionVars().OptPartialOrderedIndexForTopN && matchPartialOrderProperty(path, prop) != nil. Then we can avoid putting some unnecessary indexes into our index candidates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, if we enable OptPartialOrderedIndexForTopN and there is a PartialOrderInfo, then all indexes are going to be put into our candidates, the if-branch below seems to stop working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the partial order skyline pruning at the begin of here ~
qw4990
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Others LGTM, please address these comments before merging it.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: qw4990 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 |
[LGTM Timeline notifier]Timeline:
|
| } | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, projection is possible. Is it expected that we bail out for Projection?
pkg/planner/core/find_best_task.go
Outdated
| type PartialOrderMatchResult struct { | ||
| // Matched indicates whether the index can provide partial order | ||
| Matched bool | ||
| // PrefixColId is the last and only one prefix column ID of index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of this field? The comment is hard to understand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
pkg/planner/core/find_best_task.go
Outdated
| if !(len(path.AccessConds) > 0 || !prop.IsSortItemEmpty() || path.Forced || path.IsSingleScan || !considerPartialOrderIndex) { | ||
| continue | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is counter intuitive, hard to follow.
Should be this:
if len(path.AccessConds) > 0 || !prop.IsSortItemEmpty() || path.Forced || path.IsSingleScan || !considerPartialOrderIndex {
currentCandidate = getIndexCandidate(ds, path, prop)
} else {
continue
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is counter intuitive, hard to follow. Should be this:
if len(path.AccessConds) > 0 || !prop.IsSortItemEmpty() || path.Forced || path.IsSingleScan || !considerPartialOrderIndex { currentCandidate = getIndexCandidate(ds, path, prop) } else { continue }
Agree with you change... but the origin logic is like that .... I can change it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
pkg/planner/core/find_best_task.go
Outdated
| // We will use index to generate physical plan if any of the following conditions is satisfied: | ||
| // 1. This path's access cond is not nil. | ||
| // 2. We have a non-empty prop to match. | ||
| // 3. This index is forced to choose. | ||
| // 4. The needed columns are all covered by index columns(and handleCol). | ||
| // 5. Has PartialOrderInfo physical property to be considered for partial order optimization (new condition). | ||
| if !(len(path.AccessConds) > 0 || !prop.IsSortItemEmpty() || path.Forced || path.IsSingleScan || !considerPartialOrderIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, is this wrong? Should !considerPartialOrderIndex be considerPartialOrderIndex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is so hard to understand, let me rephrase it in a way that's human-readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
| // partialOrderInfo: sortItems: [a, b] | ||
| // The partialOrderInfo property will pass through to the datasource and try to matchPartialOrderProperty such as: | ||
| // index: (a, b(10) ) | ||
| PartialOrderInfo *PartialOrderInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we extend PhysicalProperty.HashCode() to incorporate PartialOrderInfo (columns + order direction) so task caching is correct?
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #65533 +/- ##
================================================
- Coverage 78.4730% 76.2034% -2.2697%
================================================
Files 1938 1922 -16
Lines 534229 546361 +12132
================================================
- Hits 419226 416346 -2880
- Misses 113483 129970 +16487
+ Partials 1520 45 -1475
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/test mysql-test |
|
@elsa0520: The specified target(s) for Use DetailsIn response to this:
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. |
|
[FORMAT CHECKER NOTIFICATION] Notice: To remove the For example:
📖 For more info, you can check the "Contribute Code" section in the development guide. |
|
@elsa0520: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
What problem does this PR solve?
Issue Number: Fix #63280
Problem Summary:
What changed and how does it work?
The planner part 1 of the partial order by enhancement
Check List
Tests
I will add more test after finish the part2 of this enhancement
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.