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

Fixed REPLACE logic to now match MySQL #392

Merged
merged 1 commit into from
Apr 29, 2021
Merged

Conversation

Hydrocharged
Copy link
Contributor

@Hydrocharged Hydrocharged commented Apr 28, 2021

Previously we thought that REPLACE was a DELETE then INSERT, but this is not the actual order that MySQL takes. According to the MySQL documentation (https://dev.mysql.com/doc/refman/8.0/en/replace.html):

 MySQL uses the following algorithm for REPLACE (and LOAD DATA ... REPLACE):

    Try to insert the new row into the table

    While the insertion fails because a duplicate-key error occurs for a primary key or unique index:

        Delete from the table the conflicting row that has the duplicate key value

        Try again to insert the new row into the table 

Special emphasis on the While, as you have to keep trying until you either get a different error, or it succeeds. So this has now been duplicated.

@Hydrocharged Hydrocharged changed the title Added temporary addition to REPLACE Fixed REPLACE logic to now match MySQL Apr 28, 2021
sql/plan/insert.go Show resolved Hide resolved
@Hydrocharged Hydrocharged merged commit 98b28e8 into master Apr 29, 2021
@Hydrocharged Hydrocharged deleted the daylon/replace-help branch April 29, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants