Skip to content

Refuse the Quantized codec in Log, TinyLog and Buffer tables - #127795

Merged
shankar-iyer merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-log-quantized-product-codec
Nov 16, 2026
Merged

shankar-iyer merged 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-log-quantized-product-codec

Conversation

@groeneai

@groeneai groeneai commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #118714

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Log, TinyLog and Buffer tables now refuse a column with the experimental Quantized codec with ILLEGAL_COLUMN.

Description

The Quantized codec does not work with these engines:

  • Log/TinyLog: on 26.8, 26.9 and 26.10, every INSERT into a table with a Quantized('product', ...) column fails with LOGICAL_ERROR: Stream was not created when writing data in LogSink (a debug-build abort, stack-use-after-scope under ASan), because LogSink::createStreamGetter captured a temporary NameAndTypePair by reference. It now captures it by value. Even with that fixed, Log writes the codebook per insert but reads it once per source, the same limitation that makes it refuse Variant.
  • Buffer: reading the codes of buffered rows fails, because buffered rows have no codebook. Found by the AST fuzzer (report):
SET enable_quantized_codec = 1;
CREATE TABLE dst (id UInt32, vec Array(Float32) CODEC(Quantized('product', 8, 2, 4))) ENGINE = MergeTree ORDER BY id;
CREATE TABLE buf AS dst ENGINE = Buffer(currentDatabase(), dst, 1, 1000, 1000, 1000000, 1000000, 100000000, 100000000);
INSERT INTO buf SELECT number, arrayMap(j -> toFloat32(j), range(8)) FROM numbers(4);
SELECT vec.quantized FROM buf; -- LOGICAL_ERROR: Column or subcolumn 'vec.quantized' not found in Buffer table

These engines now refuse every Quantized method with ILLEGAL_COLUMN for a fresh definition (CREATE, CREATE ... AS, CREATE ... AS SELECT, full-definition ATTACH, and for Buffer also a structure inferred from the destination) and, for Buffer, on ALTER ... ADD/MODIFY COLUMN with the codec. A table stored by an older server still loads. 02184_storage_add_support_ttl now expects this for its Buffer over a Merge table with the codec.

The test fails on master and on the previous head of this PR, which refused only product, and passes with the fix (50/50 randomized runs, also with --replicated-database); removing any of the three checks makes it fail. Tables created on master load with the fix, and inserts into their int8 Log tables keep working. Not for changelog: the codec is experimental (enable_quantized_codec).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/127795]

Version info

  • Merged into: 26.11.1.2404-master (included in 26.11 and later)

groeneai and others added 2 commits October 25, 2026 22:23
An INSERT into a Log or TinyLog table with a `Quantized('product')` column
failed with LOGICAL_ERROR "Stream was not created when writing data in
LogSink" (abort in debug builds, stack-use-after-scope under ASan).
`LogSink::onFinish` passes a temporary `NameAndTypePair` to
`createStreamGetter`, whose closure captured it by reference, so the getter
read a destroyed object when `SerializationQuantizedVector` wrote the
per-part codebook in `serializeBinaryBulkStateSuffix`. Capture it by value.

With that fixed, the insert succeeds but the data cannot be read back
correctly: LogSink writes one codebook per INSERT, while LogSource reads it
once per source and broadcasts it, the same limitation that already makes
Log refuse Variant. Measured on a build with only the capture fix: after two
inserts, `vec.product_quantization_codebook` returns the first insert's
codebook for the second insert's rows (MergeTree returns two codebooks), and
on TinyLog a codebook read of a 4-row table returns 65409 rows.

So Log and TinyLog refuse a column with this serialization with
ILLEGAL_COLUMN for a fresh definition (CREATE, CREATE AS, CREATE AS SELECT,
full-definition ATTACH), and `write` refuses INSERT for every table, so a
definition stored by an older server still loads and can be dropped. The
refusal checks the column's serialization over its type tree rather than
its codec, because a column inferred by `CREATE ... AS SELECT` keeps the
serialization of the source column without its codec. The data-independent
methods are unaffected.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rewrite the checkSupportedCodecs comment as a standalone invariant, dropping the narration of the check below it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 findings over 3 rounds, the last round clean) plus my own review (3 findings).

