Skip to content

Replace a dropped always-true filter with an expression - #124056

Merged
yariks5s merged 12 commits into
masterfrom
yarik/replace-always-true-filter
Oct 15, 2026
Merged

yariks5s merged 12 commits into
masterfrom
yarik/replace-always-true-filter

Conversation

@yariks5s

@yariks5s yariks5s commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #105987

The (almost) fix for regression from #105987. No release contains #105987 yet

Changelog category (leave one):

  • Performance Improvement

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

Replace a WHERE filter that is always true with an expression, so join reordering sees all joined tables as one graph.


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

Version info

  • Merged into: 26.10.1.2491-master (included in 26.10 and later)

@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a94c52c]

Summary: ✅


AI Review

Summary

This PR adds a first-pass rewrite that turns constant-true FilterSteps into ExpressionSteps so folded predicates stop breaking join-graph collection, and it expands the stateless coverage around folded predicates, masked secrets, projections, and join ordering. I did not find any correctness or PR-metadata issues in the current diff.

Missing context / blind spots
  • ⚠️ Static review only: there is no local build tree or binary in this checkout, so I did not execute the new stateless cases (05292, 05293) against a server. Running them on a current build would close the remaining runtime-validation gap.
Final Verdict

✅ No blocking issues found.

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Oct 5, 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 Oct 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR adds a query-plan pass that replaces a filter step with an expression step when its condition has folded to a constant true and the filter column is unused, so such a filter no longer blocks join reordering. None of the four flagged improvements can be attributed to it: clickbench Q33 (-12.9%) and Q34 (-13.7%) and TPC-H Q1 (-20.0%) are single-table aggregations with no constant-true filter. TPC-H Q7 (-25.9%) is a multi-way join, but its predicates are real column comparisons that do not fold to true. All four are therefore downgraded to not sure, because they share a similar CPU drop and a noisy history, which points to a build or environment difference rather than this change.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 33 not_sure 1134 988 -12.9% <0.0001 aggregation: Q33 is a plain GROUP BY over hits with no constant-folded WHERE, so the new always-true filter rewrite never runs here. The -12.9% shift on a noisy query is not attributable to this PR.
⚠️ 34 not_sure 1140 984 -13.7% <0.0001 aggregation: Q34 is a GROUP BY/ORDER BY LIMIT over hits with no join and no always-true filter for the rewrite to remove. The -13.7% shift matches Q33 and is not attributable to this diff.

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

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 1 not_sure 65 52 -20.0% <0.0001 aggregation: Q1 is a single-table lineitem aggregation with a real date predicate, so no filter step is constant-true and no join is reordered. Measurements are very noisy, so the -20.0% is not a PR effect.
⚠️ 7 not_sure 81 60 -25.9% <0.0001 join_operator: Q7 is a multi-way join, but its predicates are real column comparisons, not a constant that folds to true, so the rewrite has nothing to replace. The -25.9% matches the CPU drop seen on unrelated queries.

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.

Debug info
  • StressHouse run: 45c4fc02-aa17-4ee1-80ac-6609df3444d0
  • MIRAI run: ba609b4c-cd66-4200-bca5-8da1a4a219e1
  • PR check IDs:
    • clickbench_1082348_1791822912
    • clickbench_1082360_1791822912
    • clickbench_1082368_1791822912
    • tpch_adapted_1_official_1082376_1791822912
    • tpch_adapted_1_official_1082404_1791822912
    • tpch_adapted_1_official_1082419_1791822912

@clickhouse-gh

clickhouse-gh Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a94c52cdb with master b4ac7be09 (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

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

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -54.2 s (-5%) in total before that adjustment.

Job report

@nihalzp nihalzp self-assigned this Oct 7, 2026
{tryPushBucketTopKIntoAggregation, "aggregationBucketTopK", &QueryPlanOptimizationSettings::aggregation_bucket_top_k},
{trySplitFilter, "splitFilter", &QueryPlanOptimizationSettings::split_filter},
{tryMergeExpressions, "mergeExpressions", &QueryPlanOptimizationSettings::merge_expressions},
{tryReplaceAlwaysTrueFilter, "replaceAlwaysTrueFilter", &QueryPlanOptimizationSettings::optimize_plan},

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.

I wonder if this should be behind a new setting which is always useful to have.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, we can do it

@yariks5s
yariks5s added this pull request to the merge queue Oct 15, 2026
Merged via the queue into master with commit 4b796eb Oct 15, 2026
177 checks passed
@yariks5s
yariks5s deleted the yarik/replace-always-true-filter branch October 15, 2026 16:02
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
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