Repository navigation
Revert "Revert "New functions isPrime and isProbablePrime"" - #104639
Conversation
|
Workflow [PR], commit [b00776d] Summary: ✅ AI ReviewSummaryThis PR reintroduces Final Verdict
|
|
@nihalzp, tests have failed. Please fix |
…t-104234-functions-is-prime
`isProbablePrime` on `UInt128`/`UInt256` delegated to `boost::multiprecision::miller_rabin_test`, which has no cancellation hook. Under heavy sanitizer + ThreadFuzzer instrumentation, a single round can stretch into minutes; combined with the server-side AST fuzzer mutating the `rounds` literal, the function hangs the stress test's `hung_check` for the full 30-minute window. This commit: - Adapts Boost's Miller-Rabin loop locally and calls `QueryStatus::checkTimeLimit` between rounds, so `KILL QUERY` and `max_execution_time` both interrupt the function. - Rejects `rounds > 256` with `BAD_ARGUMENTS`. `4^-256 < 10^-150` already, so larger values add no meaningful confidence and only widen the worst-case runtime under the AST fuzzer. See CI report on the AST-fuzzer-re-enablement PR: #101354 https://s3.amazonaws.com/clickhouse-test-reports/PRs/101354/f0038d26f27dc2d179136ae371e632746bab3c30/stress_test_arm_tsan/hung_check.log Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
A single `Primality::isProbablePrime` call on a wide `UInt128`/`UInt256` input runs many Miller-Rabin rounds; under the ASan+UBSan instrumentation of `function_prop_fuzzer`, this can take longer than the test's 30 second stop deadline, and the worker is then reported as stuck. The cancellation hook added in #104633 cannot help here: the stress test has no `QueryStatus`, so `check_cancelled` is a no-op. Add a hard constraint that caps the first argument at 1000, forcing the function through its fast bitmap / UInt64 path on every iteration. The function is still exercised on all supported input types - just on small values. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104639&sha=708387ba14ed6c25931b4d202c9198fc9d6cb223&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%2C%20function_prop_fuzzer%29 PR: #104639 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Thanks! Limiting I will edit on this PR to make the changes. |
The textbook Miller-Rabin bound assumes uniformly random independent witnesses. `isProbablePrime` seeds the witness RNG deterministically from the input so the same `(n, rounds)` pair reproduces the same result, which means a composite that passes the specific witness sequence will return `1` on every call rather than failing independently with probability `4^(-rounds)`. Soften the documentation and add a code comment to reflect this — the bound now describes typical accuracy across inputs, not a per-call probability for a fixed input.
LLVM Coverage Report
Changed lines: 90.99% (202/222) · Uncovered code |
Reverts #104638
Need to include changes from #104633 into this PR.
Version info
26.5.1.588