-
Notifications
You must be signed in to change notification settings - Fork 6.1k
planner: Show Execution Plans for Scalar Subqueries | tidb-test=pr/2585 #63047
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
Conversation
pkg/expression/explain.go
Outdated
| case *Constant: | ||
| v := expr.StringWithCtx(ctx, errors.RedactLogDisable) | ||
| redact.WriteRedact(builder, v, redactMode) | ||
| // For Projection operators, show only the subquery reference without the constant value |
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.
Why?
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.
Since I think showing the column mapping is sufficient. For example: (ScalarQueryCol#14) -> Column#15 vs (ScalarQueryCol#14) -> 55 -> Column#15.
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.
Before your pr, it will show 55?
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.
Yes, what I’m thinking is that, rather than the exact numbers, what we really need to know is which subquery influenced that operator, or in other words, their causal relationship.
Before:
55 -> Column#15
After this pr:
ScalarQueryCol#14 -> Column#15
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.
Maybe append the constant value after ScalarQueryCol#14? like
ScalarQueryCol#14(55) -> Column#15
time-and-fate
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.
- I think we also need to update
handleExistSubquery() - Please fix the CI.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #63047 +/- ##
================================================
+ Coverage 72.7588% 73.7962% +1.0374%
================================================
Files 1835 1839 +4
Lines 496690 503619 +6929
================================================
+ Hits 361386 371652 +10266
+ Misses 113324 110176 -3148
+ Partials 21980 21791 -189
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
/retest |
|
/retest |
1 similar comment
|
/retest |
| for _, arg := range x.GetArgs() { | ||
| if c, ok := arg.(*Constant); ok && c.SubqueryRefID > 0 { | ||
| subqRef = c.SubqueryRefID | ||
| break |
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 happens when there are more than 1 constant arguments with valid SubqueryRefID ?
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.
Will output like:
ScalarSubQuery N/A root Output: ScalarQueryCol#14, ScalarQueryCol#15, ScalarQueryCol#16
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 I mean is during constant folding, if a function has more than 1 arguments which are coming from scalar subquery, then that is that looks like? In your code logic, it seems only display the first argument's source?
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, the in list case actually won’t reach this logic because the earlier call will exit in advance. For eq, le, and similar cases, only one SubqueryRefID > 0, so that’s fine. For + - * /, (select a from t where b = sub1+sub2-sub3) If we display all the subqueries that contribute to it, it would look really messy, so we just take the first one.
pkg/expression/explain.go
Outdated
| case *Constant: | ||
| v := expr.StringWithCtx(ctx, errors.RedactLogDisable) | ||
| redact.WriteRedact(builder, v, redactMode) | ||
| // For Projection operators, show only the subquery reference without the constant value |
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.
Before your pr, it will show 55?
|
/retest |
1 similar comment
|
/retest |
| if expr.SubqueryRefID > 0 { | ||
| return fmt.Sprintf("ScalarQueryCol#%d(%s)", expr.SubqueryRefID, valueStr) | ||
| } |
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 behavior here is different from (*Constant).StringWithCtx() when it's RedactLogMarker. ‹› is not added here.
|
/retest |
windtalker
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.
lgtm
[LGTM Timeline notifier]Timeline:
|
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: time-and-fate, windtalker 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 |
|
/retest |
2 similar comments
|
/retest |
|
/retest |
What problem does this PR solve?
Issue Number: close #63045
Problem Summary:
For actually executed SQL statements, the execution plans of subqueries that were pre-executed are not recorded or displayed. As a result, in slow query logs, statement summary, or EXPLAIN ANALYZE, these parts of the plan are missing.
This makes troubleshooting and performance tuning more difficult.
What changed and how does it work?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.