Skip to content

Keep the IN selectivity estimation bound under old compatibility - #118095

Merged
fm4v merged 4 commits into
masterfrom
nik/statistics-max-set-size-compat
Sep 6, 2026
Merged

fm4v merged 4 commits into
masterfrom
nik/statistics-max-set-size-compat

Conversation

@fm4v

@fm4v fm4v commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Related: #116137
Related: #114389

#114389 added statistics_max_set_size_for_exact_selectivity_estimation (default 10000) to bound the cost of estimating the selectivity of col IN (...) from column statistics. Its settings changes history entry recorded 0 (no limit) as the previous value, so any user running with compatibility set to 26.6 or an earlier version still gets the uncapped estimation, which is exactly the behavior that could add hundreds of milliseconds and gigabytes of allocations to the planning of a single query.

This makes the previous value equal to the new one, so the bound applies regardless of compatibility. An explicitly specified value still wins, as before.

Changelog category (leave one):

  • Performance Improvement

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

The bound on the cost of estimating the selectivity of col IN (...) from column statistics, controlled by statistics_max_set_size_for_exact_selectivity_estimation, is now also applied when compatibility is set to 26.6 or an earlier version.


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

Version info

  • Merged into: 26.9.1.863 (included in 26.9 and later)
  • Backported to: 26.8.3.82, 26.7.7.69, 26.6.5.108

The settings changes history entry for `statistics_max_set_size_for_exact_selectivity_estimation` had 0 as the previous value, so `compatibility` with 26.6 or an earlier version restored the uncapped estimation, which can add hundreds of milliseconds to the planning of a single query.

Related: #116137
Related: #114389
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4ac9d78]

Summary: ❌

job_name test_name status info comment
Stress test (arm_tsan) FAIL
ThreadSanitizer: data race (STID: 3097-4413) FAIL cidb

AI Review

Summary

This PR turns the statistics_max_set_size_for_exact_selectivity_estimation history entry into a no-op rollback and duplicates it into the 26.6, 26.7, and 26.9 blocks so older compatibility levels no longer re-enable uncapped IN selectivity estimation. The settings-history change looks internally consistent with applyCompatibilitySetting, but the PR still lacks focused proof that the compatibility contract is preserved end to end, so I would not approve it yet.

Findings

⚠️ Majors

  • [src/Core/SettingsChangesHistory.cpp:111] This PR changes the compatibility behavior of a user-visible setting, but there is still no focused regression test showing that an old compatibility level keeps statistics_max_set_size_for_exact_selectivity_estimation at 10000 instead of restoring the uncapped 0. Because the same setting is also manually overridable, the absence of coverage leaves two important branches unproven: the compatibility-derived default and the "explicit user value wins" override.
    Suggested fix: add a tiny stateless test that checks getSetting or system.settings under an old compatibility level and after an explicit SET statistics_max_set_size_for_exact_selectivity_estimation = 0.
Tests
  • ⚠️ Add a focused stateless regression test for the exact contract this patch changes: compatibility = '26.5' or compatibility = '26.6' should still yield statistics_max_set_size_for_exact_selectivity_estimation = 10000, and an explicit statistics_max_set_size_for_exact_selectivity_estimation = 0 in the same session should still override compatibility.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: add the focused regression test above so the compatibility-preserving settings history entries are actually pinned by CI.

LLVM Coverage Report

