Repository navigation
Conversation
`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
|
Workflow [PR], commit [87f5bc5] Summary: ✅
AI ReviewSummaryAt head Missing context / blind spots
Final Verdict✅ Approve based on the current code and regression coverage. No additional code changes requested. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
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
…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]>
Closes: #125929
A filter on a column with a
DEFAULTexpression could silently drop rows when reading Parquet throughfile,urlor object storage. Withk Int64 DEFAULT -1over a Parquet column that holds NULLs,WHERE k = -1returned 0 rows whilecountIf(k = -1)returned 5.ReadFromFormatInfo::getFormatFilterpassed 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), butAddingDefaultsTransformreplaces those NULLs with theDEFAULTexpression (-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 onlyoptimize_move_to_prewheredoes not.getFormatFilternow also drops conjuncts that read a column with aDEFAULT(orMATERIALIZED/ALIAS) expression, or a subcolumn of one, the same way it already drops conjuncts on Hive partition and virtual columns. This is the reasoningReadFromFile::supportsTopKDynamicFilter(the comment above itshasDefaultcheck) 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_columnis the reproducer from the issue plusk < 0,k IN (-1, 3)andk > 4. On the current master build it returns0, 5, 0, ...; the expected values are what master returns with the Parquet pushdowns turned off.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a filter on a column with a
DEFAULTexpression 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]