# Sev Finding Verdict Evidence / action
1 ❌ CREATE TABLE ... ENGINE = Log AS SELECT from a Quantized('product') column bypassed the refusal: the inferred column keeps the serialization but not the codec (StorageLog.cpp, checkSupportedCodecs) AGREE, fixed the check looks at the column's serialization over its type tree; the test covers AS SELECT on both engines
2 ⚠️ No test exercises the stored-definition load and the INSERT-time refusal DISAGREE such a definition cannot be created through SQL on a fixed build, and a test would have to hand-write stored metadata; validated locally: tables created by the base build load with the fix, INSERT returns ILLEGAL_COLUMN, DROP works
3 ⚠️ The test did not pin the type-tree walk (a product column nested in tuple(...) or [...]) AGREE, fixed nested AS SELECT refusals added for both engines; a top-level-only check fails exactly those lines
4 💡 PR text called stored tables "always empty" (the old failure is undefined behaviour) AGREE, fixed reworded
5 💡 The by-value capture is not exercised by the test noted after the refusal no Log state suffix writes through the getter; kept, it is the measured cause of the LOGICAL_ERROR
6 💡 The AS SELECT refusal names a codec the new definition does not declare noted the column inherits the serialization from the source; the description explains the case

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Also noticed: CREATE ... AS SELECT from an int8-quantized column keeps the serialization without the codec in any engine; a separate bug, not in this PR.

Session id: cron:clickhouse-review-self-slot-58:20261025-222500

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: the 3-statement INSERT in the description aborts a debug build every time (Log and TinyLog); Code: 49 LOGICAL_ERROR on 26.8.21.12, 26.9.7.6, 26.10.1.286.
b Root cause explained? The getter built in LogSink::onFinish captured a temporary NameAndTypePair by reference; the product suffix writes its codebook through it after the temporary is gone. Even with that fixed, Log writes a codebook per insert but reads it once per source (wrong reads, measured).
c Fix matches root cause? Yes: by-value capture at the lifetime source; a column with the product serialization is refused where Log already refuses Variant for the same read-once reason. The check reads the serialization, not the codec, because a column inferred by AS SELECT keeps the serialization without the codec.
d Test intent preserved / new tests added? New 05452_log_quantized_product_codec.sql: refusals for Log, TinyLog, CREATE ... AS, CREATE ... AS SELECT on both engines (also with the column nested in Tuple/Array), full-definition ATTACH, plus an explicit-column AS SELECT control and int8 controls on both engines.
e Both directions demonstrated? Base build: test FAILS on the 9 refusal lines (the server stays up); fix: OK, 50/50 randomized. Removing the CREATE-time check, limiting it to CREATE, refusing every column, checking only the codec, or checking only the top-level type each make it fail.
f Fix is general across code paths? Other getter users (writeData, LogSource readers) keep their argument alive; other suffix writers cannot reach the getter in LogSink; TinyLog shares the code; StripeLog/Memory use Native, which writes no codebook; a materialized view's inner table is created from a formatted column list and does not carry the serialization (measured).
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked Array(Float32/Float64/BFloat16), lowercase codec name, Quantized(...), ZSTD chains, temporary tables, CTAS with and without a column list, a quantized column nested in Array/Tuple by AS SELECT; only product is refused (int8, rabitq stay allowed).
h Backward compatible? (maintainer-approved exception only) Yes: a table stored by an older server still loads, reads and drops; only a new definition and INSERT are refused, and INSERT never worked there. No setting changed.
i Invariants and contracts preserved? The getter no longer outlives its data; the refusal runs before the write lock and before the sink exists, so a refused INSERT leaves no partial marks or sizes; a refused AS SELECT creates no table.

Session id: cron:clickhouse-impl-self-slot-57:20261025-221800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @Avogar @shankar-iyer, could you review this and add the can be tested label so CI runs? Log/TinyLog write the Quantized('product') codebook per insert but read it once per source (like the Variant prefix), so such a column is now refused with ILLEGAL_COLUMN; the LogSink stream getter also captured a temporary NameAndTypePair by reference, which caused the LOGICAL_ERROR, and now captures it by value.

@clickhouse-gh

clickhouse-gh Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [15a5c42]

Summary: ✅


AI Review

Summary

The PR refuses Quantized columns in new Log, TinyLog, and Buffer definitions and in Buffer codec alterations, preserves stored definitions, and fixes the captured argument lifetime in LogSink::createStreamGetter. No actionable findings remain. The added stateless test passed against the PR's CI binary and matched its reference output.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... labels Oct 25, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 27, 2026
In a Replicated database, CREATE TABLE ... AS SELECT is replicated as a
formatted query with an explicit column list, so the new table is created
from that list and does not inherit the Quantized('product') serialization
of the source column. The table is then a plain Array(Float32) table, which
is correct, but the five ILLEGAL_COLUMN expectations failed in the
DBReplicated stateless job. The arms now create their tables in a dedicated
Atomic database, so they check the inferred-type path in every lane.

A populated AS SELECT is also refused by the check in StorageLog::write, so
those arms cannot tell whether the CREATE check fired. Two EMPTY AS SELECT
arms (top-level on Log, nested on TinyLog) skip the insert and pin the
CREATE check itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 10807b4

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build profile diff infra, not from this PR: the CI logs cluster never passed the readiness probe, so the job ended with LogClusterNotReady: the endpoint never became ready before comparing anything. 349 of 353 runs since 2026-10-26 22:00 UTC are red, on 260 PRs #126200 (mine, open)
PR praktika rollup of the row above #126200 (the owner of the row above)

05452_log_quantized_product_codec now passes in every job that ran it, including Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 2/2) and the flaky checks (50/50 each). CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261028-013006

Comment thread src/Storages/StorageLog.cpp Resolved
Comment thread src/Storages/StorageLog.cpp Resolved
Comment thread src/Storages/StorageLog.cpp Resolved
@rschu1ze

rschu1ze commented Nov 9, 2026

Copy link
Copy Markdown
Member

@shankar-iyer Could you check this one please if you have time?

Review feedback on ClickHouse#127793 and ClickHouse#127795: refuse the Quantized codec in
Buffer the same way as in Log and TinyLog, for every method rather than
only `product`.

Buffer: a `product` column read a subcolumn of buffered rows that the
buffer cannot produce, so `SELECT vec.quantized` from a Buffer with
unflushed rows aborted with LOGICAL_ERROR "Column or subcolumn 'vec.quantized'
not found in Buffer table" (AST fuzzer, arm_asan_ubsan:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=121674&sha=660cb5a2ee&name_0=PR).
A fresh Buffer definition (explicit columns, `AS <table>`, a structure
inferred from the destination, full-definition ATTACH) is now refused
with ILLEGAL_COLUMN, and so is `ALTER ... ADD/MODIFY COLUMN` with the
codec. The ALTER check looks at the codec, because MODIFY COLUMN sets the
codec without attaching its serialization.

Log and TinyLog now refuse every method, not only `product`. The check in
`StorageLog::write` is removed: it existed only for definitions stored by
older servers, which are replayed without the CREATE check, and with
every method refused it would also break inserts into `int8` Log tables
that work today. The by-value capture in `LogSink::createStreamGetter`
stays.

Closes ClickHouse#118714

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai changed the title Refuse the Quantized('product') codec in Log and TinyLog tables Refuse the Quantized codec in Log, TinyLog and Buffer tables Nov 9, 2026
The Buffer case of 02184 infers its structure from a Merge table whose
`vec` column carries the Quantized codec of one source table. Buffer now
refuses any Quantized codec, so that CREATE fails with ILLEGAL_COLUMN
(Fast test on c38a612). Distributed and Remote still cover the
inherited-TTL case over the same Merge table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 15a5c4293 with master 4ce893869 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

13 translation units recompiled, 66 s compile time in total, 13 of them have a recent master baseline.

Job report

@shankar-iyer
shankar-iyer added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit 9fce705 Nov 16, 2026
188 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

5 participants