Skip to content

Use statistics of a plain Parquet INT64 column read as DateTime - #124863

Merged
PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:parquet-int64-datetime-statistics
Oct 20, 2026
Merged

PedroTadim merged 6 commits into
ClickHouse:masterfrom
groeneai:parquet-int64-datetime-statistics

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #123564
Related: #117017
Related: #121033

Changelog category (leave one):

  • Performance Improvement

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

A Parquet INT64 column without a logical type that is read as DateTime (like EventTime in ClickBench's hits.parquet) now uses its min/max statistics, so WHERE conditions and ORDER BY ... LIMIT skip row groups.

Description

The remaining part of #123564. This is the same one-line change as #117017 by @ wudidapaopao (credited as co-author). Its bound rules are already on master via #121033, and #117017 itself conflicts with master.

Why it was off. The plain INT64 branch of SchemaConverter::processPrimitiveColumn passed allow_datetime_and_ipv4 = false, so a column read as DateTime got no statistics at all. That was needed while a 64-bit bound outside [0, 4294967295] could reach pruning, because the read saturates such values. Since #121033, IntConverter::convertField leaves that side unbounded for a negative or > UINT32_MAX bound, and IPv4 over a 64-bit integer is refused by the order check. The plain INT32 and annotated INTEGER(64) branches already pass true; this flips the last one. Query results do not change.

Measured (debug build, the perf test's 200-row-group file): WHERE t BETWEEN ... reads 1 row group instead of 200; ORDER BY t [DESC] LIMIT 10 skips 189/187 row groups instead of 0. @ snelheidai measured ClickBench q25/q27 at 0.35x time and q24 at 0.64x (their numbers).

Validation. New test 05372_parquet_int64_datetime_statistics: pruning and top-K skip counts (fail on the old binary); row groups and pages entirely or partly outside the DateTime range, and NULLs read as Nullable(DateTime) or LowCardinality(DateTime) (including top-K with NULLS FIRST), each against the same query with push-down off; and the IPv4 refusal. Removing the > UINT32_MAX rule or the IPv4 refusal fails the test. #117017's own test also passes. Perf test parquet_int64_datetime_statistics.xml.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.11.1.289-master (included in 26.11 and later)

The plain INT64 branch of SchemaConverter::processPrimitiveColumn turned the
statistics off for a DateTime target, so a Parquet INT64 column without a
logical type (EventTime in ClickBench's hits.parquet) got no row group or page
pruning and no top-K row group skipping. The plain INT32 and annotated
INTEGER(64) branches already allow it: a bound outside the DateTime range is
not used, and IPv4 over a 64-bit integer is still refused.

This is the remaining part of ClickHouse#117017; ClickHouse#121033 already added those rules.

Co-authored-by: wudidapaopao <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

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) plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 ⚠️ ParquetTopKSkippedRowGroups > 0 in 05372 cannot tell 1 skipped row group from 4 DISAGREE The change is one flag, so its top-K effect is 0 vs more than 0 skips, which the line separates (it fails with the line reverted). The file is ascending and the query is DESC, so a file-order admission regression also gives 0. The exact count depends on admission depth, already pinned by 05317_parquet_top_k_row_group_order (BETWEEN 17 AND 20); the quantity itself is measured by the new perf test (189/187 of 200 row groups skipped vs 0).
2 💡 The comment on the IPv4 line could say that the oracle is the cast error not being pruned away AGREE, not changed Wording only; the line fails when the IPv4 refusal is removed.

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

Session id: cron:clickhouse-review-slot-48:20261009-083600

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05372_parquet_int64_datetime_statistics fails on the binary without the change (pruned counts 0 instead of 1/1/4, top-K skip 0), with fixed settings and 20/20 randomized.
b Root cause explained? The plain INT64 branch of SchemaConverter::processPrimitiveColumn passed allow_datetime_and_ipv4 = false, so a column read as DateTime got allow_stats = false.
c Fix matches root cause? Yes. The flag is flipped at that call site; the bound rules it needs are in IntConverter::convertField since #121033 and already serve the INT32 and INTEGER(64) branches.
d Test intent preserved / new tests added? New stateless test plus perf test parquet_int64_datetime_statistics.xml. Deleting the > UINT32_MAX bound rule or the IPv4 refusal makes the test fail.
e Both directions demonstrated? Yes. With the change: 50/50 randomized and 20/20 with fixed settings. Without it: 20/20 randomized failures.
f Fix is general across code paths? Yes. All integer branches now agree; BOOLEAN and DATE keep false on purpose. Row group, page index and top-K use the same bounds; hash filters are unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. Checked Nullable, LowCardinality, LowCardinality(Nullable), non-UTC time zones, NULLs, and bounds that are negative, 0, 2^32-1 or above 2^32. Every count equals the same query with all push-down off.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or default changes; query results are identical.
i Invariants and contracts preserved? Yes. A used bound still bounds the values after the saturating cast, because each out-of-range side is dropped. The reader's min > max check still fails closed.

Session id: cron:clickhouse-impl-slot-41:20261009-075700

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2134a1c]

Summary: ❌

job_name test_name status info comment
Stress test (amd_tsan) FAIL
AST Fuzzer oracle mismatch: TLP WHERE FAIL cidb IGNORED

AI Review

Summary

Enables min/max statistics for unannotated Parquet INT64 columns read as DateTime, allowing predicate pruning and top-K row-group skipping. No actionable findings after reviewing the current diff, surrounding conversion and statistics consumers, tests, and prior discussion.

Missing context / blind spots
Final Verdict

✅ Approve — no changes requested.

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2134a1c8a with master 74d99c64e (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 2134b447b; 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, 15 s compile time in total, 7 of them have a recent master baseline.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 31 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: 430a1ce1-030b-413a-8629-91911287395c
  • MIRAI run: 6dded241-ef32-4fe7-a2ec-fb41f8691e1f
  • PR check IDs:
    • clickbench_524470_1791542953
    • clickbench_524483_1791542953
    • clickbench_524489_1791542953
    • tpch_adapted_1_official_524499_1791542953
    • tpch_adapted_1_official_524508_1791542953
    • tpch_adapted_1_official_524541_1791542953

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 158781b

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05055_string_filters_during_scan_merge_tree flaky, not from this PR (which changes the plain INT64 statistics flag in SchemaConverter.cpp): the query_log ProfileEvents check reads 0 0 0 instead of 1 1 1; under parallel replicas the scan events land only in the remote replica's row, which the current_database = currentDatabase() filter drops. 49/49 reruns pass #124911 (mine, open)
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines test regression from merged #123364, not from this PR: under DatabaseReplicated the final query_log count returns 0 2 instead of 0 1 (the password stays hidden; the CREATE DICTIONARY row is counted twice). 22/22 reruns pass; the same diff is on 20+ PRs in this lane today a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR praktika rollups of the two rows above, no independent failure #124911 (mine, open) and a fix task is created (the two rows above)

Session id: cron:our-pr-ci-monitor:20261009-133010

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 05316_secret_arguments_declared_by_engines (DatabaseReplicated 0 1 -> 0 2) from the CI finish ledger above: #124928 (external, open).

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai 🕵️
The change itself looks correct to me: convertField leaves a negative bound or one above UINT32_MAX open, which matches the read, since the internal cast from castColumn saturates both ways. I think the test misses three paths that this flip also turns on:

  1. Nullable(DateTime) and LowCardinality(DateTime). The type hint is stripped of LowCardinality and Nullable before dispatch_int_stats_converter runs, so these get statistics too. The test only writes a required ts Int64. Could you add an optional Int64 column with some NULLs, read as Nullable(DateTime), and check against input_format_parquet_filter_push_down = 0:

    • WHERE ts IS NULL and WHERE ts IS NOT NULL;
    • ORDER BY ts DESC NULLS FIRST LIMIT 3 with use_top_k_dynamic_filtering = 1: a row group that holds NULLs must not be skipped because its max is below the threshold.
  2. Page-level statistics. The column index of each page goes through the same convertField, and input_format_parquet_page_filter_push_down is on by default, so page pruning is now active for this type as well. The test only checks ParquetPrunedRowGroups. A file with one row group and several small pages (output_format_parquet_data_page_size) whose ranges cross 0 and UINT32_MAX, compared against the same queries with input_format_parquet_page_filter_push_down = 0, would cover it.

  3. The IPv4 check. WHERE ts = toIPv4('1.2.3.4') expects NOT_IMPLEMENTED, so the read itself fails, and that case can't show whether the statistics were refused. The description says that removing the IPv4 refusal fails the test: which line fails then? If it's this one, a comment saying where the NOT_IMPLEMENTED comes from would help. If the read can't reach the statistics at all, the line doesn't test the refusal.

Read an optional Int64 column with NULLs as Nullable(DateTime) and as
LowCardinality(DateTime), including a top-K read with NULLS FIRST where a row
group with NULLs has a maximum below the threshold, and add a file with one row
group whose pages cross 0 and UINT32_MAX. The push-down-off lines of the range
file now also turn off the page index, which uses the same bounds. Say where the
NOT_IMPLEMENTED of the IPv4 read comes from.

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

Copy link
Copy Markdown
Collaborator Author

Thanks, added in 0f42039. All three paths already behave correctly; the new lines pin them.

  1. A file with an optional Int64 in 6 row groups: one all NULL, one with 2 NULLs among the smallest values, the rest without NULLs. Read as Nullable(DateTime), IS NULL and IS NOT NULL match push-down off and prune 4 and 1 row groups. LowCardinality(DateTime) reads a NULL as the default, so ts = toDateTime(0) returns the same 102 rows. For ORDER BY ts DESC NULLS FIRST, v LIMIT 3 with top-K, the row group with 2 NULLs gets no top-K range at all (getTopKSortColumnRange refuses a chunk that may contain NULLs), so it is read. With that check removed, it is skipped and the result loses both of its NULLs.

  2. One row group with 6 pages whose ranges cross 0 and UINT32_MAX, compared with input_format_parquet_page_filter_push_down = 0: 3 pages pruned on each side. Removing the > UINT32_MAX rule fails the page line on its own (1 row instead of 3). You were right that the existing push-down-off lines of the range file still used the page index, so they now turn it off too.

  3. Yes, it is that line. The NOT_IMPLEMENTED is Conversion from Int64 to IPv4 is not supported, thrown by the cast at the read stage, so it fires only if a row group is read. 1.2.3.4 is below every row group's minimum, so with the refusal removed all 5 row groups are pruned and the query returns 0. I added a comment saying this.

With the flip reverted, every new prune count is 0. The test passes 100/100 with random settings.

…ime-statistics

Master factored the plain `INT64` decoder setup into the `set_plain_int64_decoder` lambda, also used for Iceberg `time` read as stored microseconds. The lambda now takes `allow_datetime_and_ipv4`: `true` for the plain `INT64` case (this PR's change), `false` for the Iceberg `time` path (master's behavior).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim
PedroTadim enabled auto-merge October 17, 2026 19:30
@PedroTadim
PedroTadim added this pull request to the merge queue Oct 20, 2026
Merged via the queue into ClickHouse:master with commit 0b46818 Oct 20, 2026
176 of 178 checks passed
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. groeneai-origin-issue PR origin: picked up an external GitHub issue 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.

4 participants