autoid: support system variables auto_increment_increment
and auto_increment_offset
#14245
Labels
type/enhancement
The issue or PR belongs to an enhancement.
Feature Request
Is your feature request related to a problem? Please describe:
The system variable
auto_increment_increment
andauto_increment_offset
are useful in some scenarios. For example, when the users want to do a Master-Master(bidirectional) replication withauto_increment
columns, duplicate-key conflict and be avoided by setting different variable values in the clusters, for example:Cluster 1:
Cluster 2:
For now, TiDB defines those 2 variables: users can set them but they don't actually take effect. We should make them work for those users who need them.
Describe alternatives you've considered:
The main implementation in MySQL Server can be found here:
https://github.com/mysql/mysql-server/blob/91a17cedb1ee880fe7915fb14cfd74c04e8d6588/sql/handler.cc#L3431
Basically, it made a rounding and then calculate next ID from the following formula:
The result can be guaranteed to be a multiple of
auto_increment_increment
offset withauto_increment_offset
.We can port this formula to TiDB's ID allocator:
tidb/meta/autoid/autoid.go
Line 312 in 0d7edc7
Somethings we may need to consider:
step
from KV is not affected.rowid
should not be affected.ALTER TABLE ... AUTO_INCREMENT
should not break the constraint of these 2 variables: looks it should be fine, the next value is calculated instantly by the formula above.Some manual tests have been done from a raw prototype: bb7133@adb83e3.
Teachability, Documentation, Adoption, Migration Strategy:
This is simply missing compatibility feature, seems we don't need to care them.
The text was updated successfully, but these errors were encountered: