-
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
ddl, executor : add auto_random column option #13127
Conversation
84e1b0d
to
c5fd251
Compare
d7e632b
to
15887eb
Compare
b502cb4
to
cb7933d
Compare
Codecov Report
@@ Coverage Diff @@
## master #13127 +/- ##
===========================================
Coverage ? 80.1654%
===========================================
Files ? 483
Lines ? 121626
Branches ? 0
===========================================
Hits ? 97502
Misses ? 16351
Partials ? 7773 |
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.
Haven't finished review yet
@@ -792,6 +807,62 @@ func getAutoRecordID(d types.Datum, target *types.FieldType, isInsert bool) (int | |||
return recordID, nil | |||
} | |||
|
|||
func (e *InsertValues) adjustAutoShardDatum(ctx context.Context, d types.Datum, hasValue bool, c *table.Column) (types.Datum, error) { | |||
if !hasValue || d.IsNull() { |
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.
should take retry into consideration.
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.
Can we simply ignore the retry, just allocate another id instead?
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 better to cache the auto shard id in retryInfo
, but we can do that in another PR, after all this PR is very large already.
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.
Maybe can plus lazy batch alloc
than alloc one by one
in next pr, by now, it's ok here.
c610f8e
to
0ed14db
Compare
@@ -792,6 +807,62 @@ func getAutoRecordID(d types.Datum, target *types.FieldType, isInsert bool) (int | |||
return recordID, nil | |||
} | |||
|
|||
func (e *InsertValues) adjustAutoShardDatum(ctx context.Context, d types.Datum, hasValue bool, c *table.Column) (types.Datum, error) { | |||
if !hasValue || d.IsNull() { |
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 better to cache the auto shard id in retryInfo
, but we can do that in another PR, after all this PR is very large already.
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
/run-all-tests |
Your auto merge job has been accepted, waiting for 14177 |
/run-all-tests |
@tangenta merge failed. |
/run-unit-test |
2 similar comments
/run-unit-test |
/run-unit-test |
Related parser PR: pingcap/parser#571
What problem does this PR solve?
A column attribute named
auto_random
is added, which is used to mitigate the hot spots on a single server when high-volume writes happen in the table with integer primary key.If the primary key constraint of a table is specified on an integer column
c
, the row values inc
are directly used as the row id instead of implicit allocation during TiDB's key-value construction.In this case, we say PKIsHandle.
This PR adds a keyword,
auto_random
. The usage is as follows:The number
n
followingauto_random
means the highest nth bits of the column value is reserved for sharding. Omitting this value is equivalent to setting it to5
. In other words,auto_random
has the same meaning asauto_random(5)
.Similar to
auto_increment
, users can also omit the column value when inserting a row, at which point the value is allocated by TiDB automatically.There are some features about these allocated values:
StartTS
of a transaction.Users can also specify the column value explicitly. In this case, TiDB will save the value intact.
Note: before using
auto_random
,allow-auto-random
needs to be set totrue
in the[experimental]
section of the configuration file.Limitations:
auto_random
is not supported.auto_random
is strongly not recommended.auto_random
column attribute is not supported.auto_increment
andauto_random
are not allowed to be specified in the same column at the same time.What is changed and how it works?
buildTableInfo
andgetModifiableColumnJob
.Check List
Tests
Code changes
Side effects
Related changes
Release note