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

Closed
wants to merge 8 commits into from

Conversation

sre-bot
Copy link
Contributor

@sre-bot sre-bot commented Sep 2, 2019

cherry-pick #11973 to release-2.1


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.

@sre-bot
Copy link
Contributor Author

sre-bot commented Sep 2, 2019

/run-all-tests

@AilinKid
Copy link
Contributor

AilinKid commented Sep 3, 2019

/rebuild

@AilinKid
Copy link
Contributor

AilinKid commented Sep 3, 2019

/run-all-tests

@AilinKid AilinKid closed this Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants