-
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
*: add global system variable tmp_table_size
#24827
Conversation
/rebuild |
sessionctx/variable/sysvar.go
Outdated
@@ -1501,6 +1501,12 @@ var defaultSysVars = []*SysVar{ | |||
{Scope: ScopeGlobal, Name: TiDBGCLifetime, Value: "10m0s", Type: TypeDuration, MinValue: int64(time.Minute * 10), MaxValue: math.MaxInt64}, | |||
{Scope: ScopeGlobal, Name: TiDBGCConcurrency, Value: "-1", Type: TypeInt, MinValue: 1, MaxValue: 128, AllowAutoValue: true}, | |||
{Scope: ScopeGlobal, Name: TiDBGCScanLockMode, Value: "PHYSICAL", Type: TypeEnum, PossibleValues: []string{"PHYSICAL", "LEGACY"}}, | |||
|
|||
// See https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_temptable_max_ram | |||
{Scope: ScopeGlobal, Name: TempTableMaxRAM, Value: strconv.Itoa(DefTempTableMaxRAM), Type: TypeInt, MinValue: 2097152, MaxValue: math.MaxInt64, SetGlobal: func(s *SessionVars, val string) error { |
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.
For MySQL, the max value is MaxUint64.
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's okay to not follow strictly, but there is an issue in that the internal value is a signed int32, but the sysvar allows up to signed int64. The two types should align.
Signed int32 only allows up to 2GB temporary tables, which is "okay", but there might be some cases where it needs to be larger.
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 still set to have a maximum value of math.MaxInt64
, but the internal value is an int32.
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 it's better to be conservative.
We can update the value to be larger anytime as long as we'd like to, but if we set it's initial value huge and turn down the value in a future release, there will be a compatibility issue.
And now I take @morgo 's advise and set it to math.MaxInt32
Please resolve conflicts, rest LGTM. @tiancaiamao |
/lgtm |
Co-authored-by: Morgan Tocker <[email protected]>
Please refer the pull request to its issue #24169 and it would be better if we create a dedicated sub-issue for this pr. |
@tiancaiamao Please create a sub-issue and resolve conflicts, and then ask @morgo and @wjhuang2016 to review it again. |
temptable_max_ram
tidb_temptable_max_ram
Since in MySQL8 PTAL @djshow832 @wjhuang2016 @morgo |
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.
restLGTM
@tiancaiamao As discussed. There are two settings which apply in MySQL 5.7 here: They are used together, so the smaller limit is what applies to in-memory temporary tables. These limits are enforced per-temporary table, which is the same semantic as what is used in this PR. The buffer for Where The bigger difference is that |
So complicated ...
|
I'll change to use the variable to For now, just raise an error when data size excess |
/merge cancel |
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.
Please fix the CI
@@ -896,9 +896,9 @@ func (s *testSuite5) TestValidateSetVar(c *C) { | |||
result = tk.MustQuery("select @@tmp_table_size;") | |||
result.Check(testkit.Rows("167772161")) | |||
|
|||
tk.MustExec("set @@tmp_table_size=18446744073709551615") | |||
tk.MustExec("set @@tmp_table_size=9223372036854775807") |
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 change is because MySQL set the value to Uint64, while in TiDB it's set to Int64
Done, please take a look @wjhuang2016 @djshow832 |
/merge |
This pull request has been accepted and is ready to merge. Commit hash: a6c14f7
|
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 754ded5
|
@tiancaiamao: Your PR was out of date, I have automatically updated it for you. At the same time I will also trigger all tests for you: /run-all-tests If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes. 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. |
What problem does this PR solve?
Problem Summary:
Use system variable
tmp_table_size
is used to control the temporary table size threshold.What is changed and how it works?
What's Changed:
tmp_table_size
How it Works:
We can't use the
txn.Size()
directly, because the data may not located in the temporary table.So I use the txn size before & after the
AddRecord()
operation to calculate the temporary table size.Check List
Tests
Need to Update document too
Release note