Skip to content

Use InlinedVector for rpn_stack in sparse checkInHyperrectangle - #110153

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
raimannma:keycondition-sparse-inlined-rpn-stack
Jul 14, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
raimannma:keycondition-sparse-inlined-rpn-stack

Conversation

@raimannma

@raimannma raimannma commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

The sparse overload of KeyCondition::checkInHyperrectangle (the default path with use_lightweight_primary_key_index_analysis) heap-allocated its rpn_stack on every invocation, while the non-sparse overload already uses absl::InlinedVector<BoolMask, 16>. The function runs once per hyperrectangle check during mark filtering, so the vector construction is hot: in the release binary, the first emplace_back always took the allocating grow path.

Benchmarks (100 parts × 1M rows, index_granularity = 256, interleaved A/B runs) show 5-26% less time in FilteringMarksWithPrimaryKey across 13 query shapes (IN with 50/500/5000 values, point lookups, ranges, OR chains, NOT IN, multi-column keys, >16-deep nested conditions), ~6% for a typical large IN. Patched binary won 71 of 75 interleaved run pairs (sign test p = 6.8e-17); no shape regressed, including the >16-depth case that spills to the heap.

Changelog category (leave one):

  • Performance Improvement

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

Avoid a heap allocation per hyperrectangle check in primary key index analysis, speeding up mark filtering by 5-26% depending on the query shape.

Version info

  • Merged into: 26.7.1.949 (included in 26.7 and later)

The sparse overload of KeyCondition::checkInHyperrectangle (the default
path with use_lightweight_primary_key_index_analysis) heap-allocated its
rpn_stack on every invocation, while the non-sparse overload already
uses absl::InlinedVector<BoolMask, 16>. This function runs once per
hyperrectangle check during mark filtering, so the allocation is hot.

5-26% less time in FilteringMarksWithPrimaryKey across IN/point/range/
OR/NOT IN/multi-column-key query shapes, ~6% for a typical large IN.
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jul 12, 2026
@alexey-milovidov alexey-milovidov self-assigned this Jul 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [19ae721]

Summary: ✅


AI Review

Summary

This PR replaces the sparse KeyCondition::checkInHyperrectangle stack from std::vector to absl::InlinedVector<BoolMask, 16>, matching the non-sparse overload and removing the unconditional heap allocation from the default lightweight primary-key analysis path. I reviewed the current diff, surrounding KeyCondition logic, prior discussion, and available CI signals, and I did not find a correctness, safety, compatibility, or evidence gap that warrants a review comment.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jul 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

This PR swaps a std::vector for an absl::InlinedVector in the primary-key index RPN stack (KeyCondition::checkInHyperrectangle), avoiding heap allocation during hyperrectangle checks. That only helps queries with selective primary-key filters; the two flagged ClickBench improvements (Q4 and Q15) are full-scan aggregations that never exercise that path, and both show essentially flat CPU (~2.6s) with wall-time-only deltas of -21.4% and -21.7%. Those readings are consistent with run-to-run variance rather than a real effect of this change, so Q4 stays no_change and Q15 is downgraded to not_sure. No cross-query pattern worth flagging.

clickbench

⚠️ 1 inconclusive

Flagged queries (1 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 15 not_sure 244 191 -21.7% <0.0001 aggregation: The -21.7% is wall-time only (CPU flat at ~2.6s); this full-scan GROUP BY doesn't exercise the primary-key index analysis the PR optimizes, so it reads as run-to-run variance.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: c3590eae-48dc-4adf-8030-8f17921bf589
  • MIRAI run: ec1515a1-e02d-4548-91b1-44adf65ac732
  • PR check IDs:
    • clickbench_534654_1784040024
    • clickbench_534668_1784040024
    • clickbench_534674_1784040024
    • tpch_adapted_1_official_534680_1784040024
    • tpch_adapted_1_official_534685_1784040024
    • tpch_adapted_1_official_534694_1784040024

@raimannma

Copy link
Copy Markdown
Contributor Author

@alexey-milovidov I don't think those test failures are caused by this change.

@clickhouse-gh

clickhouse-gh Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.80% 85.80% +0.00%
Functions 92.70% 92.70% +0.00%
Branches 78.00% 78.00% +0.00%

Changed lines: Changed C/C++ lines covered: 2/2 (100.00%) · Uncovered code

Full report · Diff report

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

3 participants