Skip to content

Use less schema comparison - #122574

Merged
scanhex12 merged 7 commits into
masterfrom
dont_use_schema_comparison
Sep 29, 2026
Merged

scanhex12 merged 7 commits into
masterfrom
dont_use_schema_comparison

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 27, 2026 •

Copy link
Copy Markdown
Member
telegram-cloud-photo-size-2-5316802164355180257-y

We spend a lot of time on schema comparison. Let's use it less

Changelog category (leave one):

  • Performance Improvement

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

Faster planning of queries to Iceberg tables with many manifest files: when a manifest file header has the schema-id key and that schema is already known from metadata.json, the schema copy stored in the manifest header is no longer parsed and compared with it. ClickHouse now also writes the schema-id key into the headers of manifest files it creates.


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

Version info

  • Merged into: 26.10.1.1028-master (included in 26.10 and later)
  • Backported to: 26.9.9.21, 26.8.16.29, 26.7.20.18, 26.3.40.8

@clickhouse-gh

clickhouse-gh Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1d81fd2]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, targeted) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb
Integration tests (arm_binary, distributed plan, targeted) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb
Integration tests (amd_tsan, targeted) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb
Integration tests (amd_msan, targeted) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb
Integration tests (amd_llvm_coverage, 1/8) FAIL
test_storage_iceberg_no_spark/test_iceberg_inverted_manifest_bounds.py::test_iceberg_narrow_manifest_bounds FAIL cidb

AI Review

Summary

