Skip to content

*: support specifying range bits for auto_random#36860

Merged
ti-chi-bot merged 11 commits into
pingcap:masterfrom
tangenta:autorand-ft-len
Aug 16, 2022
Merged

*: support specifying range bits for auto_random#36860
ti-chi-bot merged 11 commits into
pingcap:masterfrom
tangenta:autorand-ft-len

Conversation

@tangenta
Copy link
Copy Markdown
Contributor

@tangenta tangenta commented Aug 3, 2022

What problem does this PR solve?

Issue Number: close #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
  • 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
  • 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

@ti-chi-bot
Copy link
Copy Markdown
Member

ti-chi-bot commented Aug 3, 2022

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

Details

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 3, 2022
@tangenta tangenta marked this pull request as ready for review August 8, 2022 13:30
@tangenta tangenta requested a review from a team as a code owner August 8, 2022 13:30
@ti-chi-bot ti-chi-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 8, 2022
@tangenta tangenta changed the title *: support specifying field type length for auto_random *: support specifying range bits for auto_random Aug 8, 2022
@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented Aug 9, 2022

@tangenta tangenta requested a review from Defined2014 August 9, 2022 08:01
Comment thread parser/parser.y
Comment thread parser/model/model.go Outdated
Comment thread meta/autoid/autoid.go
Comment thread meta/autoid/autoid.go
Comment thread ddl/column.go Outdated
Comment thread ddl/serial_test.go
Comment thread meta/autoid/autoid.go Outdated
Comment thread executor/insert_common.go Outdated
@ti-chi-bot ti-chi-bot added status/LGT1 Indicates that a PR has LGTM 1. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Aug 9, 2022
@tangenta tangenta requested a review from bb7133 August 10, 2022 06:18
Copy link
Copy Markdown
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Aug 16, 2022
@bb7133
Copy link
Copy Markdown
Member

bb7133 commented Aug 16, 2022

@tangenta Please resolve the conflicts.

@tangenta
Copy link
Copy Markdown
Contributor Author

/merge

@ti-chi-bot
Copy link
Copy Markdown
Member

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

DetailsCommit hash: 5fa589a

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Aug 16, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2022
@ti-chi-bot ti-chi-bot merged commit d0f8487 into pingcap:master Aug 16, 2022
@sre-bot
Copy link
Copy Markdown
Contributor

sre-bot commented Aug 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to allow limiting auto_random maximum value/range

5 participants