-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner: Add control flag to keep or remove ORDER BY in subquery #33173
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Welcome @yuanhsh! |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/7bc1164629562c1fea0c477ca799c1727ed7dda6 |
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.
Rest LGTM
{Scope: ScopeGlobal | ScopeSession, Name: TiDBRemoveOrderbyInSubquery, Value: BoolToOnOff(DefTiDBRemoveOrderbyInSubquery), Type: TypeBool, SetSession: func(s *SessionVars, val string) error { | ||
s.RemoveOrderbyInSubquery = TiDBOptOn(val) | ||
return 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.
I think it's not a global variable in this way. Mark the ScopeGlobal will enable the persistence to GLOBAL_VARIABLES table while the value persisted is never inherited by session (You use DefTiDBRemoveOrderbyInSubquery to init s. RemoveOrderbyInSubquery).
You can just remove ScopeGlobal or implement the full ScopeGlobal logic.
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.
Thanks, I have removed ScopeGlobal
as suggested.
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 think this looked right to me, but I'm not sure because of the force-push.
The Value:
only refers to the default value, once it is persisted it will use what is stored internally. SetSession
is called both when a session value is changed, and on init for new sessions (on init the val will be the global value, which matches the GLOBAL_VARIABLES -- although we have a cache of it internally called sysvar_cache).
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 downside of ScopeSession only is that it doesn't persist, so each time a user wants this optimization to apply -- they'll need to SET sysvar = x
. Which limits its appeal.
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.
You are right, my fault, I mixed the situation, @yuanhsh please ignore my previous 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.
OK, I will revert to previous version.
@morgo Thank you for advising!
We introduced a new contral flag "tidb_remove_orderby_in_subquery" to indicate whether to remove ORDER BY clause in subquery if the subquery doesn't have LIMIT clause. The default value is false, which means no behaviour change in current system, unless users explicitly change this setting.
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.
LGTM
@chrysan: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments. In 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 ti-community-infra/tichi repository. |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 7bc1164
|
/run-mysql-test |
What problem does this PR solve?
Issue Number: close #32900
Unnecessary OrderBy not removed resulting in poor performance.
Problem Summary:
What is changed and how it works?
We introduced a new control flag "tidb_remove_orderby_in_subquery" to indicate
whether to remove ORDER BY clause in subquery if the subquery doesn't have LIMIT
clause. The default value is OFF, which means no behavior change in current
system, unless users explicitly change this setting.
Check List
Tests
Side effects
Documentation
Release note