Repository navigation
[jdbc-v2] Keep the INSERT target when the ANTLR4 parser sees source tables - #3352
Merged
chernser merged 1 commit intoNov 17, 2026
Merged
Conversation
chernser
approved these changes
Nov 17, 2026
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.
Summary
With the
ANTLR4andANTLR4_PARAMS_PARSERbackends,ParsedPreparedStatement.getTable()of anINSERTreturned the last table read anywhere in the statement (a CTE name, aFROM/JOINtable, or a table in a scalar subquery insideVALUES) instead of the insert target. Withbeta.row_binary_for_simple_insert=true, the RowBinary writer was then built against the source table and the row was written there.enterInsertStmtsets the target, but ANTLR entersinsertStmtbefore its nestedtableExprIdentifiernodes, andenterTableExprIdentifieroverwrotetable/databasefor each of them.Change:
enterTableExprIdentifierno longer sets the table once the statement is known to be an insert (setInsert(true)runs inenterInsertStmt, before the children are entered). Statements that are not inserts keep using it as the only source of the name.Unchanged:
INSERT INTO [TABLE] FUNCTION f(...)still setsuseFunction, and the defaultJAVACCbackend is not touched.Closes #3129
Checklist
BaseSqlParserFacadeTest#testInsertTargetIsNotReplacedBySourceTable, run for all three backends: CTE,FROM, qualifieddb1.dstfromdb2.src,JOIN, scalar subquery inVALUES, plus inserts and selects without the problem). The five affected cases fail onmainfor both ANTLR4 backends and pass with the fix. The database assertion is skipped forJAVACC, which reports the database only as part of the table name.history/latest/3129.md)Note
Medium Risk
Incorrect insert targets could route RowBinary writes to source tables when
beta.row_binary_for_simple_insert=true; the fix is narrow but touches prepared-statement parsing used for all INSERTs on ANTLR4 backends.Overview
Fixes a jdbc-v2 parsing bug on the ANTLR4 and ANTLR4_PARAMS_PARSER backends where
ParsedPreparedStatement.getTable()forINSERTstatements was overwritten by the last table referenced in the query (CTEs,FROM/JOIN, or subqueries inVALUES).enterTableExprIdentifiernow skips updating database/table when the statement is already marked as an insert, so the target set inenterInsertStmtis kept. Non-insert statements behave as before.Regression coverage was added via
testInsertTargetIsNotReplacedBySourceTable, and CHANGELOG entryhistory/latest/3129.mddocuments the fix (closes #3129).Reviewed by Cursor Bugbot for commit 07bc0de. Bugbot is set up for automated code reviews on this repo. Configure here.