Repository navigation
[jdbc-v2] Send the writer INSERT to the database selected with setSchema - #3398
Open
piyush15102003 wants to merge 1 commit into
Open
piyush15102003 wants to merge 1 commit into
piyush15102003 wants to merge 1 commit into
Conversation
The RowBinary writer built its InsertSettings without a database, so the INSERT went to the database from the connection configuration even though the table schema was resolved in the one set by Connection.setSchema. Closes ClickHouse#3212
1 task
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
beta.row_binary_for_simple_insert=true, anINSERTprepared afterConnection.setSchema(db)ignoreddb.ConnectionImpl.prepareStatementresolves the table schema in the connection schema (client.getTableSchema(table, schema)), butWriterStatementImpl.executeLargeUpdatebuiltInsertSettingswithout a database, so the request used the database from the client configuration. If a table with the same name existed there, the rows were silently written to it; otherwise the insert failed withUNKNOWN_TABLE.Change:
WriterStatementImpl.executeLargeUpdatesetsInsertSettings.setDatabase(tableSchema.getDatabaseName()), so the INSERT goes to the database the schema was resolved in. A qualified table name (db1.t) still wins on the server side.The non-writer path (
PreparedStatementImpl) already used the connection schema and is not changed.Closes #3212
Checklist
WriterStatementImplTest#testWriterInsertsIntoDatabaseSelectedWithSetSchema): same table name in both databases, and a table that exists only in the selected database. It fails onmainand passes with the fix; the other 38 tests inWriterStatementImplTestpass.history/latest/3212.md)Note
Medium Risk
Targets insert routing in the beta RowBinary writer path; behavior change for multi-database use, but aligns with existing prepare-time schema resolution and is covered by integration tests.
Overview
Fixes a bug where
beta.row_binary_for_simple_insert=trueINSERTs prepared afterConnection.setSchema(db)did not targetdb.WriterStatementImpl.executeLargeUpdatenow setsInsertSettings.setDatabase(tableSchema.getDatabaseName()), so the RowBinary insert uses the same database schema resolution used atprepareStatementtime instead of the connection URL’s default database.Rows no longer land in a same-named table in the default DB or fail with
UNKNOWN_TABLEwhen the table exists only in the selected schema. Qualified names (db.table) are unchanged on the server side.An integration test covers ambiguous table names across two databases and tables that exist only in the selected schema; a changelog note was added for #3212.
Reviewed by Cursor Bugbot for commit c0e095a. Bugbot is set up for automated code reviews on this repo. Configure here.