Convert REPLACE INTO -> INSERT ON DUPLICATE KEY UPDATE (MySQL) #601
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changed?
Converted all REPLACE INTO usages with INSERT ON DUPLICATE KEY UPDATE semantics.
Docs - https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html
Why?
Vitess does not support REPLACE INTO with fully sharded setups as REPLACE INTO deletes and reinserts the new row, which could possibly be in another shard depending on the VIndex. INSERT ON DUPLICATE KEY UPDATE forces you to specify which columns are being updated (cannot be VIndex column) and modifies the existing row.
How did you test it?
Existing Unit Tests, Buildkite, Manual BenchTest on EKS cluster.
Potential risks
Update behavior change of REPLACE vs INSERT could bring in subtle changes in behavior, but this should not be a major issue.
Todo
This needs to be validated for Postgres, but as Postgres does not support REPLACE INTO, this may not be an issue. In any case this is a backwards compatible change. Will do in a separate PR.