Skip to content

[jdbc-v2] Send the writer INSERT to the database selected with setSchema - #3398

Open
piyush15102003 wants to merge 1 commit into
ClickHouse:mainfrom
piyush15102003:fix/writer-insert-database
Open

piyush15102003 wants to merge 1 commit into
ClickHouse:mainfrom
piyush15102003:fix/writer-insert-database

Conversation

@piyush15102003

@piyush15102003 piyush15102003 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With beta.row_binary_for_simple_insert=true, an INSERT prepared after Connection.setSchema(db) ignored db. ConnectionImpl.prepareStatement resolves the table schema in the connection schema (client.getTableSchema(table, schema)), but WriterStatementImpl.executeLargeUpdate built InsertSettings without 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 with UNKNOWN_TABLE.

Change:

  • WriterStatementImpl.executeLargeUpdate sets InsertSettings.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


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=true INSERTs prepared after Connection.setSchema(db) did not target db. WriterStatementImpl.executeLargeUpdate now sets InsertSettings.setDatabase(tableSchema.getDatabaseName()), so the RowBinary insert uses the same database schema resolution used at prepareStatement time 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_TABLE when 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.

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
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.

[jdbc-v2] Connection.setSchema is ignored by the RowBinary writer INSERT path (rows go to the connection's configured database)

1 participant