Skip to content

Revert "Join reordering: FK->PK heuristic for equi joins without NDV statistics" - #120923

Merged
alexey-milovidov merged 2 commits into
masterfrom
revert-120176-join-order-fk-pk-heuristic
Sep 19, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
revert-120176-join-order-fk-pk-heuristic

Conversation

@fm4v

@fm4v fm4v commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

Reverts #120176.

Since that merge (2026-09-17 22:33 UTC), every master run of Performance Comparison (amd_release, master_head, 2/6) that samples iceberg_suite_tpch query 4 (TPC-H Q5 over the CI Iceberg dataset) fails with 10 errors: the query hits the runner's 15 s max_execution_time on its first measured run, right after a 1.6 s prewarm on the same server. It ran in ~350 ms before. On 2026-09-18, 16 of 24 master runs of that shard failed, and PR runs fail the same way, for example https://s3.amazonaws.com/clickhouse-test-reports/PRs/120677/292397793c01e430db3c87625724c3a9d94b4610/pr/performance_comparison_amd_release_master_head_2_6/report.html.

Root cause, repro with the public dataset and CI binaries, and notes for re-landing the heuristic are in the linked issue. In short: ReadFromObjectStorageStep has no row estimate, so after the prewarm run only two leaves get row counts from the hash-table statistics cache. The new cost model then treats the one relation with a known size as the most expensive thing to join, starts with the many-to-many customer ⋈ supplier on nationkey, estimates the resulting blob at 1 row (one side unknown, other side region[1]), and builds it as the hash table.

This is a plain git revert -m 1 of the merge commit, so the master perf CI is green again while the heuristic is reworked for relations without row estimates.

Closes: #120921

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Version info

  • Merged into: 26.10.1.205 (included in 26.10 and later)

…r_no_stats_heuristic"

This reverts commit 07f2c40, reversing
changes made to 2493bb8.
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5ea686c]

Summary: ✅

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 18, 2026
INSERT INTO ta SELECT number FROM numbers(100);
INSERT INTO tb SELECT number FROM numbers(100);
INSERT INTO tc SELECT number FROM numbers(10);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This revert keeps the greedy planner's non-equi connectivity handling: GreedyJoinOrderOptimizer::solve still treats a pair as connected as soon as getApplicableExpressions returns cross-side predicates, so the ta/tb/tc range-join case remains a valid invariant of the current optimizer. Deleting this test broadens the rollback beyond the stated FK->PK/no-stats heuristic and drops the only focused coverage I could find for "prefer the range-connected pair over a bare cross product". Please keep this test or re-add an equivalent greedy regression case.

@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 18, 2026
Clears the stale `Build (arm_tidy)` failure on this pull request: it was a
duplicate `#include <IO/VarInt.h>` in `src/Core/tests/gtest_settings.cpp`,
unrelated to the revert and already removed on master by 4137c11.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

Merged master into this branch (5ea686c).

The only red job here was Build (arm_tidy), and it had nothing to do with the revert: a duplicate #include <IO/VarInt.h> in src/Core/tests/gtest_settings.cpp, flagged by readability-duplicate-include. It was already removed on master by 4137c11 (2026-09-19 01:20), which this branch did not contain. The diff of the merged branch against master is byte-identical in shape to the revert commit (25 files, 213 insertions, 382 deletions), so nothing else came along.

Independent confirmation on aarch64, with the public tpch_ice_sf10 dataset attached as IcebergLocal and the iceberg_suite_tpch settings (join_use_nulls=1, max_bytes_ratio_before_external_join=0, max_execution_time=15). Every binary is the CI arm_release build; run 1 is the prewarm, in a server process already warmed by the suite's other queries:

binary prewarm run 2 run 3 run 4 run 5
master before #120176 (2493bb8) 0.84 s 0.30 s 0.27 s 0.31 s 0.31 s
master today (26.10.1.183) 0.72 s timeout timeout timeout timeout
#120762 (forward fix) 0.78 s 1.22 s 1.62 s 1.63 s 1.66 s

So the revert restores the 0.3 s steady state, while #120762 removes the hard failure but leaves Q5 about 5x slower than before #120176 - which is the argument for landing the revert now and re-landing the heuristic on top of the costing fix.

Still reproducing on PR runs today, e.g. https://s3.amazonaws.com/clickhouse-test-reports/PRs/108550/0d2109d9c2c0cc61f4a3e3f5de395f968a1fed81/pr/performance_comparison_arm_release_master_head_5_6/report.html (#108550, which does not touch joins). Over the last two days Performance Comparison (amd_release, master_head, 2/6) and (arm_release, master_head, 5/6) failed on 30 of 96 master runs.

@alexey-milovidov
alexey-milovidov merged commit 0b3b89d into master Sep 19, 2026
176 of 177 checks passed
@alexey-milovidov alexey-milovidov self-assigned this Sep 19, 2026
@alexey-milovidov
alexey-milovidov deleted the revert-120176-join-order-fk-pk-heuristic branch September 19, 2026 18:34
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 19, 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-not-for-changelog This PR should not be mentioned in the changelog 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.

Join reordering: TPC-H Q5 over Iceberg times out after the FK->PK heuristic (perf CI iceberg_suite_tpch fails on master)

3 participants