Skip to content

Keep 05339_string_filters_during_scan_parquet_short_dictionary_values on the filtered dictionary read path - #126384

Closed
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05339-string-filter-earlier-prewhere-step
Closed

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05339-string-filter-earlier-prewhere-step

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #124131
Related: #124507

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Not required.

Description

05339_string_filters_during_scan_parquet_short_dictionary_values fails on every master run since the merge of #124131 (master report), with and without randomized settings, and on every PR whose merge commit includes it. Only the last line differs: StringValueFilterValuesReplaced is 0.

Since #124131, a single-column last PREWHERE step on a dictionary-encoded Parquet column evaluates its functions once per dictionary value and reads the rows as indexes. The dictionary values are read without the string filter, so the filter reports nothing. The test's PREWHERE s LIKE '%R%' has exactly that shape. #124131 adapted the sibling 05055_string_filters_during_scan_parquet.sh for the same reason, but this test came with #124507 after #124131's last CI run.

The change adds the same always-true conjunct AND id < 100000 to the test's three PREWHERE queries, so s is read by an earlier step, through the masked dictionary path the test checks. Without it the apply_string_filters_during_scan = 0/1 comparison also compared nothing. The reference is unchanged.

Validation on a debug build of d64fd503b42e: the old test fails 6 of 6 runs. The new one passes 50 of 50 randomized runs, with 66667 values replaced and 0 rows read as indexes in each. With Dictionary::appendIndexes reporting its mask lookups through updateStats instead of updateStatsWithoutPerValueChecks, the new test fails 8 of 8 (5712-6384 replaced), so it still catches the regression it was written for.

🤖 Generated with Claude Code


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

Since ClickHouse#124131, the only input of the last PREWHERE step on a dictionary-encoded
Parquet `String` column is read as dictionary indexes when no earlier step
reads it (`decode_dictionary_as_replicated`), and its dictionary values come
from `Reader::getDictionaryValues` with `use_string_value_filter = false`. So a
single-column `PREWHERE s LIKE '%R%'` no longer passes through
`StringValueFilter` and `StringValueFilterValuesReplaced` stays 0, which made
the last line of 05339 print 0 on every master run since d64fd50.

ClickHouse#124131 adapted 05055 for the same reason (32e261a), but 05339 was added
by ClickHouse#124507 after ClickHouse#124131's last CI run, so it was never adapted.

Add the same always-true conjunct `AND id < 100000` to the three PREWHERE
queries: the conjunct order is kept, so `s` is read by the first of two steps
and goes through the masked `Dictionary::appendIndexes` path the test checks.
It goes on the two `apply_string_filters_during_scan = 0/1` comparison queries
too, because with the single-column shape both arms read indexes and the
comparison compared nothing. The reference does not change.

Validated on a debug build of d64fd50: the old test fails 6/6, the new one
passes 50/50 randomized (66667 replaced, 0 rows read as indexes). Reporting the
mask lookups through `updateStats` instead of `updateStatsWithoutPerValueChecks`
makes the new test fail 8/8 (5712-6384 replaced).

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; 1 finding; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ > 50000 would also pass if mask accounting skipped ~2 of 10 row groups; assert = 66667. DISAGREE No path skips only some row groups: every chunk builds its mask and a disabled filter stays disabled. The guarded disable fires in row group 1 (mutation: 5712-6384 replaced). Existing oracle kept.

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

Session id: cron:clickhouse-review-slot-8:20261016-231100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. Debug build of d64fd503b42e: the unmodified test fails 1/1 unrandomized and 5/5 randomized, with the CI diff (last line 0, not 1).
b Root cause explained? Since #124131 the only input of the last PREWHERE step is decoded as dictionary indexes, with values from getDictionaryValues(use_string_value_filter = false), so Dictionary::appendIndexes skips the mask branch and StringValueFilterValuesReplaced stays 0. PREWHERE s LIKE '%R%' alone is that shape.
c Fix matches root cause? Yes. The product behaviour is intended; the always-true AND id < 100000 moves s to an earlier PREWHERE step, back to the masked path. No tags, bounds or data changes.
d Test intent preserved / new tests added? Preserved: it still checks that dictionary mask lookups do not trip the short-value cutoff, and its apply_string_filters_during_scan = 0/1 comparison covers the filtered path again. Test-only.
e Both directions demonstrated? Old test FAIL 6/6; new test PASS 10/10 + 50/50 randomized. Mutation updateStatsWithoutPerValueChecks -> updateStats in Dictionary::appendIndexes: new test FAIL 8/8, PASS after revert.
f Fix is general across code paths? All StringValueFilter* tests checked: 05055 already adapted by #124131, 05347 dictionary too large for the index path, 05334 no dictionary, the rest MergeTree; 05055, 05347, 05331 pass.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). The 50 randomized runs covered both enable_multiple_prewhere_read_steps values, use_columns_cache on/off and many max_block_size values; all took the masked path.
h Backward compatible? (maintainer-approved exception only) Yes. Test-only: no setting, default or format change.
i Invariants and contracts preserved? Yes. The conjunct is true for every row, so the reference is byte-identical; the test stays parallel-safe.

Session id: cron:clickhouse-impl-slot-4:20261016-225500

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7959cad]


AI Review

Summary

Adds the always-true AND id < 100000 predicate to three queries in 05339_string_filters_during_scan_parquet_short_dictionary_values, restoring the dictionary mask path after the last-step dictionary optimization. No actionable findings: the result checks and regression-sensitive profile-event assertion remain intact.

Missing context / blind spots
  • ⚠️ Current-head stateless checks are pending, and I did not rerun the test locally. Validation relies on the author's reported 50 randomized passes and eight mutation failures; a completed stateless run would independently confirm the fix.
Final Verdict

✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @alexey-milovidov, could you review this and add can be tested (I cannot add labels at the moment)? Since #124131, a single-column PREWHERE on a dictionary-encoded Parquet column evaluates once per dictionary value without the string filter, so 05339 (from #124507) reads 0 replaced values on every master run; this adds the same always-true AND id < 100000 conjunct #124131 used for 05055. Your #124531 edits the same line, so one of the two will need a trivial rebase.

@alexey-milovidov

Copy link
Copy Markdown
Member

Thank you! The fix is included in #126397, which re-applies #124131 after its revert.

@clickhouse-gh clickhouse-gh Bot added comp-parquet-reader-v3 Issues related to the native Parquet reader. and removed comp-testing Test content only (no production code). labels Nov 22, 2026
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-parquet-reader-v3 Issues related to the native Parquet reader. pr-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants