tidb icon indicating copy to clipboard operation
tidb copied to clipboard

*: support specifying range bits for auto_random

Open tangenta opened this issue 2 years ago • 3 comments

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 to sign bit + shard bits + incremental bits.
  • The reserved bits is equal to 64 - 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

tangenta avatar Aug 03 '22 11:08 tangenta

[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.

ti-chi-bot avatar Aug 03 '22 11:08 ti-chi-bot

Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/bf44ec094c930a6d0d1c026e81898751064b98a7

sre-bot avatar Aug 09 '22 06:08 sre-bot

@tangenta Please resolve the conflicts.

bb7133 avatar Aug 16 '22 07:08 bb7133

/merge

tangenta avatar Aug 16 '22 09:08 tangenta

This pull request has been accepted and is ready to merge.

Commit hash: 5fa589ab225646072774d45d51ea2cd19bed86ef

ti-chi-bot avatar Aug 16 '22 09:08 ti-chi-bot

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

sre-bot avatar Aug 16 '22 13:08 sre-bot