Skip to content

Report NOT_IMPLEMENTED instead of a logical error when a Buffer table cannot read a codec subcolumn from its unflushed rows - #127793

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-buffer-quantized-codec-subcolumn
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:fix-buffer-quantized-codec-subcolumn

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):

...

Description

Reading the codes of a Quantized('product', ...) column from a Buffer table that still holds unflushed rows threw Logical error: 'Column or subcolumn 'vec.quantized' not found in Buffer table' (an abort in debug and sanitizer builds). It was found by AST fuzzer (arm_asan_ubsan) (report) and reported in #118714:

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, 100000, 100000, 1000000, 1000000, 1000000000, 1000000000);
INSERT INTO buf SELECT number, arrayMap(j -> toFloat32(j), range(8)) FROM numbers(4);
SELECT sum(cityHash64(vec.quantized)) FROM buf;

The product codes and codebook depend on a codebook trained per part, so SerializationQuantizedVector gives them no in-memory value and tryGetColumnFromBlock returns null on the buffered block. BufferSource::generate treated any null as a column missing from the block. Now, when the storage column is in the block but the subcolumn cannot be computed from it, the read fails with NOT_IMPLEMENTED, the code Memory, StripeLog, EmbeddedRocksDB and Join already return here. A column really missing from the block is still a LOGICAL_ERROR. Subcolumns the in-memory value can produce (size0, the codes of data-independent methods such as int8) are still read from the buffer, and after a flush the codes come from the destination.

Not for changelog: the Quantized codec is experimental (enable_quantized_codec).

Validation: the new test aborts a base-build server and passes on the fix, 50/50 with random settings and 5/5 with parallel replicas. Dropping the new branch, refusing every subcolumn or every codec subcolumn, or returning default codes each fail it. The *buffer*, 02354_vector_search_*, 05241_*, 05321_* and 01475_read_subcolumns_storages tests give identical results on both builds.

🤖 Generated with Claude Code


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

…om its rows

Reading `vec.quantized` or `vec.product_quantization_codebook` of a
`Quantized('product', ...)` column from a `Buffer` table that still holds
unflushed rows threw `LOGICAL_ERROR "Column or subcolumn ... not found in
Buffer table"` (ClickHouse#118714, found by the AST fuzzer).

The `product` codes depend on the per-part trained codebook, so
`SerializationQuantizedVector::enumerateStreams` gives these substreams no
column and no lazy creator, and `tryGetColumnFromBlock` returns null for the
buffered block. `BufferSource::generate` read every null as a column lost from
the block. The column is in the block; its subcolumn just cannot be computed
from an in-memory value, which `IDataType::getSubcolumn` already reports as
NOT_IMPLEMENTED for Memory, StripeLog, EmbeddedRocksDB and Join.

Now a subcolumn whose storage column is in the buffered block but cannot be
extracted is refused with NOT_IMPLEMENTED; a column missing from the block is
still a LOGICAL_ERROR. Subcolumns the value can produce (`size0`, the codes of
data-independent methods such as `int8`) are still read from the buffer.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121674&sha=660cb5a2eea7efc974c72871133b9d62da7cff2c&name_0=PR&name_1=AST%20fuzzer%20%28arm_asan_ubsan%29
Found on PR: ClickHouse#121674

Closes ClickHouse#118714

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds): 2 fixed, 1 not-blocking, round 2 clean
Finding Verdict
❌ The int8 arm read vec.quantized from a SELECT * subquery column, so both sides ran the same in-memory encoder and the buffer read path was never checked AGREE, fixed: the arm reads the subcolumn from the tables, and a mutation that refuses every codec subcolumn now fails it
💡 Commit message lacked the CI report link AGREE, fixed
💡 The after-flush arm checks one distinct code length, not the codes not blocking: the arm checks that the read no longer refuses after the flush

