-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: support ScalarSubQuery to display them in EXPLAIN #45252
Conversation
/test all |
/retest |
/test all |
/retest |
1 similar comment
/retest |
|
||
// EvalInt returns the int64 representation of expression. | ||
func (*ScalarSubQueryExpr) EvalInt(_ sessionctx.Context, _ chunk.Row) (val int64, isNull bool, err error) { | ||
return 0, false, errors.Errorf("Evaluation methods is not implemented for ScalarSubQueryExpr") |
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.
Do we need to implement these funcs in the future?
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.
Don't need it for now. Since it will not be executed during optimization.
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.
Need to revisit and implement those EvalXXX later, when we need to support execution under ScalarSubqueryExpr. Please add some comments here.
) | ||
|
||
// ScalarSubQueryExpr is a expression placeholder for the non-correlated scalar subqueries which can be evaluated during optimizing phase. | ||
type ScalarSubQueryExpr struct { |
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.
core
has too many codes in it. so can you put this code into the sub package of the core
.
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.
Decoupling the codes in core
is not easy work...
And you'll see that the struct embeds basePlan
in it, which means we cannot move it out from the package...
I have tried to decouple some codes in core
before. But it's really a time costing work.
"SQL": "explain analyze format = 'brief' select * from t1 where (a, b) = (select a, b from t2 limit 1)", | ||
"IsExplainAnalyze": true, | ||
"HasErr": false | ||
} |
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.
Please add some tests about constant folding
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #45252 +/- ##
================================================
+ Coverage 73.2767% 73.3524% +0.0757%
================================================
Files 1264 1268 +4
Lines 389025 391061 +2036
================================================
+ Hits 285065 286853 +1788
- Misses 85717 85873 +156
- Partials 18243 18335 +92
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/retest |
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
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
for _, scalarSubQ := range p.SCtx().GetSessionVars().MapScalarSubQ { | ||
castedScalarSubQ, ok := scalarSubQ.(*ScalarSubQueryExpr) | ||
if !ok { | ||
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.
how can we assert fail here? the log is better to notify at debug level
"Selection 8000.00 root ScalarQueryCol#15", | ||
"└─TableReader 10000.00 root data:TableFullScan", | ||
" └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo", | ||
"ScalarSubQuery N/A root Output: ScalarQueryCol#13", |
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.
may we follow the dependency order here?
main (use col2 inside)
dependency2 (use col1 inside) output col2
dependency1 output col1
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.
We can left for future optimization
{ | ||
"SQL": "explain format = 'brief' select * from t1 where (a, b) = (select a, b from t2 limit 1)", | ||
"Plan": [ | ||
"Selection 8000.00 root eq(test.t1.a, ScalarQueryCol#9), eq(test.t1.b, ScalarQueryCol#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.
may we add one more case like:
select sub-q as yy, xx, xx from t where yy > 0 order by yy;
this kind subq's output col will be built and used through projection then selection, then sort
return s.Value, s.evalErr | ||
} | ||
err := s.selfEvaluate() | ||
if err != 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.
may merge the below two line together?
/hold |
Waiting for the configure review's approval. |
/unhold |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AilinKid, chrysan, elsa0520, hawkingrei, qw4990 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
/found community |
What problem does this PR solve?
Issue Number: close #22076
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.