-
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 specify table partition in optimize hint #17638
planner: support specify table partition in optimize hint #17638
Conversation
/run-unit-test |
Codecov Report
@@ Coverage Diff @@
## master #17638 +/- ##
================================================
+ Coverage 79.4228% 80.0594% +0.6366%
================================================
Files 524 526 +2
Lines 142143 145994 +3851
================================================
+ Hits 112894 116882 +3988
+ Misses 20101 19969 -132
+ Partials 9148 9143 -5 |
…on_in_table_hints
if hintInfo.ifPreferTiFlash(alias) { | ||
if ds.preferStoreType != 0 { | ||
if hintTbl := hintInfo.ifPreferTiFlash(alias); hintTbl != nil { | ||
if ds.preferStoreType != 0 && ds.tableInfo.Partition == 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.
Add a comment for why we do not raise an error when ds.tableInfo.Partition != nil
planner/core/logical_plans.go
Outdated
@@ -502,7 +503,8 @@ type DataSource struct { | |||
// it is converted from statisticTable, and used for IO/network cost estimating. | |||
TblColHists *statistics.HistColl | |||
//preferStoreType means the DataSource is enforced to which storage. | |||
preferStoreType int | |||
preferStoreType int | |||
preferStoreTypePartitions map[int][]model.CIStr |
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.
preferPartitions
is enough?- Add a comment for why this is a map
planner/core/planbuilder.go
Outdated
case TiDBMergeJoin, HintSMJ, TiDBIndexNestedLoopJoin, HintINLJ, HintINLHJ, HintINLMJ, TiDBHashJoin, HintHJ: | ||
if len(tableInfo.partitions) > 0 { | ||
ctx.GetSessionVars().StmtCtx.AppendWarning( | ||
errors.New(fmt.Sprintf("%s hint do not support specify partitions", hintName))) |
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 invoke
restore2StorageHint
here? - Do we need to extend
restore2StorageHint
?
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 error message can be refined to Optimizer Hint %s is inapplicable on specified partitions
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 raise a warning for sql like if the partition is unknown in the hint:
select /*+ use_index(t partition(p_non_exist)) */ from t partition(p1,p2)
OK, I try to support it. |
/rebuild |
….com/lzmhhh123/tidb into dev/support_partition_in_table_hints
planner/core/planbuilder.go
Outdated
if len(table.partitions) > 0 { | ||
buffer.WriteString(" PARTITION(") | ||
for j, partition := range table.partitions { | ||
buffer.WriteString(partition.L) |
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 should be moved to line 262
for _, p := range partitions { | ||
if !partitionSet.Exist(p.L) { | ||
ds.ctx.GetSessionVars().StmtCtx.AppendWarning( | ||
errors.New(fmt.Sprintf("partition `%s` in hint can't hit any source", p.L))) |
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 we return the partition name back to checkHintsApplicable
, and build a more comprehensible error message like Unknow partition %s in optimizer hint %s
/run-unit-test |
LGTM |
…on_in_table_hints
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 |
Signed-off-by: ti-srebot <[email protected]>
cherry pick to release-4.0 in PR #18157 |
What problem does this PR solve?
Issue Number: close #17113
Problem Summary: support specify table parition in optimize hint
What is changed and how it works?
What's Changed: support specify table parition in optimize hint
Related changes
pingcap/docs
/pingcap/docs-cn
: after this PR merge, we should update the docs.Check List
Tests
Side effects
Release note