Round 2 (own review + second model on the fixed head): no findings.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The SQL in the description aborts the base debug build every time (StorageBuffer.cpp:258, BufferSource::generate), for vec.quantized and vec.product_quantization_codebook.
b Root cause explained? product codes and codebook need the per-part trained codebook, so SerializationQuantizedVector gives them no in-memory value; tryGetColumnFromBlock returns null, and BufferSource::generate read every null as a column missing from the buffered block.
c Fix matches root cause? Yes. A subcolumn whose storage column is in the block but cannot be computed is refused with NOT_IMPLEMENTED; a missing column is still LOGICAL_ERROR.
d Test intent preserved / new tests added? New 05452_buffer_quantized_codec_subcolumn: refusal for codes and codebook, size0 and int8 codes still read from the buffer (equal to MergeTree's), read after flush.
e Both directions demonstrated? The test kills a base-build server and passes on the fix, 50/50 with random settings and 5/5 with parallel replicas. Refusing every subcolumn or every codec subcolumn, or returning default codes, also fails it.
f Fix is general across code paths? BufferSource is the only reader of buffered rows (merge() over a Buffer checked). Memory, StripeLog, EmbeddedRocksDB and Join already return NOT_IMPLEMENTED.
g Fix generalizes across inputs (params/datatypes/wrappers)? Both product subcolumns covered; data-independent int8 codes and generic size0 still served; an empty buffer and a flushed one read from the destination.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or persisted state; only a LOGICAL_ERROR becomes NOT_IMPLEMENTED. The Buffer / vector-search / subcolumn tests give identical results on both builds.
i Invariants and contracts preserved? Every header column still gets one column of rows() rows or the source throws before setting the chunk; the buffer lock scope is unchanged.

Session id: cron:clickhouse-impl-slot-6:20261025-213800

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat @rschu1ze, could you review this and add the can be tested label so CI runs? BufferSource::generate treated a subcolumn it cannot compute from the buffered rows (the codes and codebook of a Quantized('product', ...) column) as a missing column and threw a logical error; it now returns NOT_IMPLEMENTED, like Memory/StripeLog/Join, and keeps LOGICAL_ERROR for a column really missing from the block.

@clickhouse-gh

clickhouse-gh Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4347bc3]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, sequential) FAIL
05218_text_index_substreams_opened_lazily FAIL cidb
Stateless tests (arm_binary, parallel) FAIL
05055_format_schema_source_query_background_access FAIL cidb

AI Review

Summary

PR #127793 replaces an inappropriate LOGICAL_ERROR with NOT_IMPLEMENTED when a Buffer table cannot extract a subcolumn from unflushed rows. No actionable findings at commit 4347bc307f532413632c857b327c891c19a28256. The added regression test passes in Fast test.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Oct 25, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 25, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-simple-engines Lightweight single-node table engines: Log/StripeLog (append-only logs), Buffer (async batching),... label Oct 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4347bc307 with master a3c141896 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of a2228ac0b; 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

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4347bc3

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
Stateless tests (arm_binary, parallel) / 05055_format_schema_source_query_background_access flaky, not from this PR (its StorageBuffer.cpp change is on the read path only): background flush refused: 1 -> 0 with session_timezone = Africa/Juba at 00:54 local time, so the session date was ahead of the server date the text_log filter compares with. Passes 21/21 without random settings; the same failure is on 7 other PRs and master since 2026-10-25 21:25Z #127797 (mine, open)
Stateless tests (amd_debug, sequential) / 05218_text_index_substreams_opened_lazily flaky, not from this PR: in_range_above_threshold 1 -> 0; the runner's random-settings diagnosis isolates use_columns_cache = 1 (17/17 fail with the draw, 20/20 pass without). 16 failures on master in 30 days #127781 (mine, open)
Mergeable Check, PR praktika rollups of the rows above #127797, #127781 (the owners of the rows above)

The Config Workflow / Pre Hooks row in CIDB is from the first run, before the can be tested label was added; the re-run passed it. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261026-020004

@rschu1ze

rschu1ze commented Nov 9, 2026

Copy link
Copy Markdown
Member

@groeneai This fix is too nasty. Make an extra commit in #127795 which rejects the Quantized codec for Buffer tables similar like the codec is rejected for Log and TinyLog tables.

@rschu1ze rschu1ze closed this Nov 9, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 9, 2026
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 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Done in c38a612: Buffer now refuses the Quantized codec like Log and TinyLog do (every method, at CREATE and ALTER), and #127795 now closes #118714.

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

Projects

None yet

3 participants