-
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
infoschema: add the SchemaNameByTableID API #56156
infoschema: add the SchemaNameByTableID API #56156
Conversation
7915aac
to
1b87969
Compare
Signed-off-by: Rustin170506 <[email protected]>
1b87969
to
74b8e5e
Compare
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #56156 +/- ##
=================================================
- Coverage 72.9579% 58.4947% -14.4632%
=================================================
Files 1611 1786 +175
Lines 447514 651094 +203580
=================================================
+ Hits 326497 380856 +54359
- Misses 100924 245874 +144950
- Partials 20093 24364 +4271
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.
This API can be implemented by combine TableByID and SchemaByID:
t := TableByID(tid)
d := SchemaByID(t.Meta().DBID)
If I write the code, I would prefer keeping the interface minimal and composible,
And provide such a function:
package infoschema
func SchemaNameByTableID(is infoschema.InfoSchema, tableID int64) (schemaName pmodel.CIStr, ok bool) {
// If is implements SchemaNameByTableID, use the native implementation for speed.
if fn, ok := is.(interface{SchemaNameByTableID(tableID int64)}); ok {
return fn(tableID)
}
// Otherwise choose the normal code path.
tbInfo := is.TableInfoByID(tid)
dbInfo := is.SchemaByID(tbInfo.DBID)
return dbInfo.Name, ok
}
and use function infoschema.SchemaNameByTableID
in the callers.
Anyway, that's just some personal coding taste.
Please address comment from others, rest LGTM
Signed-off-by: Rustin170506 <[email protected]>
Signed-off-by: Rustin170506 <[email protected]>
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
[LGTM Timeline notifier]Timeline:
|
/assign @GMHDBJD |
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
@@ -308,6 +308,19 @@ func (is *infoSchema) TableByID(_ stdctx.Context, id int64) (val table.Table, ok | |||
return slice[idx], true | |||
} | |||
|
|||
func (is *infoSchema) SchemaNameByTableID(tableID int64) (schemaName pmodel.CIStr, ok bool) { | |||
tbl, ok := is.TableByID(stdctx.Background(), tableID) |
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 about pass the ctx instead of the background ctx
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 don't really use that context.
/hold We need to consider the partition ID as well. |
/unhold Using table id is enough. |
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: GMHDBJD, lance6716, tiancaiamao 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 |
4 similar comments
/retest |
/retest |
/retest |
/retest |
@ti-chi-bot Hi |
/ping |
What problem does this PR solve?
Issue Number: ref #55906
Problem Summary:
What changed and how does it work?
This PR introduced a new API to query the database name using the table ID. This API will be used in the new priority queue implementation.
Because we want to avoid fetching table information as much as possible. So we need to add this new API to achieve it.
Check https://github.com/pingcap/tidb/pull/55889/files#r1766302195 out to see how we use it in the new priority queue.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.