Skip to content

Fix File row policy / PREWHERE breaking DEFAULT columns missing from the data file - #114667

Open
Ria-K912 wants to merge 15 commits into
ClickHouse:masterfrom
Ria-K912:fix-file-row-policy-defaults
Open

Ria-K912 wants to merge 15 commits into
ClickHouse:masterfrom
Ria-K912:fix-file-row-policy-defaults

Conversation

@Ria-K912

@Ria-K912 Ria-K912 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #114616

When a file-backed table (File, and the same path for object storage) has a DEFAULT column that is not present in the data file, a row policy or PREWHERE could prune the inputs of that default expression before AddingDefaultsTransform ran. That led to UNKNOWN_IDENTIFIER on current master, and on 26.7 to silently wrong row-policy results (type defaults instead of real values).

This keeps columns required by DEFAULT expressions in the read set through prewhere pruning, and applies filters that reference defaulted columns after defaults are computed.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix queries over file-backed tables where a row policy or PREWHERE interacted with DEFAULT columns missing from the data file: they no longer fail with UNKNOWN_IDENTIFIER, and row policies are evaluated on real default values instead of type defaults.


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

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e3ee4d7]

Summary: ✅


AI Review

Summary

This PR fixes file-backed reads where row policies or PREWHERE used DEFAULT columns missing from the data file, by retaining DEFAULT dependencies and replaying affected filters after AddingDefaultsTransform. The remaining issue is a new object-storage performance regression: when that fallback path triggers, it drops top_k_filter, so Parquet ORDER BY ... LIMIT reads lose TopN pruning.

Findings

⚠️ Majors

  • [src/Storages/ObjectStorage/StorageObjectStorageSource.cpp:1381] The new deferred-filter path forces object-storage reads through reconstructed FormatFilterInfo objects that never copy top_k_filter. For Parquet-backed S3 / Iceberg tables, ORDER BY ... LIMIT queries that still sort on an on-disk column but defer a row policy / PREWHERE on a missing DEFAULT column will now stop doing TopN dynamic filtering / row-group pruning. The File / URL paths had to preserve top_k_filter for the same reason.
    Suggested fix: copy top_k_filter into each reconstructed FormatFilterInfo in this fallback path, the same way StorageFile / StorageURL now do.
Final Verdict

Changes are not ready to merge yet: the object-storage fallback still regresses TopN pruning when the new deferred-default filter path is taken.

LLVM Coverage Report

Measured on commit e3ee4d7.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 248/383 (64.75%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 21, 2026
@Ria-K912
Ria-K912 force-pushed the fix-file-row-policy-defaults branch from c5b3862 to 64943da Compare August 22, 2026 04:39
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e3ee4d786 with master 74512d564 (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

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

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/prepareReadingFromFormat.cpp.o 291.51 KiB 368.35 KiB +76.84 KiB (+26.36%)
src/CMakeFiles/dbms.dir/Storages/StorageURL.cpp.o 1.20 MiB 1.24 MiB +32.18 KiB (+2.61%)
src/CMakeFiles/dbms.dir/Storages/StorageFile.cpp.o 1.11 MiB 1.13 MiB +21.84 KiB (+1.93%)

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

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Sep 4, 2026
Comment thread src/Storages/StorageFile.cpp Resolved
&& filter_requires_missing_defaulted_column(format_filter_info->row_level_filter->actions.getRequiredColumns()))
|| (format_filter_info->prewhere_info
&& filter_requires_missing_defaulted_column(format_filter_info->prewhere_info->prewhere_actions.getRequiredColumns())))
format_supports_prewhere = false;

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.

This new format_supports_prewhere = false path now routes object-storage reads through the cloned FormatFilterInfo objects below, but unlike StorageFile / StorageURL those clones never copy top_k_filter. A Parquet-backed S3 / Iceberg read with ORDER BY ... LIMIT and a deferred row policy / PREWHERE on a missing DEFAULT column will therefore stop doing TopN dynamic filtering / row-group pruning even though the sort key is still read from the file. Please carry top_k_filter across the reconstructed FormatFilterInfos here as well.

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-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). external Author is not a member of the ClickHouse organization pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Row policy over a file-backed table breaks DEFAULT columns missing from the data file (UNKNOWN_IDENTIFIER; silently wrong results on 26.7)

3 participants