Skip to content

Keep columns_read_under_other_names in a serialized ReadFromFormatInfo - #131173

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:keep-columns-read-under-other-names-in-serialized-read-info
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:keep-columns-read-under-other-names-in-serialized-read-info

Conversation

@groeneai

@groeneai groeneai commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131029
Related: #130793
Related: #124545

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

Follow-up to #131029, as asked in #131029 (comment) (review point #131029 (comment)).

ReadFromFormatInfo::columns_read_under_other_names (#130793) makes ReadFromObjectStorageStep::supportsTopKDynamicFilter decline the top-K filter for a Delta Lake column that is read under another column's physical name. ReadFromFormatInfo::serialize and deserialize did not carry the set, so after a plan round trip the worker, which optimizes the deserialized plan again, matched the logical k against the physical k of k_old (the wrong result of #124545).

The set is now written after the PREWHERE info as a marker byte and the sorted names, only when it is not empty, so every other read keeps its exact bytes. An older reader refuses a stream with the set (CANNOT_PARSE_INPUT_ASSERTION_FAILED at the closing newline) instead of reading it without the exclusion. The only callers of these two functions are the ReadFromObjectStorageStep::serialize and deserialize declared under CLICKHOUSE_CLOUD, whose step version is registered outside this repository, so it is not bumped here.

No SQL test reaches this code, so the test is a gtest of the round trip: the set of the #130793 test's mapping and a set of 10 names (its size byte is '\n') survive it, and an empty set adds no bytes. Both tests fail on master and pass with the change; the bytes for an empty set are identical to master's.

#131029 is marked pr-must-backport, so this change should follow it to the same branches.


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

…Info`

`ReadFromFormatInfo::serialize` / `deserialize` did not carry the set that
ClickHouse#130793 added. After a plan round trip the deserialized info has the logical
`source_header`, the physical `format_header` and an empty set, so
`ReadFromObjectStorageStep::supportsTopKDynamicFilter` again accepts a
logical column against an unrelated physical column of the same name (with
the mapping `k_old` -> `k`, `k` -> `v`), and the worker, which optimizes the
deserialized plan again, arms the top-K filter on the wrong column.

The set is written after the PREWHERE info as a marker byte '\1' and the
sorted names, only when it is not empty:
- every read without renamed columns keeps its exact bytes (measured: the
  empty-set serialization is byte-identical to master's);
- an older reader refuses a stream with the set: it expects the closing
  "\n" and throws CANNOT_PARSE_INPUT_ASSERTION_FAILED on the marker, instead
  of reading the step without the exclusion;
- the marker differs from '\n' because the size of a set of 10 names is the
  VarUInt byte 0x0A;
- the names are sorted so the bytes are deterministic, also for the plan
  cache key.

The only callers of these functions are the `ReadFromObjectStorageStep`
serializers declared under CLICKHOUSE_CLOUD, whose step-version registration
is outside this repository, so the trailer is used instead of a step version.

Follow-up to ClickHouse#131029, review comment
ClickHouse#131029 (comment)

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; 1 full pass).

# Sev Finding Verdict Evidence / action
1 ❌ readVectorBinary with the default bound lets a small plan allocate many Strings (prepareReadingFromFormat.cpp:515) DISAGREE No plan reaches this reader in this repository (ReadFromObjectStorage is not in QueryPlanStepRegistry); client plans need the server setting process_query_plan_packet (default off) and arrive after authentication; the allocation is tracked, so a memory limit stops it with an exception; plan steps read their vectors the same way (BuildRuntimeFilterStep.cpp:499, MergeRuntimeFiltersStep.cpp:189). The suggested bound source_header.columns() does not hold after updateFormatPrewhereInfo.
2 ⚠️ The tests would pass with marker '\n' or without sorting DISAGREE With marker '\n' the empty-set case consumes the closing newline and throws at EOF, so it fails. Sorting only keeps the bytes of equal sets equal; without it the round trip is still correct.
3 ⚠️ The Cloud caller and its step version cannot be verified here DISAGREE The callers are declared under CLICKHOUSE_CLOUD and defined outside this repository, so the struct round trip is the boundary this repository can test. An older reader refusing the trailer was checked against a master build.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-8:20261113-010800

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: unit_tests_dbms --gtest_filter='ReadFromFormatInfoSerialization*' fails every run on master (the deserialized set is {}).
b Root cause explained? ReadFromFormatInfo::serialize / deserialize were not extended with columns_read_under_other_names (#130793), so a plan round trip drops the exclusion and the worker's re-optimization enables the top-K filter on the wrong physical column.
c Fix matches root cause? Yes: the struct's own serializer carries the set; the guard in supportsTopKDynamicFilter is unchanged.
d Test intent preserved / new tests added? New gtest gtest_read_from_format_info_serialization.cpp; no SQL path reaches the serializer outside the CLICKHOUSE_CLOUD step.
e Both directions demonstrated? Master: both tests fail (set {}; 666 vs 666 bytes). With the change: both pass, 50 of 50 repeats. Dropping the marker makes the 10-name case fail.
f Fix is general across code paths? One producer (DeltaLakeMetadataDeltaKernel::prepareReadingFromFormat), one consumer (supportsTopKDynamicFilter); the copies (updateFormatPrewhereInfo, clone, splitLazilyReadColumnsFromFormatInfo) keep the set; the serializer was the only place that dropped it.
g Fix generalizes across inputs (params/datatypes/wrappers)? Empty set (no bytes written), 2 names, 10 names (size byte equal to '\n'); names are sorted, so the bytes do not depend on set order.
h Backward compatible? (maintainer-approved exception only) Bytes for an empty set are identical to master's (cmp); an older reader refuses a stream with the set (CANNOT_PARSE_INPUT_ASSERTION_FAILED) rather than misreading it; the new reader reads old streams. No setting or protocol version change.
i Invariants and contracts preserved? The stream still ends with "\n" and the reader consumes exactly what was written (in.eof() asserted); checkChar consumes nothing when the marker is absent; deterministic bytes for the plan cache key.

Session id: cron:clickhouse-impl-slot-40:20261113-003800

@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4b1290b]

Summary: ✅


AI Review

Summary

Preserves ReadFromFormatInfo::columns_read_under_other_names across serialization so worker-side top-K optimization retains the Delta Lake column-mapping exclusion. The optional marker distinguishes the trailer from the existing terminator, sorted names keep serialization deterministic, and focused regression tests cover empty and nonempty sets, including ten names. No actionable findings in the current diff.

Missing context / blind spots
  • ⚠️ The Cloud-only ReadFromObjectStorageStep serialization implementations and step-version registration are outside this checkout. This review covers the shared serialization boundary and visible consumers; companion Cloud CI must validate the complete distributed-plan round trip and mixed-version behavior. No local build or test binary was available; execution evidence comes from the author's reported regression runs.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog can be tested Allows running workflows for external contributors comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4b1290b20 with master 5ea9bec93 (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.

Object file sizes

3 object files changed (+28.16 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/prepareReadingFromFormat.cpp.o 329.92 KiB 358.07 KiB +28.16 KiB (+8.53%)

711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.64 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.6 s 12.8 s +9.4 s (+274%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.3 s +5.3 s (+261%)
Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). and removed comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 19, 2026

This branch has not been deployed

No deployments
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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant