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

dml : fix last insert id when autoid specified by user in first row. #11973

Merged
merged 9 commits into from
Sep 2, 2019

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Sep 2, 2019

What problem does this PR solve?

Fix last insert id when autoid specified by user in first row.
Table

mysql> desc t;
+-------+---------+------+------+---------+----------------+
| Field | Type    | Null | Key  | Default | Extra          |
+-------+---------+------+------+---------+----------------+
| a     | int(11) | NO   | PRI  | NULL    | auto_increment |
| b     | int(11) | YES  |      | NULL    |                |
+-------+---------+------+------+---------+----------------+
2 rows in set (0.00 sec)

before this PR

mysql> insert into t values(300000, -1),(null, -1),(null, -1);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|                0 |
+------------------+
1 row in set (0.00 sec)

After this PR = MySQL's behavior

mysql> insert into t values(300000, -1),(null, -1),(null, -1);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
|           300001 |
+------------------+
1 row in set (0.00 sec)

What is changed and how it works?

Last insert id is not strong lied with the first insert row.
More specifically, it does lie with the first row that without user specified autoID.

Change the judging logic, 0 is inited value meaning that last insert id hasn't be assigned. So do the assignment under the condition.

Check List

Tests

  • Unit test
  • Integration test

Related changes

  • Need to cherry-pick to the release branch

Release note

  • fix last insert id when autoid specified by user in first row.

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

Any test case could cover it?

@AilinKid AilinKid changed the title dmlfix last insert id when autoid specified by user in first row dml : fix last insert id when autoid specified by user in first row. Sep 2, 2019
@AilinKid
Copy link
Contributor Author

AilinKid commented Sep 2, 2019

Any test case could cover it?

Addressed. @jackysp

@codecov
Copy link

codecov bot commented Sep 2, 2019

Codecov Report

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

@@             Coverage Diff             @@
##             master     #11973   +/-   ##
===========================================
  Coverage   81.2597%   81.2597%           
===========================================
  Files           444        444           
  Lines         95116      95116           
===========================================
  Hits          77291      77291           
  Misses        12332      12332           
  Partials       5493       5493

@AilinKid AilinKid changed the title dml : fix last insert id when autoid specified by user in first row. dml : fix last insert id when autoid specified by user in first row.[DNM] Sep 2, 2019
@AilinKid AilinKid changed the title dml : fix last insert id when autoid specified by user in first row.[DNM] dml : fix last insert id when autoid specified by user in first row. Sep 2, 2019
@AilinKid AilinKid closed this Sep 2, 2019
@AilinKid AilinKid reopened this Sep 2, 2019
Copy link
Member

@jackysp jackysp 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

@lonng lonng left a comment

Choose a reason for hiding this comment

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

LGTM

@lonng lonng added the status/can-merge Indicates a PR has been approved by a committer. label Sep 2, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 2, 2019

/run-all-tests

@sre-bot
Copy link
Contributor

sre-bot commented Sep 2, 2019

cherry pick to release-3.0 in PR #11992

@sre-bot
Copy link
Contributor

sre-bot commented Sep 2, 2019

cherry pick to release-2.1 in PR #11993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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