Support REPLACE and IGNORE in MySQL :copyfrom Queries#4350
Open
noxymon wants to merge 1 commit intosqlc-dev:mainfrom
Open
Support REPLACE and IGNORE in MySQL :copyfrom Queries#4350noxymon wants to merge 1 commit intosqlc-dev:mainfrom
noxymon wants to merge 1 commit intosqlc-dev:mainfrom
Conversation
Ensures that REPLACE INTO and INSERT IGNORE INTO statements are correctly translated to LOAD DATA LOCAL INFILE REPLACE and LOAD DATA LOCAL INFILE IGNORE respectively when using the :copyfrom directive in MySQL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
When using the
:copyfromdirective with MySQL insqlc, users were limited to standardINSERT INTOoperations. MySQL supports optimized bulk loading viaLOAD DATA LOCAL INFILE, and users often need to handle duplicate keys or errors using theREPLACEorIGNOREmodifiers. Previously, even if a user specifiedREPLACE INTOorINSERT IGNORE INTOin their SQL query,sqlcwould translate these to a standardLOAD DATA LOCAL INFILEwithout the necessary modifiers, leading to potential constraint violations or unintended failures during bulk inserts.Fix Proposal
This PR introduces support for
REPLACEandIGNOREmodifiers in:copyfromqueries for the MySQL engine as fixes #4339 . The compiler and codegen have been updated to track these modifiers from the initial SQL AST through to the final Go code generation.Technical Implementation:
IsReplaceandIgnoreErrfields to theast.InsertStmtininternal/sql/ast/insert_stmt.go.dolphinengine'sconvertInsertStmtto propagateIsReplaceandIgnoreErrfrom the MySQL-specific parser AST to the unified AST._analyzeQueryininternal/compiler/analyze.goto extract these flags during semantic analysis.plugin.Querymessage in the codegen protocol to includeis_replaceandignore_errfields, ensuring that language-specific generators can access this information.internal/codegen/golang/query.goandresult.go.copyfromtemplate (internal/codegen/golang/templates/go-sql-driver-mysql/copyfromCopy.tmpl) to conditionally injectREPLACEorIGNOREinto the generatedLOAD DATA LOCAL INFILEstatement.mysql_copyfrom_replaceto verify that bothREPLACEandIGNOREmodifiers are correctly generated in the resulting Go code.Verification Results
REPLACE INTO ...results inLOAD DATA LOCAL INFILE REPLACE ....INSERT IGNORE INTO ...results inLOAD DATA LOCAL INFILE IGNORE ....