[jdbc-v2] RowBinary writer drops the quotes of the INSERT table name: names that need quotes fail, a quoted name with a dot writes to another table
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
調査の方向性
Start with ConnectionImpl.prepareStatement around lines 474–478 and trace how parsedStatement.getTable() is passed to Client.getTableSchema; then check WriterStatementImpl and the related open PRs #3390 and #3398. Reproduce with the supplied Java program and quoted table names. Done means the RowBinary writer describes and inserts into the correctly quoted database and table, matching the writer-off behavior.
索引モデルが issue の本文から書いたものです。
説明
Description
With beta.row_binary_for_simple_insert=true, Connection.prepareStatement("INSERT INTO <table> VALUES (?)") takes the table name without its quotes. There are two results:
- When a table name or a database name needs quotes (
`t?q`,`t-q`,"t-q",`my table`,`my-db`.t),prepareStatementthrows a server syntax error orUNKNOWN_TABLE. - A quoted table name that contains a dot (
`a.b`) is read as databasea, tableb. When that table exists,executeUpdate()writes the row intoa.band returns 1, with no error. The tabledefault.`a.b`gets nothing.
All three parsers (JAVACC, ANTLR4, ANTLR4_PARAMS_PARSER) give the same results. With the writer off, each of these statements inserts into the correct table.
Steps to reproduce
- Create the tables of "
CREATE TABLEstatements" below. - Run the program of "Code Example": it prepares
INSERT INTO <name> VALUES (?)for each table with the writer on, then counts the rows. The last insert is with the writer off.
Error Log or Exception StackTrace
writer=true INSERT INTO `t?q` VALUES (?) -> ServerException: Code: 62. DB::Exception: Syntax error: failed at position 17 (?): ?q
writer=true INSERT INTO `t-q` VALUES (?) -> ServerException: Code: 62. DB::Exception: Syntax error: failed at position 17 (-): -q
writer=true INSERT INTO "t-q" VALUES (?) -> ServerException: Code: 62. DB::Exception: Syntax error: failed at position 17 (-): -q
writer=true INSERT INTO `my table` VALUES (?) -> ServerException: Code: 60. DB::Exception: Table default.my does not exist. (UNKNOWN_TABLE)
writer=true INSERT INTO `my-db`.t VALUES (?) -> ServerException: Code: 62. DB::Exception: Syntax error: failed at position 18 (-): -db.t
writer=true INSERT INTO `a.b` VALUES (?) -> OK, rows=1
count default.`a.b` = 0
count a.b = 1
writer=false INSERT INTO `a.b` VALUES (?) -> OK, rows=1
count default.`a.b` = 1
system.query_log shows the statements that the writer sent for `a.b`: DESCRIBE TABLE a.b and INSERT INTO a.b (id) FORMAT RowBinary.
Expected Behaviour
The writer uses the table that the statement names, as the path with the writer off does. The server finds these tables only with the quotes: DESCRIBE TABLE `t?q` returns id Int32, and DESCRIBE TABLE t?q fails with Syntax error: failed at position 17 (?).
Root cause: ConnectionImpl.java:474-478 gives parsedStatement.getTable() to client.getTableSchema(table, schema), but the parser returns the names without quotes and joins the database and the table with a . (SqlParserFacade.java:96, :272, :552). Client.getTableSchema needs an escaped name (its Javadoc, since #3089) and puts it into DESCRIBE TABLE as it is (Client.java:2361). WriterStatementImpl.java:127 gives the same name to Client.insert (Client.java:1846).
The fix is in ConnectionImpl.prepareStatement: quote the database and the table separately before the schema lookup. Polyglot AI can open a fix PR if a maintainer assigns this issue to @polyglotAI-bot.
Related: open PRs #3390 (the same getTableSchema call) and #3398 (the database of the same writer insert) change these lines.
Code Example
Reproduction program (Java, 40 lines)
import java.sql.*;
import java.util.Properties;
public class Repro {
static Connection open(boolean writer) throws SQLException {
Properties p = new Properties();
p.setProperty("user", "default");
p.setProperty("password", System.getenv("CLICKHOUSE_PASSWORD"));
p.setProperty("beta.row_binary_for_simple_insert", String.valueOf(writer));
return new com.clickhouse.jdbc.Driver().connect("jdbc:clickhouse://clickhouse:8123/default", p);
}
static void insert(boolean writer, String table) {
String sql = "INSERT INTO " + table + " VALUES (?)";
try (Connection c = open(writer); PreparedStatement ps = c.prepareStatement(sql)) {
ps.setInt(1, 7);
System.out.println("writer=" + writer + " " + sql + " -> OK, rows=" + ps.executeUpdate());
} catch (Exception e) {
String m = e.getMessage().split("\\. Expected one of|\\(version")[0];
System.out.println("writer=" + writer + " " + sql + " -> " + e.getClass().getSimpleName() + ": " + m);
}
}
static void count(String table) throws SQLException {
try (Connection c = open(false); ResultSet rs = c.createStatement().executeQuery("SELECT count() FROM " + table)) {
rs.next();
System.out.println("count " + table + " = " + rs.getLong(1));
}
}
public static void main(String[] args) throws Exception {
for (String t : new String[]{"`t?q`", "`t-q`", "\"t-q\"", "`my table`", "`my-db`.t", "`a.b`"}) {
insert(true, t);
}
count("default.`a.b`");
count("a.b");
insert(false, "`a.b`"); // contrast: writer off
count("default.`a.b`");
}
}
Configuration
Client Configuration
p.setProperty("beta.row_binary_for_simple_insert", "true"); // jdbc_sql_parser: default (JAVACC); ANTLR4 and ANTLR4_PARAMS_PARSER give the same results
Environment
- Cloud
- Client version: jdbc-v2
main8480ca001 (0.12.0-rc1-SNAPSHOT) - Language version: OpenJDK 17.0.21
- OS: Linux (Docker)
ClickHouse Server
- ClickHouse Server version: 26.11.2.4
- ClickHouse Server non-default settings, if any: none
CREATE TABLEstatements for tables involved:CREATE DATABASE `my-db`; CREATE DATABASE a; CREATE TABLE `t?q` (id Int32) ENGINE = MergeTree ORDER BY id; CREATE TABLE `t-q` (id Int32) ENGINE = MergeTree ORDER BY id; CREATE TABLE `my table` (id Int32) ENGINE = MergeTree ORDER BY id; CREATE TABLE `my-db`.t (id Int32) ENGINE = MergeTree ORDER BY id; CREATE TABLE `a.b` (id Int32) ENGINE = MergeTree ORDER BY id; CREATE TABLE a.b (id Int32) ENGINE = MergeTree ORDER BY id;- Sample data for all these tables: none (empty tables)
Classification: impact: Data integrity · area: Queries (table name quoting)
Found by automated analysis (Polyglot AI) while working on ClickHouse/clickhouse-rs#551. Verified against a live server.
- 主要言語
- Java
- スター
- 1.6k
- フォーク
- 657
- 平均マージ
- 2日 6時間
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ClickHouse/clickhouse-java のほかの issue
-
api-diagnostics bug jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
ClickHouse/clickhouse-java#3464 ·
メンテナーはふだん 1 日以内に返信
-
tests
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3452 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc performance queries sql-parser
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
ClickHouse/clickhouse-java#3451 ·
メンテナーはふだん 1 日以内に返信
-
bug jdbc legacy queries
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
ClickHouse/clickhouse-java#3444 ·
メンテナーはふだん 1 日以内に返信
-
api-diagnostics bug client jdbc
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ClickHouse/clickhouse-java#3439 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
ClickHouse/clickhouse-java の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 60/100
quelea-projection/Quelea#749 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
erkamyaman/rust-anything#963 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 76/100
-
Deferred
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Sanne/incus-spawn#2768 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
morluto/rea#15041 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信