tidb
tidb copied to clipboard
*: support specifying range bits for auto_random
What problem does this PR solve?
Issue Number: close https://github.com/pingcap/tidb/issues/32508
Problem Summary: Previously, auto_random
column makes use of the highest several bits for shard. An auto_random
ID can be too large to be represented in some special data types. For example, JSON's number can only represent 54-bits integer.
What is changed and how it works?
This PR introduces a new syntax, which allows users to specify the max "range bits" for the BIGINT
type:
CREATE TABLE t (a BIGINT AUTO_RANDOM(5,54) PRIMARY KEY, b INT); -- the generated ID is guaranteed to be smaller than (2^53)-1
CREATE TABLE t (a BIGINT UNSIGNED AUTO_RANDOM(5,32) PRIMARY KEY, b INT); -- a workaround for "INT UNSIGNED AUTO_RANDOM(5)"
In the above SQLs, 54
and 32
are the "range bits". The new 64-bit shard ID format is as follows:
[sign bit] + [reserved bits] + [shard bits] + [incremental bits]
- The
range bits
is equal tosign bit + shard bits + incremental bits
. - The
reserved bits
is equal to64 - range bits
. The content of the reserved bits are always zero.
Check List
Tests
- [ ] Unit test
- [x] Integration test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No code
Side effects
- [ ] Performance regression: Consumes more CPU
- [ ] Performance regression: Consumes more Memory
- [ ] Breaking backward compatibility
Documentation
- [ ] Affects user behaviors
- [x] Contains syntax changes
- [ ] Contains variable changes
- [ ] Contains experimental features
- [ ] Changes MySQL compatibility
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.
None
[REVIEW NOTIFICATION]
This pull request has been approved by:
- Defined2014
- bb7133
To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer
in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer
in the comment to help you merge this pull request.
The full list of commands accepted by this bot can be found here.
Reviewer can indicate their review by submitting an approval review. Reviewer can cancel approval by submitting a request changes review.
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/bf44ec094c930a6d0d1c026e81898751064b98a7
@tangenta Please resolve the conflicts.
/merge
This pull request has been accepted and is ready to merge.
TiDB MergeCI notify
✅ Well Done! New fixed [1] after this pr merged.
CI Name | Result | Duration | Compare with Parent commit |
---|---|---|---|
idc-jenkins-ci-tidb/integration-ddl-test | ✅ all 6 tests passed | 6 min 44 sec | Fixed |
idc-jenkins-ci/integration-cdc-test | 🟢 all 36 tests passed | 34 min | Existing passed |
idc-jenkins-ci-tidb/integration-common-test | 🟢 all 17 tests passed | 13 min | Existing passed |
idc-jenkins-ci-tidb/common-test | 🟢 all 11 tests passed | 12 min | Existing passed |
idc-jenkins-ci-tidb/tics-test | 🟢 all 1 tests passed | 10 min | Existing passed |
idc-jenkins-ci-tidb/sqllogic-test-2 | 🟢 all 28 tests passed | 4 min 56 sec | Existing passed |
idc-jenkins-ci-tidb/sqllogic-test-1 | 🟢 all 26 tests passed | 4 min 34 sec | Existing passed |
idc-jenkins-ci-tidb/mybatis-test | 🟢 all 1 tests passed | 3 min 14 sec | Existing passed |
idc-jenkins-ci-tidb/integration-compatibility-test | 🟢 all 1 tests passed | 3 min 4 sec | Existing passed |
idc-jenkins-ci-tidb/plugin-test | 🟢 build success, plugin test success | 4min | Existing passed |