This PR speeds up Iceberg manifest planning by reusing the manifest header schema-id when that id is already known from metadata.json, and it starts writing schema-id plus the correctly named partition-spec-id metadata into ClickHouse-written manifests. The write-side change is fine, but the read-side fast path still accepts an internally inconsistent manifest header without validating that the embedded schema copy names the same schema-id, so I would not merge it as-is.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp:328] The fast path trusts the standalone schema-id header as soon as that id is already registered from metadata.json, but it skips even a cheap consistency check against the schema blob that is still present and required a few lines above. A manifest whose header says schema-id = 5 while the embedded schema says schema-id = 7 now binds the manifest to schema 5, which feeds buildPartitionKeyFromSpec and later becomes the fallback resolved_schema_id when snapshot metadata has expired. That can misdecode bounds or prune files against the wrong schema instead of rejecting a malformed manifest.
    Suggested fix: parse just enough of schema to verify its own schema-id before taking the fast path, or fall back to the old parse-and-validate path whenever that consistency check is unavailable.

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp:328] [dismissed by author -- https://github.com/ClickHouse/ClickHouse/pull/122574#discussion_r4134494019] The PR is tagged Performance Improvement, but there is still no focused evidence that this branch is hit on the target workload or that it materially helps there. The only performance data in the discussion is an after-only flame graph and a cloud benchmark report that showed no measurable change, so the user-facing speedup claim is still unpinned.
    Suggested fix: add either a narrow manifest-heavy planner benchmark or a focused regression test that exercises the metadata.json-registered plus standalone schema-id path and report before/after timings.
Tests
  • ⚠️ No focused coverage was added for the new ManifestFileIterator::create fast path or for the new manifest-header keys written by generateManifestFile. The existing SchemaProcessor gtests do not execute the fast path, and the integration tests that already inspect Avro user metadata do not assert the new schema-id / partition-spec-id headers.
Final Verdict

Changes required.

LLVM Coverage Report

Measured on commit 1d81fd2.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 50/62 (80.65%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 27, 2026
@scanhex12

Copy link
Copy Markdown
Member Author
Screenshot 2026-09-27 at 23 16 43

flame graph after

@scanhex12 scanhex12 changed the title Don't use schema comparison Use less schema comparison Sep 27, 2026
{
auto schema_id_string = manifest_file_deserializer_->tryGetAvroMetadataValue(f_schema_id);
Int32 schema_id = 0;
if (schema_id_string.has_value() && tryParse(schema_id, *schema_id_string) && schema_processor.isSchemaRegisteredFromMetadata(schema_id))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trusting the standalone Avro schema-id header here without cross-checking the embedded schema blob changes which schema becomes authoritative for the manifest. Before this change manifest_schema_id always came from schema_object->getValue<int>(f_schema_id). After it, a manifest whose header says schema-id = 5 but whose embedded schema object is schema-id = 7 will silently bind the manifest to schema 5 as soon as 5 is already registered from metadata.json.

That is not just a diagnostics change: buildPartitionKeyFromSpec below uses manifest_schema_id, and processRow falls back to manifest_schema_id when snapshot metadata has already been expired. So a mismatched/corrupted manifest can now change pruning and bounds decoding instead of being revalidated on the old parse path.

Please either parse just enough of schema to verify its own schema-id before taking this fast path, or fall back to the old parse-and-validate path whenever that consistency check is unavailable.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 38 queries analysed

no significant changes detected. K_source=6 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: b78b16e2-0799-4db2-b927-aa56621b3e02
  • MIRAI run: b846378b-ee46-4c52-ac21-77c31488ae40
  • PR check IDs:
    • clickbench_2420415_1790701010
    • clickbench_2420428_1790701010
    • clickbench_2420434_1790701010
    • tpch_adapted_1_official_2420440_1790701010
    • tpch_adapted_1_official_2420450_1790701010
    • tpch_adapted_1_official_2420485_1790701010

@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 28, 2026
…pec name

`generateManifestFile` stored the partition spec id in the manifest file
metadata under `f_partition_spec_id`, which is `partition_spec_id`, the name of
the manifest list field. The Iceberg spec and the Java implementation read the
manifest header key `partition-spec-id`, so the value was never found. Add a
separate `f_manifest_partition_spec_id` constant for the header key.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Avogar Avogar self-assigned this Sep 28, 2026

@Avogar Avogar left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments:

  1. Let's write a better changelog entry with more details about the change and what it improves. Right now it's very short and confusing for users; it's not even clear that it's related to Iceberg.
  2. The docs of the setting iceberg_tolerate_conflicting_manifest_schemas promise a warning when a manifest header schema conflicts with the one from metadata.json. After this change we never compare them, so the warning is never printed: when the header has the schema-id key we don't parse schema at all, and when it doesn't, the new early return in addIcebergTableSchema exits before the comparison. Let's just remove this warning and its mention in the setting docs and in the SettingsChangesHistory.cpp entry.
  3. Now, depending on the setting iceberg_tolerate_conflicting_manifest_schemas, we take the manifest schema id either from the schema-id key or from the schema-id field inside schema. If they differ, flipping the setting changes the partition key and the schema used to read data files, while the setting is documented only as choosing whether a conflict is tolerated or throws. Let's always use the schema-id key as the source of truth when it's present, and fall back to the id inside schema only when it's missing (e.g. manifests written by older ClickHouse versions). Where we parse schema anyway, we can also check that both ids match.

scanhex12 and others added 2 commits September 29, 2026 13:36
…ct warning

Take the manifest schema id from the `schema-id` header key whenever it is
present, independently of `iceberg_tolerate_conflicting_manifest_schemas`, and
fall back to the id inside `schema` only for manifests without that key. When
`schema` is parsed anyway, check that both ids match.

Remove the warning about a manifest header schema conflicting with
metadata.json: with toleration enabled the header copy is not compared anymore,
so the warning was never printed. Update the setting docs and the
`SettingsChangesHistory.cpp` entry accordingly.

Addresses review: #122574

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…mparison

# Conflicts:
#	src/Core/SettingsChangesHistory.cpp
The schema written into a manifest always comes from Iceberg metadata, which
requires `schema-id`, so there is no reason to skip the key silently.

Addresses review: #122574

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 1d81fd264 with master 2d4ec667f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 5f5478bde; 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

8 object files changed (+21.79 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp.o 467.59 KiB 489.76 KiB +22.17 KiB (+4.74%)

716 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.

Compile time of recompiled translation units

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

Job report

@Avogar Avogar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix the failed integration tests and it's good to go

@scanhex12

Copy link
Copy Markdown
Member Author

@Avogar the failed integration tests are broken in master

@Avogar

Avogar commented Sep 29, 2026

Copy link
Copy Markdown
Member

Ah, I see, ok. Seems it's fixed in #122895.

@scanhex12
scanhex12 enabled auto-merge September 29, 2026 19:58
@scanhex12
scanhex12 disabled auto-merge September 29, 2026 19:59
@scanhex12
scanhex12 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into master with commit b4c7286 Sep 29, 2026
143 of 149 checks passed
@scanhex12
scanhex12 deleted the dont_use_schema_comparison branch September 29, 2026 20:22
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 29, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 29, 2026
robot-ch-test-poll added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122574 to 26.3: Use less schema comparison
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122574 to 26.7: Use less schema comparison
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122574 to 26.8: Use less schema comparison
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Cherry pick #122574 to 26.9: Use less schema comparison
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122574 to 26.7: Use less schema comparison
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122574 to 26.9: Use less schema comparison
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #122574 to 26.8: Use less schema comparison
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #122574 to 26.3: Use less schema comparison
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants