-
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
infoschema: don't load table info to get auto_increment value #57296
infoschema: don't load table info to get auto_increment value #57296
Conversation
Hi @tangenta. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with 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. |
/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;") |
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.
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"))
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 schema is not v2 if we don't reload.
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -242,11 +242,29 @@ func getAutoIncrementID( | |||
sctx sessionctx.Context, | |||
tblInfo *model.TableInfo, | |||
) int64 { | |||
if raw, ok := is.(*infoschema.SessionExtendedInfoSchema); ok { |
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.
Why do we need this type assertion?
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.
Infoschema
that we can get from session is wrapped with SessionExtendedInfoSchema
:
tidb/pkg/table/temptable/infoschema.go
Line 23 in a5832b4
func AttachLocalTemporaryTableInfoSchema(sctx variable.SessionVarsProvider, is infoschema.InfoSchema) infoschema.InfoSchema { |
[LGTM Timeline notifier]Timeline:
|
[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 |
/test all |
@purelind: Cannot trigger testing until a trusted user reviews the PR and leaves an 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 kubernetes-sigs/prow repository. |
/retest |
1 similar comment
/retest |
@purelind: Cannot trigger testing until a trusted user reviews the PR and leaves an 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 kubernetes-sigs/prow repository. |
pkg/executor/infoschema_reader.go
Outdated
@@ -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 |
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.
Could we use IsV2
which seems easier to understand? It seems that the v1 tables are all cached.
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.
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: close #57295
Problem Summary:
What changed and how does it work?
TableIsCached()
forinfoschemaV2
.getAutoIncrementID()
. If we do, the current auto ID must be zero. Let's return zero directly.Check List
Tests
After this PR, the same query only takes 80ms.
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.