-
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
expression: Add warning info for exprs that can not be pushed to storage layer #22713
Conversation
if storeType == kv.UnSpecified { | ||
storageName = "storage layer" | ||
} | ||
pc.sc.AppendWarning(errors.New("Scalar function '" + scalarFunc.FuncName.L + "'(signature: " + scalarFunc.Function.PbCode().String() + ") can not be pushed to " + storageName)) |
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.
Looks like each time only one function can be shown. For a real world case it will be tricky.
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 TiDB implementation, for each DNF
expression, If a function can not be pushed down, then all the other functions in the same DNF
expression will not be checked, as far as I known, TiDB will convert filter expression into a list of DNF
before predicate pushdown, so if function_1
and function_2
is not supported by the storage layer, for query:
select * from a where function_1 or function_2
, only function_1 will be recorded.
but for query
select * from a where function_1 and function_2
, both function_1 and function_2 will be recorded.
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 not reading the explain result to find which functions are not pushed down?
/run-all-tests |
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
@@ -1161,6 +1161,13 @@ func canScalarFuncPushDown(scalarFunc *ScalarFunction, pc PbConverter, storeType | |||
|
|||
// Check whether this function can be pushed. | |||
if !canFuncBePushed(scalarFunc, storeType) { | |||
if pc.sc.InExplainStmt { |
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.
for example: select fun1(), agg_fun2() from t where func3() group by c having fun4(); if funx() cannot be pushed down, will this shows 4 warnings, even though it first encounters func3()?
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 pr only record the unsupported functions, it does not change the behavior of optimizer, so if func3
is not supported, and the optimizer decide not pushdown agg
to the storage layer, then only func3
will be recorded.
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.
other unsupported functions also will be recorded?
@@ -1184,6 +1191,9 @@ func canScalarFuncPushDown(scalarFunc *ScalarFunction, pc PbConverter, storeType | |||
|
|||
func canExprPushDown(expr Expression, pc PbConverter, storeType kv.StoreType) bool { | |||
if storeType == kv.TiFlash && expr.GetType().Tp == mysql.TypeDuration { | |||
if pc.sc.InExplainStmt { |
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.
duration and func() will rusult two warnings? if func() cannot be pushed down
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.
If the expr
contains Duration
, it will return directly without checking function
in this expr
if sc.InExplainStmt { | ||
storageName := storeType.Name() | ||
if storeType == kv.UnSpecified { | ||
storageName = "storage layer" |
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.
when will we encounter this branch?
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 predicate_push_down
rule, it uses Unspecified
to make sure it can pushdown all the possible expressions, and when generating the cop task, the DataSource
will use the specific store type(TiFlash/TiKV/TiDB
) to make sure only pushdown supported expressions to each store.
if storeType == kv.UnSpecified { | ||
storageName = "storage layer" | ||
} | ||
pc.sc.AppendWarning(errors.New("Scalar function '" + scalarFunc.FuncName.L + "'(signature: " + scalarFunc.Function.PbCode().String() + ") can not be pushed to " + storageName)) |
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 not reading the explain result to find which functions are not pushed down?
Explain result only tells that
|
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
/merge |
/run-all-tests |
@windtalker merge failed. |
/run-integration-copr-test |
/merge |
/run-all-tests |
/label needs-cherry-pick-4.0 |
1 similar comment
/label needs-cherry-pick-4.0 |
/remove-label needs-cherry-pick-4.0 |
/label needs-cherry-pick-4.0 |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #23020 |
What problem does this PR solve?
Issue Number: close #xxx
Problem Summary:
Currently, when user running a query, and found the query is slower than expected because some part of the query(e.g.
Selection
orAggregation
) is not pushed down to coprocessor, there is no easy way to find out which function not supported by coprocessor.What is changed and how it works?
Proposal: xxx
What's Changed:
How it Works:
According to Mysql document:
It is reasonable to add warnings about functions that can not be pushed to coprocessor when user executing an explain statement, so this pr add this information to make user easier to figure out why
Selection
orAggregation
is not pushed to coprocessor.Related changes
Check List
Tests
Side effects
Release note