-
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, statistics: use the correct column ID when recording stats loading status #52208
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #52208 +/- ##
================================================
+ Coverage 71.1432% 73.3190% +2.1758%
================================================
Files 1468 1468
Lines 432193 433639 +1446
================================================
+ Hits 307476 317940 +10464
+ Misses 105490 95852 -9638
- Partials 19227 19847 +620
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -152,7 +152,7 @@ func crossEstimateRowCount(sctx context.PlanContext, | |||
return 0, err == nil, corr | |||
} | |||
idxID := int64(-1) | |||
idxIDs, idxExists := dsStatsInfo.HistColl.ColID2IdxIDs[colID] |
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.
It is better to use the clearly name 'colUniqueID' instead of 'colID' to avoid the wrong used.
@@ -45,7 +45,11 @@ func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistCo | |||
} | |||
sc := sctx.GetSessionVars().StmtCtx | |||
c, ok := coll.Columns[colID] | |||
recordUsedItemStatsStatus(sctx, c, coll.PhysicalID, colID) | |||
colInfoID := colID |
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.
Same as above
if len(coll.UniqueID2colInfoID) > 0 { | ||
colInfoID = coll.UniqueID2colInfoID[colID] | ||
} | ||
recordUsedItemStatsStatus(sctx, c, coll.PhysicalID, colInfoID) |
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 we should distinguish colId and colUniqueId in explain such as "colID: xxx" , "colUniqueID: XXX"
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 want the column name in the EXPLAIN result, which should be fetched using the column ID from the metadata instead of the UniqueID
.
@@ -170,15 +170,15 @@ func getIndexRowCountForStatsV1(sctx context.PlanContext, coll *statistics.HistC | |||
} | |||
var count float64 | |||
var err error | |||
colIDs := coll.Idx2ColumnIDs[idxID] | |||
colIDs := coll.Idx2ColUniqueIDs[idxID] |
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.
same as above
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.
Index ID is not relevant here, only Column ID has this difference.
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 good to me. Thanks! 👍
/hold
Feel free to update the testing code or ignore it.
@@ -175,6 +175,7 @@ | |||
"fieldalignment": { | |||
"exclude_files": { | |||
"pkg/parser/parser.go": "parser/parser.go code", | |||
"pkg/statistics/table.go": "disable this limitation that prevents us from splitting struct fields for clarity", |
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 always want to do this, but I can never convince myself. 😃
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 performance benefits and memory efficiency from this rule are small. So I think it's totally OK to disable it when it causes problems or inconvenience.
@@ -215,17 +215,11 @@ const ( | |||
|
|||
// HistColl is a collection of histogram. It collects enough information for plan to calculate the selectivity. | |||
type HistColl struct { | |||
Columns map[int64]*Column |
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.
Big thanks for refactoring this structure!
Idx2ColumnIDs map[int64][]int64 | ||
// ColID2IdxIDs maps the column id to a list index ids whose first column is it. It's used to calculate the selectivity in planner. | ||
ColID2IdxIDs map[int64][]int64 | ||
// MVIdx2Columns maps the index id to its columns by expression.Column. | ||
// For normal index, the column id is enough, as we already have in Idx2ColumnIDs. But currently, mv index needs more | ||
// information to match the filter against the mv index columns, and we need this map to provide this information. | ||
MVIdx2Columns map[int64][]*expression.Column |
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.
nit: It seems we still using some of these names in our testing code. Feel free to update it or ignore it.
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.
From what I found, that's used inside a function, I think that's OK.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hi-rustin, winoros 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 |
/unhold |
/cherry-pick release-7.5 |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@time-and-fate: new pull request created to branch 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. |
@time-and-fate: new pull request created to branch 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. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
What problem does this PR solve?
Issue Number: close #52207
What changed and how does it work?
Previously, this place incorrectly used the
UniqueID
, which is only valid during this query.We should use the column ID from the metadata so that we can correctly fetch the column name from
TableInfo
.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.