Skip to content

Use ARRAY JOIN element conditions for index analysis - #118582

Merged
yariks5s merged 6 commits into
masterfrom
yarik/index-analysis-through-array-join
Sep 9, 2026
Merged

yariks5s merged 6 commits into
masterfrom
yarik/index-analysis-through-array-join

Conversation

@yariks5s

@yariks5s yariks5s commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Related: #117882
Related: #112241

Changelog category (leave one):

  • Performance Improvement

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

A condition on an ARRAY JOIN element, such as ARRAY JOIN tags AS t WHERE t IN (...), is now used for skip index analysis the same way arrayJoin(tags) IN (...) already is


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

@yariks5s
yariks5s requested a review from nihalzp September 7, 2026 14:18
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e72c85]

Summary: ✅


AI Review

Summary

This PR extends optimizePrimaryKeyConditionAndLimit so ARRAY JOIN element predicates are translated into the same arrayJoin(col) atoms the skip-index analyzer already understands, avoids unsafe LIMIT pushdown across real ArrayJoinSteps, and adds focused stateless coverage for the local MergeTree cases. After checking the current diff, the affected consumers, and the existing review threads against the current code, I did not find a remaining correctness, safety, or evidence gap in the current version.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 5e72c85.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 44/45 (97.78%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 7, 2026
@nihalzp nihalzp self-assigned this Sep 7, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... label Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 40 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: e34530bd-7519-4dfc-9f13-84f62fb6e873
  • MIRAI run: 196bf994-ab72-4af1-bf47-2a165764149d
  • PR check IDs:
    • clickbench_70518_1788899855
    • clickbench_70524_1788899855
    • clickbench_70530_1788899855
    • tpch_adapted_1_official_70541_1788899855
    • tpch_adapted_1_official_70552_1788899855
    • tpch_adapted_1_official_70588_1788899855

@nihalzp nihalzp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@yariks5s
yariks5s enabled auto-merge September 8, 2026 20:38
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5e72c858f with master 85439c0e4 (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

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

Job report

@yariks5s
yariks5s added this pull request to the merge queue Sep 9, 2026
Merged via the queue into master with commit 10678db Sep 9, 2026
342 of 345 checks passed
@yariks5s
yariks5s deleted the yarik/index-analysis-through-array-join branch September 9, 2026 13:44
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 9, 2026
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Nov 7, 2026
…ColumnsPass

The pass set the type of every reference to an ARRAY JOIN column (the first
argument of `tupleElement`) to the type of the ARRAY JOIN expression, for every
expression, pruned or not. The analyzer can give a reference a different type
than the definition: `join_use_nulls` (ARRAY JOIN on the nullified side of a
RIGHT/FULL JOIN) and `group_by_use_nulls` (the column is a ROLLUP/CUBE key)
make it `Nullable`, and a `USING` key gives it the common supertype. After the
overwrite `tupleElement` was re-resolved to the narrower type while its parent
function still expected the old one, so the query tree validator of debug and
sanitizer builds threw `LOGICAL_ERROR` "Function tupleElement(__array_join_exp_1,
'a') > 0 expects argument 1 to have Nullable(Int64) type but receives Int64 after
running PruneArrayJoinColumns pass". Release builds were not affected: the
planner rebuilds a function whose argument types do not match.

Now `pruned_type` is set only when `pruneNestedFunctionArguments` actually
pruned the expression, so references of other expressions keep their type, and
a reference of a pruned expression keeps its own `Nullable`. A `USING` key or a
matcher column is a direct reference, which marks the expression fully used,
so it is never pruned.

Found by the server-side AST fuzzer in Stress tests (PR ClickHouse#126991, ClickHouse#118582,
ClickHouse#115763).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-query-optimizer Query plan optimization: physical plan steps, plan-level rewrites and optimizations (QueryPlan pa... 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