Skip to content
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

executor: fix last_insert_id in auto_random mode #15145

Merged
merged 10 commits into from
Mar 5, 2020

Conversation

djshow832
Copy link
Contributor

@djshow832 djshow832 commented Mar 5, 2020

What problem does this PR solve?

Fix #15140.

  • Last insert id shouldn't be 0 when inserting with auto_random.
  • 0 is not replaced with an auto allocated value.
  • Error message of auto_random is confusing.

What is changed and how it works?

  • Set last insert id after inserting 0.
  • Consider NO_AUTO_VALUE_ON_ZERO and fill auto value with inserting 0.
  • Refine error message of auto_random.

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)
mysql> insert ar value(0, 'a'), (0, 'b');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from ar;
+-----------+------+
| id        | name |
+-----------+------+
| 671178642 | a    |
| 671178643 | b    |
+-----------+------+
2 rows in set (0.00 sec)

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|        671178642 |
+------------------+
1 row in set (0.01 sec)
mysql> create table ar(id int key auto_random(32));
ERROR 8216 (HY000): Invalid auto random: Bits of column `id` is 32, but auto_random bits is 32. Max allowed auto_random bits for column `id` is 31
mysql> create table ar(id int key auto_random(31));
Query OK, 0 rows affected (0.00 sec)

Code changes

N/A

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix the bug that last_insert_id is wrong when inserting with auto_random; Inserting 0 with auto_random column is not replaced with an allocated value.

@codecov
Copy link

codecov bot commented Mar 5, 2020

Codecov Report

Merging #15145 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #15145   +/-   ##
===========================================
  Coverage   80.3007%   80.3007%           
===========================================
  Files           503        503           
  Lines        132279     132279           
===========================================
  Hits         106221     106221           
  Misses        17680      17680           
  Partials       8378       8378

@djshow832 djshow832 added sig/execution SIG execution type/bugfix This PR fixes a bug. labels Mar 5, 2020
@djshow832
Copy link
Contributor Author

/run-all-tests

@djshow832 djshow832 requested a review from crazycs520 March 5, 2020 06:55
Copy link
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

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

Rest LGTM

executor/insert_test.go Show resolved Hide resolved
Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@djshow832
Copy link
Contributor Author

/merge

@sre-bot sre-bot added the status/can-merge Indicates a PR has been approved by a committer. label Mar 5, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Mar 5, 2020

/run-all-tests

@sre-bot sre-bot merged commit dcb8b3d into pingcap:master Mar 5, 2020
sre-bot added a commit to sre-bot/tidb that referenced this pull request Mar 5, 2020
Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor

sre-bot commented Mar 5, 2020

cherry pick to release-3.1 in PR #15149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

last_insert_id() doesn't work with auto_random
5 participants