-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Option to allow limiting auto_random maximum value/range #32508
Comments
This is a great point, thank you for the feature request. I would actually say because it is random, there should not be a need to create an option. Not all users will be aware that numbers greater than 2^53-1 will be incorrectly handled in their apps. |
Now auto_random only support int64, it exceed the range of JSON/NodeJS data type range then cause this issue.
|
@andreifedorov-bolt Hi, did you already use JSON format in TiDB? Since TiDB are also evaluting JSON support recently, could you please share your use scenario with us? |
For some columns in databases, we use BIGINT UNSIGNED datatype. However, the following factors do not allow to use values that do not fit more than 53bits:
https://datatracker.ietf.org/doc/html/rfc7159#page-6
Examples:
% node -e 'console.log(JSON.stringify({"foobar": 18446744073709551615}))'
{"foobar":18446744073709552000}
% node -e 'console.log(JSON.parse("{"foobar": 18446744073709551615}"))'
{ foobar: 18446744073709552000 }
This causes issues if we convert autoincrement bigint unsigned to auto_random, as it almost immediately exceeds 53bit value by using the full range.
So limiting, e.g. AUTO_RANDOM(5, 6) instead of AUTO_RANDOM(5) (thus using only 6 bytes) might solve this issue.
This might be useful to allow to migrate back to auto_increment - if we limit the range when migrating to auto_random - so we have enough values free between the current and maximum.
The text was updated successfully, but these errors were encountered: