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: don't load table info to get auto_increment value #57296

Merged
merged 5 commits into from
Nov 13, 2024

Conversation

tangenta
Copy link
Contributor

@tangenta tangenta commented Nov 11, 2024

What problem does this PR solve?

Issue Number: close #57295

Problem Summary:

What changed and how does it work?

  • Add a method TableIsCached() for infoschemaV2.
  • Don't load table info in getAutoIncrementID(). If we do, the current auto ID must be zero. Let's return zero directly.
  • Add a simple unit test.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
    After this PR, the same query only takes 80ms.
  • 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 do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2024
Copy link

tiprow bot commented Nov 11, 2024

Hi @tangenta. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes-sigs/prow repository.

@tangenta
Copy link
Contributor Author

/check-issue-triage-complete

tk.MustQuery(autoIncQuery).Check(testkit.Rows("0"))
tk.MustExec("insert into t values ();")
tk.MustQuery(autoIncQuery).Check(testkit.Rows("5"))
tk.MustExec("set @@global.tidb_schema_cache_size = 0;")
Copy link
Contributor

Choose a reason for hiding this comment

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

There is an API you can use to evict table cache directly, although trigger reload can get the same effect.

	is := dom.InfoSchema()
	ok, v2 := infoschema.IsV2(is)
	require.True(t, ok)
	v2.EvictTable(model.NewCIStr("test"), model.NewCIStr("t1"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The schema is not v2 if we don't reload.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 11, 2024
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 68.29268% with 13 lines in your changes missing coverage. Please review.

Project coverage is 74.7861%. Comparing base (e16613d) to head (bc5e3d1).
Report is 66 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #57296        +/-   ##
================================================
+ Coverage   72.8878%   74.7861%   +1.8983%     
================================================
  Files          1667       1715        +48     
  Lines        460775     472808     +12033     
================================================
+ Hits         335849     353595     +17746     
+ Misses       104289      97083      -7206     
- Partials      20637      22130      +1493     
Flag Coverage Δ
integration 49.1697% <68.2926%> (?)
unit 72.3338% <68.2926%> (+0.0581%) ⬆️

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

Components Coverage Δ
dumpling 52.7673% <ø> (ø)
parser ∅ <ø> (∅)
br 60.3570% <ø> (+15.3111%) ⬆️
---- 🚨 Try these New Features:

@@ -242,11 +242,29 @@ func getAutoIncrementID(
sctx sessionctx.Context,
tblInfo *model.TableInfo,
) int64 {
if raw, ok := is.(*infoschema.SessionExtendedInfoSchema); ok {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this type assertion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Infoschema that we can get from session is wrapped with SessionExtendedInfoSchema:

func AttachLocalTemporaryTableInfoSchema(sctx variable.SessionVarsProvider, is infoschema.InfoSchema) infoschema.InfoSchema {

@ti-chi-bot ti-chi-bot bot added sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 11, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 12, 2024
Copy link

ti-chi-bot bot commented Nov 12, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-11-11 10:26:28.702297169 +0000 UTC m=+265550.893166159: ☑️ agreed by tiancaiamao.
  • 2024-11-12 05:33:10.633279437 +0000 UTC m=+334352.824148433: ☑️ agreed by CbcWestwolf.

Copy link

ti-chi-bot bot commented Nov 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CbcWestwolf, hawkingrei, tiancaiamao, wjhuang2016

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 Nov 12, 2024
@purelind
Copy link
Contributor

/test all

Copy link

tiprow bot commented Nov 12, 2024

@purelind: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

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 kubernetes-sigs/prow repository.

@hawkingrei
Copy link
Member

/retest

1 similar comment
@purelind
Copy link
Contributor

/retest

Copy link

tiprow bot commented Nov 13, 2024

@purelind: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest

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 kubernetes-sigs/prow repository.

@@ -242,11 +242,29 @@ func getAutoIncrementID(
sctx sessionctx.Context,
tblInfo *model.TableInfo,
) int64 {
if raw, ok := is.(*infoschema.SessionExtendedInfoSchema); ok {
v2, ok := raw.InfoSchema.(interface {
TableIsCached(id int64) bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we use IsV2 which seems easier to understand? It seems that the v1 tables are all cached.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ti-chi-bot ti-chi-bot bot merged commit eea72ec into pingcap:master Nov 13, 2024
23 checks passed
@tangenta tangenta added the needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. label Nov 19, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #57494.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner 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.

Query to is.tables is slow in infoschema cache v2
8 participants