New functions isPrime and isProbablePrime#104234
Conversation
| } | ||
|
|
||
| template <typename T> | ||
| UInt8 isProbablePrimeWide(const T & num, unsigned rounds) |
There was a problem hiding this comment.
I think here it doesn't make a big difference, but when you want to have separate overloads of the same function for multiple types, you can use concepts that utilizes overload resolution. The only reasonable place I see it useful is instead of doing the manual dispatch in isProbablyPrime for wide vs other integers. However it is not so important, I just thought let's mention it, maybe you haven't thought about it.
There was a problem hiding this comment.
Thanks for pointing it out! I have improved it.
LLVM Coverage Report
Changed lines: 93.06% (161/173) · Uncovered code |
|
@groeneai Investigate the CI failures. |
|
@nihalzp Both failures are pre-existing flaky tests, not caused by this PR. Details:
|
| Metric | Value |
|---|---|
| Master hits in last 30 days | 14 (every day 5/5–5/10) |
| Unrelated PRs affected | 30+ (e.g. #102351, #96978, #96130, #104475, #104228, #100146, …) |
| Tracking | Issue #104219 (labeled flaky test, assigned @azat) |
| Active fix | PR #104296 by @azat — "Fix trivial count optimization with additional_table_filters with parallel replicas and analyzer" — OPEN, MERGEABLE |
The failure is exclusively on amd_llvm_coverage, ParallelReplicas, s3 storage — a combination this PR doesn't touch. Root cause is in the analyzer's trivial count optimization interacting with parallel replicas + additional_table_filters.
04103_user_network_bandwidth_throttler — Stateless tests (amd_tsan, parallel, 2/2)
Known flaky test, CI's own diagnosis says "not reproducible":
--- Randomized settings diagnosis ---
Step 1: Re-running with the same randomized settings (budget: 60s)...
Runs: 5, Failed: 0, Passed: 5, Other: 0
Result: All reruns passed. The failure is not reproducible (likely a transient issue).
| Metric | Value |
|---|---|
| Master hits in last 30 days | 5 (4/22, 4/24, 4/27, 5/2, 5/6) across amd_tsan / amd_msan / s3-storage variants |
| Unrelated PRs affected | 30+ |
| Tracking | Issue #103422 (auto-generated, assigned @tiandiwonder) |
| Origin | Introduced by PR #103080 (April 2026), 59 failures during its own CI |
The diff is a single counter flip: read 1 1 1 → read 1 1 0 — a race in the read-network-throttler test that doesn't depend on the new function code.
Summary
Neither failure touches src/Common/Primality.h, src/Functions/isPrime*.cpp, or the new test files. PR is functionally clean — your code already has @antaljanosbenjamin's approval. The two red checks here are infrastructure debt being tracked separately and will clear once #104296 merges.
Nothing to do on your end; safe to merge from a correctness standpoint.
— @groeneai (session cron:clickhouse-ci-task-worker:20260511-051500)
|
01710_projection_additional_filters 04103_user_network_bandwidth_throttler |
144a47e
|
@nihalzp, this was merged with red CI, which we never do. If the CI is red, stop working on features and work on CI instead. |
|
If we paid attention to the CI, we had a chance to find this #104633 before merging. |

isPrime(n)returns1ifnis prime and0otherwise. It supports unsigned integer types up toUInt64and always returns an exact result.Examples:
isProbablePrime(n[, rounds])(inspired by Java) returns0ifnis definitely composite and1ifnis probably prime. It gives exact results for unsigned integer types up toUInt64, and also supports probabilistic checks forUInt128andUInt256. The optionalroundsargument controls the confidence for wider integers.Examples:
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
New functions
isPrimeandisProbablePrimefor primality checks.isPrimereturns an exact result for unsigned integers up toUInt64.isProbablePrimealso supportsUInt128andUInt256; for those wider types,0means definitely composite and1means probably prime. The optional second argument ofisProbablePrime,rounds, controls the confidence, with the default of25rounds bounding the false-positive rate for a random composite below10^-15.Documentation entry for user-facing changes
Version info
26.5.1.510