Measured on commit 4ac9d78.

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

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

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Sep 4, 2026
@nickitat nickitat self-assigned this Sep 4, 2026
The entry is a no-op for `compatibility` (previous value equals the new one), but having it in every version block from 26.6 on makes the backports to the 26.6, 26.7 and 26.8 branches land in the block that exists there.
{"join_algorithm", "direct,parallel_hash,hash", "direct,parallel_hash,hash,ie_join", "Appended `ie_join` to the default list, so a join whose `ON` section has only inequality conditions is executed with IEJoin instead of a `CROSS JOIN` with a filter. Being last, it is used only when the other algorithms do not apply."},
{"unique_key_probe_implementation", "auto", "auto", "New setting: selects the UNIQUE KEY probe implementation (currently only the simple baseline exists)"},
{"statistics_max_set_size_for_exact_selectivity_estimation", 0, 10000, "New setting to bound the cost of estimating the selectivity of `IN` with a large set: above the limit the estimator uses the size of the set and its bounding range instead of the exact ranges. Before 26.8 the estimation was uncapped, so the previous value is 0 (no limit) and `compatibility` with an earlier version restores the exact ranges for sets of any size."},
{"statistics_max_set_size_for_exact_selectivity_estimation", 10000, 10000, "New setting to bound the cost of estimating the selectivity of `IN` with a large set: above the limit the estimator uses the size of the set and its bounding range instead of the exact ranges. The previous value is deliberately equal to the new one, so that `compatibility` with an earlier version keeps the bound instead of restoring the uncapped estimation, which could add hundreds of milliseconds to the planning of a single query."},

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 changes the compatibility behavior of a concrete user-visible setting, but the final revision no longer has any focused regression test for it. Right now nothing in CI proves that statistics_max_set_size_for_exact_selectivity_estimation still stays at 10000 under compatibility = '26.7' / '26.6', or that an explicit statistics_max_set_size_for_exact_selectivity_estimation = 0 still overrides compatibility as intended.

A tiny stateless test against system.settings or getSetting would close that gap.

@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 4ac9d78d1 with master 384f59b5e (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

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 41 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: 9ad7aecc-7161-44bd-a702-1eedb418f4c9
  • MIRAI run: becac6e1-b424-4426-86af-a3254b90a8bf
  • PR check IDs:
    • clickbench_1407206_1788700709
    • clickbench_1407212_1788700709
    • clickbench_1407218_1788700709
    • tpch_adapted_1_official_1407229_1788700710
    • tpch_adapted_1_official_1407240_1788700709
    • tpch_adapted_1_official_1407276_1788700709

Preserve both the compatibility bound and the new settings history entries.

Related: #118095
@fm4v
fm4v added this pull request to the merge queue Sep 6, 2026
Merged via the queue into master with commit 588d908 Sep 6, 2026
173 of 175 checks passed
@fm4v
fm4v deleted the nik/statistics-max-set-size-compat branch September 6, 2026 19:02
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 6, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo labels Sep 6, 2026
PedroTadim added a commit that referenced this pull request Sep 10, 2026
The cherry-pick resolution imported master's whole 26.7, 26.8 and 26.9
settings-history sections. They name 153 settings that do not exist on 26.6,
so applyCompatibilitySetting() threw UNKNOWN_SETTING for every
`SET compatibility`, and servers with `compatibility` in a profile exited
with code 115 at startup.

26.6 already declares the setting in its own 26.6 section, so the backport is
just the previous value 0 -> 10000 on that entry.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 10, 2026
The cherry-pick resolution imported master's whole 26.8 and 26.9
settings-history sections. They name settings that do not exist on 26.7, so
applyCompatibilitySetting() threw UNKNOWN_SETTING for every
`SET compatibility`, and servers with `compatibility` in a profile exited
with code 115 at startup.

What is left is the original change itself: previous value 0 -> 10000 on the
declaring entry, plus the two no-op entries in the 26.7 and 26.6 sections.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
PedroTadim added a commit that referenced this pull request Sep 10, 2026
The cherry-pick resolution imported master's whole 26.9 settings-history
section. It names settings that do not exist on 26.8, so
applyCompatibilitySetting() threw UNKNOWN_SETTING for every
`SET compatibility`, and servers with `compatibility` in a profile exited
with code 115 at startup.

What is left is the original change itself: previous value 0 -> 10000 on the
declaring entry, plus the two no-op entries in the 26.7 and 26.6 sections.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Sep 10, 2026
Backport #118095 to 26.8: Keep the IN selectivity estimation bound under old compatibility
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 10, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 10, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 10, 2026
Backport #118095 to 26.7: Keep the IN selectivity estimation bound under old compatibility
PedroTadim added a commit that referenced this pull request Sep 11, 2026
Backport #118095 to 26.6: Keep the IN selectivity estimation bound under old compatibility
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo v26.6-must-backport v26.7-must-backport v26.8-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants