Skip to content
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

Merged

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Sep 19, 2024

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

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 19, 2024
@Rustin170506 Rustin170506 force-pushed the rustin-patch-SchemaNameByTableID branch 2 times, most recently from 7915aac to 1b87969 Compare September 19, 2024 07:22
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
@Rustin170506 Rustin170506 force-pushed the rustin-patch-SchemaNameByTableID branch from 1b87969 to 74b8e5e Compare September 19, 2024 07:23
Copy link
Member Author

@Rustin170506 Rustin170506 left a 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.)

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 64.28571% with 10 lines in your changes missing coverage. Please review.

Project coverage is 58.4947%. Comparing base (70a26f8) to head (ee621a2).
Report is 65 commits behind head on master.

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     
Flag Coverage Δ
integration 41.2239% <32.1428%> (?)
unit 73.9386% <64.2857%> (+1.8714%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.1514% <ø> (+0.1947%) ⬆️
parser ∅ <ø> (∅)
br 65.3621% <ø> (+19.5735%) ⬆️

@Rustin170506
Copy link
Member Author

/retest

pkg/infoschema/infoschema.go Outdated Show resolved Hide resolved
pkg/infoschema/infoschema_v2.go Show resolved Hide resolved
Copy link
Contributor

@tiancaiamao tiancaiamao left a 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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Sep 19, 2024
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
Signed-off-by: Rustin170506 <29879298+Rustin170506@users.noreply.github.com>
Copy link
Member Author

@Rustin170506 Rustin170506 left a 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.)

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Sep 19, 2024
Copy link

ti-chi-bot bot commented Sep 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-09-19 08:32:11.930770288 +0000 UTC m=+1122801.671194227: ☑️ agreed by tiancaiamao.
  • 2024-09-19 09:06:20.456434996 +0000 UTC m=+1124850.196858936: ☑️ agreed by lance6716.

@lance6716
Copy link
Contributor

/assign @GMHDBJD

Copy link
Contributor

@GMHDBJD GMHDBJD left a 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)
Copy link
Contributor

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

Copy link
Member Author

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.

@Rustin170506
Copy link
Member Author

/hold

We need to consider the partition ID as well.

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 24, 2024
@Rustin170506
Copy link
Member Author

/unhold

Using table id is enough.

@ti-chi-bot ti-chi-bot bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 24, 2024
Copy link
Contributor

@GMHDBJD GMHDBJD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

ti-chi-bot bot commented Sep 24, 2024

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Sep 24, 2024
@Rustin170506
Copy link
Member Author

/retest

4 similar comments
@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

/retest

@Rustin170506
Copy link
Member Author

@ti-chi-bot Hi

@wuhuizuo
Copy link
Contributor

@ti-chi-bot Hi

/ping

@ti-chi-bot ti-chi-bot bot merged commit 8c12f12 into pingcap:master Sep 25, 2024
25 checks passed
@Rustin170506 Rustin170506 deleted the rustin-patch-SchemaNameByTableID branch September 25, 2024 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants