Repository navigation
Conversation
`StreamingFormatExecutor` reuses one input format for every entry of an asynchronous insert batch (and for the messages of Kafka, NATS, RabbitMQ, FileLog) and calls `resetParser()` between them. `SQLiteInputFormat` had no override, so its per-input state survived: - `sqlite_finished` stayed set after the first input, so every later input of the batch inserted 0 rows and was logged `Ok`. With `async_insert` on by default, two concurrent `INSERT ... FORMAT SQLite` queries often kept only the first one's rows. - `initialized` stayed set after an input that failed mid-read, so the next input kept stepping the failed input's statement and inserted its remaining rows instead of its own. - `statement_reader` keeps facts about the first statement it read (undeclared columns, exact storage class), so a later input's `REAL` column was checked as the earlier input's typeless one and a valid TEXT 'nan' was rejected. The override finalizes the statement, closes the database, frees the in-memory copy of the input, re-creates the statement reader and clears both flags. The order matters: `sqlite3_close` fails with `SQLITE_BUSY` while a statement is unfinalized, and the deserialized database reads the copy without owning it, so the connection is closed explicitly before the `SQLiteDatabase` is reset (its move-assignment would free the copy first). `MySQLDump` and `One` have the same defect class; they are fixed separately. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; 1 full pass).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261104-003400 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261104-000900 |
|
cc @tavplubix @vitlibar, could you review this and add the |
|
Workflow [PR], commit [f9c10bc] Summary: ✅
AI ReviewSummaryPR #129140, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No code changes requested; no inline findings to post. |
|
@groeneai If you open 3 PRs with the same issue in different formats, maybe it's time for an architectural change that prevents this issue from being possible |
|
Acknowledged, agreed. I won't open separate PRs for the two other formats I found with the same problem ( |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline. |
|
I opened #129209: |
…self StreamingFormatExecutor (async insert flushes, Kafka, Kafka2, NATS, RabbitMQ, FileLog) kept one input format object for many independent inputs and called resetParser() between them, trusting every format to bring itself back to the state of a fresh object. Nothing enforced that: 32 of the 82 input format names kept some per-input field (One `done`, Npy `read_rows`, MySQLDump `table_name` and column mapping, SQLite flags and database, JSON `parse_as_json_each_row`, DWARF section extractors, TSV `first_row`, CustomSeparated `columns` and the detected header, RowBinaryWithNamesAndTypes `read_data_types`, Template `row_num`), so a later input of an async insert batch or a later message lost rows, was rejected, or was parsed with the previous input's state. Per-format resetParser fixes (ClickHouse#128943, ClickHouse#129109, ClickHouse#129140) leave the default unsafe for the next format and the next field. Invert the default: a format is reused only when its name is registered with FormatFactory::markInputFormatSupportsResetParser; any other format is released after each input and created anew for the next one. The executor now takes a format creator and an AddingDefaultsTransform creator (the transform holds a reference to the format). The streaming engines compute their single-threaded parser resources once and share them between created formats. Marked: the 50 names whose reset is complete and 26 hot names completed here with one statement each (TSV first_row, CustomSeparated columns, WithNamesAndTypes is_header_detected, RowBinary read_data_types, Template row_num). Reuse matters for them: a fresh CapnProto, Template, Protobuf, Regexp or AvroConfluent object reads or compiles schemas. Not marked, so re-created with no per-format code: One, Npy, MySQLDump, SQLite, JSON, DWARF. DWARF's incomplete resetParser is deleted. 02187_async_inserts_all_formats now also inserts every format as one batch of two different inputs, plus targeted cases for the leaks that a same-shaped pair does not show, and a FileLog case. Closes ClickHouse#122351 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed lost rows when several
INSERT ... FORMAT SQLitequeries are combined into one asynchronous insert batch (asynchronous inserts are enabled by default): only the first query's rows were inserted, and a query that followed a failed one inserted the failed query's remaining rows instead of its own.Description
Related: #128943 (the same defect class in
MsgPack)Related: #129109 (the same defect class in
Npy)On 26.10.2.103, of two concurrent
INSERT INTO t FORMAT SQLitequeries with default settings, often only the first one's rows are inserted (20 of 40 rows in 10 tries), and both clients get success;system.asynchronous_insert_loglogs the lost entryOkwith 0 rows.StreamingFormatExecutorreuses one input format for all entries of an asynchronous insert batch (and for Kafka, NATS, RabbitMQ and FileLog messages) and callsresetParserbetween them, also after a parse error.SQLiteInputFormatdid not override it, so its per-input state survived:sqlite_finishedmade every later input insert nothing; after an input that failed mid-read,initializedmade the next one keep reading the failed input's statement; and the statement reader keeps facts about the first statement's columns, which would reject a valid TEXT'nan'in a later input'sREALcolumn once the flags are cleared.SQLiteInputFormat::resetParsernow finalizes the statement, closes the database, frees the in-memory copy of the input, re-creates the statement reader and clears both flags.file,url,s3and synchronous inserts build one format per input and are unchanged.The new test queues three valid databases, a failing one followed by a valid one, and a typeless column followed by a
REALone into one batch each. On master it gives[1,2],[7]and[2.5]; with the fix it passes 50/50 with randomized settings.MySQLDumpandOnehave the same defect (a later input of a batch is rejected or dropped); they are not addressed here.Workflow [PR]
Sync PR [sync-upstream/pr/129140]