Skip to content

Do not push filters on DEFAULT columns into the input format - #127108

Open
JayPokale wants to merge 7 commits into
ClickHouse:masterfrom
JayPokale:format-filter-default-columns
Open

JayPokale wants to merge 7 commits into
ClickHouse:masterfrom
JayPokale:format-filter-default-columns

Conversation

@JayPokale

@JayPokale JayPokale commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #125929

A filter on a column with a DEFAULT expression could silently drop rows when reading Parquet through file, url or object storage. With k Int64 DEFAULT -1 over a Parquet column that holds NULLs, WHERE k = -1 returned 0 rows while countIf(k = -1) returned 5.

ReadFromFormatInfo::getFormatFilter passed conjuncts on such columns to the format. The Parquet reader prunes row groups and pages by statistics and dictionary values, treating a NULL as the type default (0), but AddingDefaultsTransform replaces those NULLs with the DEFAULT expression (-1) after the format has read, so the pruned rows were the ones that match. On the current master build, turning off the Parquet filter, page, bloom and dictionary pushdowns gives the right result, while turning off only optimize_move_to_prewhere does not.

getFormatFilter now also drops conjuncts that read a column with a DEFAULT (or MATERIALIZED/ALIAS) expression, or a subcolumn of one, the same way it already drops conjuncts on Hive partition and virtual columns. This is the reasoning ReadFromFile::supportsTopKDynamicFilter (the comment above its hasDefault check) already applies to the top-K threshold. The query still filters these rows after the defaults are applied; only the format-level pruning on these columns is lost.

05443_parquet_filter_on_default_column is the reproducer from the issue plus k < 0, k IN (-1, 3) and k > 4. On the current master build it returns 0, 5, 0, ...; the expected values are what master returns with the Parquet pushdowns turned off.

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 a filter on a column with a DEFAULT expression dropping rows when reading formats with filter pushdown such as Parquet: rows whose missing or NULL value is replaced by the default were pruned by the format before the replacement.


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

`AddingDefaultsTransform` replaces the values a format reports as missing (e.g. a Parquet NULL read into a non-Nullable
column) with the column's `DEFAULT` expression after the format has read the data. The format compared its
placeholder (the type default) against the filter and pruned row groups, pages or dictionary values that match after
the replacement: `WHERE k = -1` on `k Int64 DEFAULT -1` returned 0 rows instead of 5. Keep such conjuncts out of
`getFormatFilter`, as the top-K threshold already does for these columns.

Closes: ClickHouse#125929
@clickhouse-gh clickhouse-gh Bot added comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization labels Oct 21, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [87f5bc5]

Summary: ✅


AI Review

Summary

At head 87f5bc58db113e8211dd257964e7ab8a98fef77b, this PR prevents format pruning from discarding rows whose values are subsequently replaced by a DEFAULT expression, including predicates on tuple subcolumns. The focused Parquet and ORC regressions cover the reported row loss. Both prior findings are addressed; no new actionable findings remain.

Missing context / blind spots
  • ⚠️ Runtime validation was not repeated locally because this checkout has no ClickHouse binary or build directory. The retrieved CI reports do not expose completed results for the new 05443 regressions; their execution remains for the standard stateless CI jobs.
Final Verdict

✅ Approve based on the current code and regression coverage. No additional code changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 87f5bc58d with master 28cd3f355 (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

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

Job report

The Parquet reader does not apply the tuple default to a NULL struct, so its baseline returns 0 with and without the filter.
…ormat, so the TopK query does not consult the cache
valerypetrov pushed a commit to valerypetrov/ClickHouse that referenced this pull request Nov 22, 2026
…ault

With `input_format_null_as_default` a NULL of a column declared
non-Nullable is read as the column default. ORC evaluates a search
argument leaf in 3-valued logic: the leaf is NULL for a NULL row, a NOT
keeps it NULL, and the row group is skipped. The query instead sees
`NOT atom(default)`, which is true when the default does not match the
atom. `buildORCSearchArgumentImpl` compared the atom for NULL and for the
default and pushed it unchanged when both were false, which is safe in a
positive context but not under a negation: `NOT (f > 0.5)` on
`f Float64` and `NOT startsWith(s, 'abc')` on `s String` returned 0 rows
instead of the NULL rows. `NOT` stays above such atoms because
KeyCondition does not invert Float comparisons (NaN) or functions
without an inverse; inside `indexHint` it stays above any atom.

Track whether an atom is under an odd number of NOTs. There, where the
atom was pushed unchanged, wrap it as `NOT isNull(col) AND atom` for a
top-level column, so a NULL row is false before the negation and every
row group that may hold NULLs is read, while NULL-free row groups still
prune by statistics. A struct element gets YES_NO_NULL instead: its
statistics do not count the rows where an ancestor is NULL, which the
reader also returns as the default. Master's guard for an atom whose
NULL and default answers differ is kept, so the new search argument
reads a superset of the row groups the old one read, and positive
contexts, Nullable and inferred schemas are unchanged.

The analysis comes from ClickHouse#133237. Its positive-context pruning part is
not included here: with a `DEFAULT` expression on a column it can turn
a correct result into a wrong one until ClickHouse#127108 is merged.

Related: ClickHouse#133237

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

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

WHERE on a DEFAULT column skips Parquet rows whose stored value is NULL

2 participants