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 mysql_insert_id() for "INSERT .. ON DUPLICATE KEY" statement #56514

Merged
merged 3 commits into from
Oct 11, 2024

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #55965

Problem Summary:

What changed and how does it work?

Handle the value correctly for mysql_insert_id() when duplicate update happen in the "INSERT .. ON DUPLICATED UPDATE" statement.

In the code internally, we use InsertID when the value auto increment column is specified explicitly.
And use LastInsertID when the value of auto increment column is auto generated.

	// PrevLastInsertID is the last insert ID of previous statement.
	PrevLastInsertID uint64
	// LastInsertID is the auto-generated ID in the current statement.
	LastInsertID uint64
	// InsertID is the given insert ID of an auto_increment column.
	InsertID uint64

The different between mysql_insert_id() and LAST_INSERT_ID() is that the former get its value either from auto generated or explicitly specified, while the later just update the value in the auto generated cases.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

See the steps descriped in the issue

  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 9, 2024
Copy link

tiprow bot commented Oct 9, 2024

Hi @tiancaiamao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.7697%. Comparing base (1eb0c8c) to head (f94965b).
Report is 449 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #56514         +/-   ##
=================================================
- Coverage   73.3698%   56.7697%   -16.6001%     
=================================================
  Files          1626       1752        +126     
  Lines        448852     634850     +185998     
=================================================
+ Hits         329322     360403      +31081     
- Misses        99364     250330     +150966     
- Partials      20166      24117       +3951     
Flag Coverage Δ
integration 36.9460% <100.0000%> (?)
unit 72.6428% <100.0000%> (+0.1796%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9478% <ø> (ø)
parser ∅ <ø> (∅)
br 52.3554% <ø> (+6.7784%) ⬆️

pkg/executor/insert.go Outdated Show resolved Hide resolved
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

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 11, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 11, 2024
Copy link

ti-chi-bot bot commented Oct 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackysp, lcwangchao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Oct 11, 2024
Copy link

ti-chi-bot bot commented Oct 11, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-10-11 03:37:51.334572019 +0000 UTC m=+1190026.754785023: ☑️ agreed by jackysp.
  • 2024-10-11 08:42:33.476218631 +0000 UTC m=+1350.625128457: ☑️ agreed by lcwangchao.

@ti-chi-bot ti-chi-bot bot merged commit 3dfc47f into pingcap:master Oct 11, 2024
23 checks passed
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. label Nov 4, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #57107.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Nov 4, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Nov 7, 2024
@ti-chi-bot ti-chi-bot bot added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Dec 10, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #58120.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Dec 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mysql_insert_id() incompatible between tidb and mysql
4 participants