Repository navigation
Description
Description
With the ANTLR4 and ANTLR4_PARAMS_PARSER SQL parser backends, an INSERT whose column list contains an unquoted column named after certain keywords (for example CLIENT, SCHEMA, MODEL, CONDITION, PAGE, CONFIG) fails to parse. The parse error is swallowed, the VALUES list is discarded (getAssignValuesListStartPosition() == -1), and PreparedStatement#executeBatch() silently falls back to one INSERT per row (PreparedStatementImpl#executeBatchImpl → executeUpdateImpl in a loop) instead of a single multi-row INSERT.
The rows are inserted correctly, so nothing fails visibly. The batch is just orders of magnitude slower, and on the server each row becomes its own part. We hit this in a streaming pipeline that flushes JDBC batches during checkpoints. Flushes of ~1,000 rows took minutes, which led to checkpoint timeouts.
The default JAVACC backend parses these statements correctly.
Cause
These tokens are defined in ClickHouseLexer.g4 but are missing from the keyword rule in ClickHouseParser.g4, so they cannot be used as unquoted identifiers. 64 tokens are affected (most were added for SYSTEM ... statements):
ALLOW, ARBITRARY, ASYNCHRONOUS, BLOCKING, CANCEL, CLIENT, COLLECTIONS, COMPILED, CONDITION, CONFIG, CUSTOM, DNS, EMBEDDED, FAILPOINT, FUZZER, GRPC, HIVE, HTTPS, INTROSPECTION, JDBC, JEMALLOC, KAFKA, LISTEN, LOAD, LOADING, MANAGEMENT, MARK, MMAP, MODEL, MONGO, MOVES, MYSQL, NATS, ODBC, PAGE, POLICIES, POSTGRES, POSTGRESQL, PROMETHEUS, PROXY, PULLING, QUEUE, QUEUES, QUOTAS, RABBITMQ, READINESS, REDIS, REDUCE, REPLICAS, REPLICATION, RESTART, SCHEMA, SECRETS, SECURE, SHARDS, SHUTDOWN, SOURCES, SQLITE, TCP, UNCOMPRESSED, UNLOAD, VIEWS, VIRTUAL, WAIT
None of them are in jdbc-v2/src/test/resources/reserved_keywords.txt. (NAN_SQL is also missing, but it is the nan literal, so it is left out.)
Steps to reproduce
// jdbc-v2 0.11.2, url ...?jdbc_sql_parser=ANTLR4
PreparedStatement ps = conn.prepareStatement("INSERT INTO t (id, CLIENT) VALUES (?, ?)");
for (int i = 0; i < 1000; i++) { ps.setInt(1, i); ps.setString(2, "c"); ps.addBatch(); }
ps.executeBatch(); // 1000 INSERT queries in system.query_log, not 1At the parser level:
ParsedPreparedStatement p = SqlParserFacade.getParser("ANTLR4", config)
.parsePreparedStatement("INSERT INTO t (id, CLIENT) VALUES (?, ?)");
p.isHasErrors(); // true
p.getAssignValuesGroups(); // 0
p.getAssignValuesListStartPosition(); // -1The same statement with id, b or with `CLIENT` parses with no errors and one values group.
Expected behaviour
Non-reserved keywords can be used as unquoted column names, and the batch is sent as one INSERT, as with the JAVACC backend.
Workaround
Quote the column (`CLIENT` or "CLIENT").
Environment
- clickhouse-java / jdbc-v2: 0.11.2 (also reproduced on
main) - Parser:
ANTLR4(alsoANTLR4_PARAMS_PARSER) - Java 17
I have a fix (add the missing tokens to the keyword rule, plus a data-driven test across the three parser backends) and will open a PR referencing this issue.
Activity
polyglotAI-bot commentedon Nov 27, 2026
Recommendation: Keep open — fix needed
Review PR #3458: with its diff, every case below sends one INSERT, and the 2058 parser unit tests pass. It also fixes the names of #3451, but not its implicit aliases (
FROM t schema,FROM t timeout): the PR does not changekeywordForAlias.main: Reproduced on main — with both ANTLR4 parsers, a batch of 1000 rows sends 1000 INSERT queries; a quotedCLIENTandJAVACCsend 1.shardsas an identifier #3428 — the same defect forSHARDS; its PR [jdbc-v2] Add SEGMENTS, SHARDS keywords for ClickHouse 26.11; accept shards in the ANTLR4 grammar #3446 also addsSHARDSto thekeywordrule.Analysis: Confirmed on
main: thekeywordrule (ClickHouseParser.g4:1225) does not list 64 lexer tokens (for exampleCLIENT,ClickHouseLexer.g4:54), soidentifier(ClickHouseParser.g4:1800) rejects them. After the parse error,SqlParserFacade.java:264-266drops the values list, soPreparedStatementImpl.java:99does not select the multi-row path, andexecuteBatchImpl(:350-356) runs each row.Reproduction: complete program and output
Changed from the issue's steps: added the table, the
system.query_logcount, and the cases forANTLR4_PARAMS_PARSER, a quoted column, andJAVACC.Output on
main(8480ca001), ClickHouse 26.11.2.4:Output with the diff of PR #3458:
Automated triage by Polyglot AI. A maintainer makes the final decision.