Skip to content

Better default selectivities for unknown and LIKE conditions - #101653

Merged
davenger merged 8 commits into
masterfrom
fix_default_selectivity
Apr 17, 2026
Merged

davenger merged 8 commits into
masterfrom
fix_default_selectivity

Conversation

@davenger

@davenger davenger commented Apr 2, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Improved default selectivity estimates for conditions without statistics to match industry-standard heuristics: 0.1 for LIKE condition selectivity, 0.33 for unknown condition selectivity.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.1020

@davenger
davenger marked this pull request as draft April 2, 2026 19:22
@clickhouse-gh

clickhouse-gh Bot commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [71a1b57]

Summary: ❌

job_name test_name status info comment
BuzzHouse (amd_debug) failure
Logical error: '!res.empty()' (STID: 2508-3ea0) FAIL cidb, issue ISSUE CREATED
BuzzHouse (amd_tsan) failure
Logical error: '!res.empty()' (STID: 2508-452d) FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR adjusts default selectivity heuristics in ConditionSelectivityEstimator (notably unknown predicates and LIKE/ILIKE handling), and adds coverage for LIKE-family estimates. The core logic looks sound after the NOT inversion fix, but there is one remaining documentation-level test-comment issue.

Findings
  • 💡 Nits
    • [src/Storages/Statistics/tests/gtest_stats.cpp:246] The comment says “notLike function directly”, but the query uses SQL operator syntax (a not like ...), not a direct notLike function call. Suggested wording: “NOT LIKE operator directly”.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Apr 2, 2026
@hanfei1991 hanfei1991 self-assigned this Apr 3, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

davenger and others added 3 commits April 7, 2026 13:01
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
UInt64 not_ilike_rows = estimate("not(a ilike '%pattern%')");
EXPECT_EQ(not_ilike_rows, 9000u);

/// notLike function directly: 0.9 * 10000 = 9000 rows.

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.

a not like '%pattern%' here is SQL operator syntax, not a direct notLike function call.

Please reword this comment to avoid confusion, e.g. “NOT LIKE operator directly”.

@clickhouse-gh

clickhouse-gh Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 100.00% (54/54) · Uncovered code

Full report · Diff report

@davenger
davenger marked this pull request as ready for review April 16, 2026 14:17
@davenger
davenger requested a review from hanfei1991 April 16, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants