Fix countmin statistics bug when comparing float32 column with float64 by hanfei1991 · Pull Request #105047 · ClickHouse/ClickHouse · GitHub
Skip to content

Fix countmin statistics bug when comparing float32 column with float64#105047

Merged
hanfei1991 merged 6 commits into
ClickHouse:masterfrom
hanfei1991:hanfei/fix-countmin-sketch
Jun 1, 2026
Merged

Fix countmin statistics bug when comparing float32 column with float64#105047
hanfei1991 merged 6 commits into
ClickHouse:masterfrom
hanfei1991:hanfei/fix-countmin-sketch

Conversation

@hanfei1991

@hanfei1991 hanfei1991 commented May 15, 2026

Copy link
Copy Markdown
Member

fix #104892

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix countmin statistics prewhere selectivity estimation for Float32 columns. Two bugs caused countmin statistics to silently produce wrong estimates for Float32 columns:

  • ConditionSelectivityEstimator skipped statistics entirely when the column type (Float32) was narrower than the literal type (Float64), falling back to default selectivity and ignoring the sketch;
  • StatisticsCountMinSketch::estimateEqual hashed the first N bytes of a Field object, but Field stores Float32 as Float64 (NearestFieldType = Float64), so the byte pattern used at query time differed from the actual Float32 bytes stored during build.

Version info

  • Merged into: 26.6.1.297

@clickhouse-gh

clickhouse-gh Bot commented May 15, 2026

Copy link
Copy Markdown
Contributor

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 15, 2026
Comment thread src/Storages/Statistics/ConditionSelectivityEstimator.cpp
@alexey-milovidov

Copy link
Copy Markdown
Member

This was fixed by #105146. Let's update the branch.

Comment thread src/Storages/Statistics/StatisticsCountMinSketch.cpp
@clickhouse-gh

clickhouse-gh Bot commented May 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 23/29 (79.31%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@vdimir vdimir self-assigned this Jun 1, 2026
@hanfei1991 hanfei1991 added this pull request to the merge queue Jun 1, 2026
Merged via the queue into ClickHouse:master with commit 7ca8362 Jun 1, 2026
166 checks passed
@hanfei1991 hanfei1991 deleted the hanfei/fix-countmin-sketch branch June 1, 2026 11:33
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

countmin statistics give wrong estimates for Float32 columns due to hash mismatch between column and Field storage

4 participants