Skip to content

executor: fix last_insert_id in auto_random mode (#15145)#15149

Merged
sre-bot merged 3 commits into
pingcap:release-3.1from
sre-bot:release-3.1-dcb8b3d5ddf0
Mar 5, 2020
Merged

executor: fix last_insert_id in auto_random mode (#15145)#15149
sre-bot merged 3 commits into
pingcap:release-3.1from
sre-bot:release-3.1-dcb8b3d5ddf0

Conversation

@sre-bot

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

Copy link
Copy Markdown
Contributor

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

sre-bot commented Mar 5, 2020

Copy link
Copy Markdown
Contributor Author

/run-all-tests

@bb7133 bb7133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, good job.

@AilinKid AilinKid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@djshow832

Copy link
Copy Markdown
Contributor

/merge

@sre-bot

sre-bot commented Mar 5, 2020

Copy link
Copy Markdown
Contributor Author

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

@djshow832

Copy link
Copy Markdown
Contributor

/run-all-tests

@bb7133

bb7133 commented Mar 5, 2020

Copy link
Copy Markdown
Member

/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

sre-bot commented Mar 5, 2020

Copy link
Copy Markdown
Contributor Author

/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