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) #15149

Merged
merged 3 commits into from
Mar 5, 2020

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Mar 5, 2020

cherry-pick #15145 to release-3.1
Conflicting files:
insert_common.go
insert_test.go


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.

Signed-off-by: sre-bot <sre-bot@pingcap.com>
@sre-bot
Copy link
Contributor Author

sre-bot commented Mar 5, 2020

/run-all-tests

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, good job.

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

/merge

@sre-bot
Copy link
Contributor Author

sre-bot commented Mar 5, 2020

Sorry @djshow832, you don't have permission to trigger auto merge event on this branch.

@djshow832
Copy link
Contributor

/run-all-tests

@bb7133
Copy link
Member

bb7133 commented Mar 5, 2020

/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 Author

sre-bot commented Mar 5, 2020

/run-all-tests

@sre-bot sre-bot merged commit 56ca69a into pingcap:release-3.1 Mar 5, 2020
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.

4 participants