Repository navigation
Functions stress test - #93543
Functions stress test#93543
Conversation
|
Workflow [PR], commit [bcbfb8a] Summary: ✅ AI ReviewSummaryThis PR adds a large Missing context
Findings
ClickHouse Rules
Performance & Safety
Final Verdict
|
1. Update expected error codes in tests to match new error codes: - `transform`: BAD_ARGUMENTS → NOT_IMPLEMENTED - `tupleElement`: NOT_FOUND_COLUMN_IN_BLOCK → ARGUMENT_OUT_OF_BOUND (for index errors) and BAD_ARGUMENTS (for name errors) - `parseDateTime`: NOT_ENOUGH_SPACE → CANNOT_PARSE_DATETIME 2. Fix implicit conversion warnings in `StorageGenerateRandom.cpp` that cause arm_tidy build failures: - Add explicit casts in `fillBufferWithRandomPrintableASCIIBytes` - Fix Enum size type from UInt8/UInt16 to size_t - Fix fmt::format scale parameter type 3. Fix DateTime64 random generation to maintain backward compatibility for non-fuzzy mode by using UInt64 arithmetic instead of Int64 Co-Authored-By: Claude Opus 4.5 <[email protected]>
Co-Authored-By: Claude Opus 4.5 <[email protected]>
- `StorageGenerateRandom.cpp`: Add explicit casts in `fuzzyRandomInteger` template and `intExp10` call to avoid precision loss warnings - `modulo.cpp`: Add explicit cast for negation result to avoid `-Wimplicit-int-conversion-on-negation` warning Co-Authored-By: Claude Opus 4.5 <[email protected]>
Fix clang-tidy errors in `gtest_functions_stress.cpp`: - Remove redundant `static` in anonymous namespace - Fix implicit int-to-float conversions with explicit casts - Remove unused variable, use `std::min`, `empty()`, `const` methods - Fix misleading indentation, qualified auto, move-const-arg - Add NOLINT for `__tsan_on_report` reserved identifier Update test reference files to match changed error codes: - `ARGUMENT_OUT_OF_BOUND` instead of `NOT_FOUND_COLUMN_IN_BLOCK` for `tupleElement` - `CANNOT_PARSE_DATETIME` instead of `NOT_ENOUGH_SPACE` for `parseDateTime` - Regenerate Enum values in `generateRandom` test after `StorageGenerateRandom` changes Co-Authored-By: Claude Opus 4.6 <[email protected]>
… wrapper The `TupleOrArrayFunction` wrapper delegates `executeImpl` directly to the inner array/tuple function, bypassing the inner function's constant argument handling. Because the wrapper had `useDefaultImplementationForConstants() = true` but returned empty `getArgumentsThatAreAlwaysConstant()`, the framework would unwrap ALL constant arguments before calling `executeImpl`. This caused the inner `arrayLpNorm` to receive its `p` parameter as a non-const column, triggering an `ILLEGAL_COLUMN` exception. Fix by forwarding `getArgumentsThatAreAlwaysConstant` from the inner `array_function`, so the framework preserves constness of the right arguments. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Avoid nesting `chassert` inside `SCOPE_EXIT` macro, which causes "expected expression" compilation error in sanitizer builds due to macro expansion issues. Use `make_scope_guard` directly instead. Update `01905_to_json_string` reference to match new enum values produced by the refactored random data generation in `StorageGenerateRandom`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ange After merging master, `WriteBufferValidUTF8` no longer emits U+FFFD replacement characters for invalid UTF-8 sequences in JSON output - it strips them instead. Update the reference file to match. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add `ORDER BY length(a)` to the multi-row query to make row order deterministic. Update reference to match the sorted output. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Skip the stress test under MSan: it finds uninitialized-memory reads in functions that are hard to debug without a local MSan build. The test still runs under ASan/UBSan and TSan where it provides value. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 86.63% (2236/2581, 12 noise lines excluded) |
This is a grave mistake. MSan is the most important of all. Will continue in subsequent PRs. |
Address review TODOs and follow-up items from PR #93543: - Remove template parameters from `FunctionKqlArraySort`: replace `<Name, is_desc>` template with runtime constructor parameters. - Add `H3Validator` to H3 functions that were missing input validation (`h3GetBaseCell`, `h3GetResolution`, and all directed edge functions), preventing out-of-bounds reads in the H3 contrib library. Add `validateEdge` method to `H3Validator` for directed edge indices. - Add bounds checking to WKB parsing (`readWKB` and variants) to prevent huge memory allocations on malformed input. - Add parameter validation to random distribution functions to prevent hangs with extreme parameters (e.g. `randBinomial` with huge trials, `randChiSquared` with extreme degrees of freedom). - Re-enable the functions stress test under MSan (was skipped). - Add function selection bias (power-of-two-choices) so less-tested functions get more coverage. - Add settings randomization to the stress test, toggling various boolean and enum settings that affect function behavior. - Remove all fixed functions from the stress test excluded list. #93543 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
@al13n321 @alexey-milovidov this PR contains some fixes in functions that might be useful to backport, but this PR contains both fuzzer implementation and bug fixes that makes it very hard to backport the fixes. For example, one of the fixes fixed incorrect result of function |
Fix `IPv6StringToNumOrDefault` not properly zeroing output bytes on parse failure. Only one byte was zeroed (`vec_res[i] = 0`) instead of all 16 bytes (`std::fill_n(&vec_res[out_offset], offset_inc, 0)`), causing stale data from previous successful parses to leak into default results. Backport of ClickHouse#93543
Fix `IPv6StringToNumOrDefault` not properly zeroing output bytes on parse failure. Only one byte was zeroed (`vec_res[i] = 0`) instead of all 16 bytes (`std::fill_n(&vec_res[out_offset], offset_inc, 0)`), causing stale data from previous successful parses to leak into default results. Backport of #93543 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Fix `IPv6StringToNumOrDefault` not properly zeroing output bytes on parse failure. Only one byte was zeroed (`vec_res[i] = 0`) instead of all 16 bytes (`std::fill_n(&vec_res[out_offset], offset_inc, 0)`), causing stale data from previous successful parses to leak into default results. Backport of #93543 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Fix `IPv6StringToNumOrDefault` not properly zeroing output bytes on parse failure. Only one byte was zeroed (`vec_res[i] = 0`) instead of all 16 bytes (`std::fill_n(&vec_res[out_offset], offset_inc, 0)`), causing stale data from previous successful parses to leak into default results. Backport of #93543 Co-Authored-By: Claude Opus 4.6 <[email protected]>
`04051_functions_various_bugs` and `03784_functions_various_bugs` (both added by #93543) asserted that `trimRight` with a trim character set longer than 16 bytes throws `TOO_LARGE_STRING_SIZE`. That limit is removed, so the queries now succeed; convert them to positive assertions and update the references.
`trimLeft`, `trimRight`, `trimBoth` (and aliases `ltrim`, `rtrim`,
`trim`) rejected a custom trim character set longer than 16 bytes with:
Code: 131. DB::Exception: Function trimLeft supports at most 16 trim
characters, but 17 were provided. (TOO_LARGE_STRING_SIZE)
The second argument was fed into `SearchSymbols`, a SIMD search primitive
that is intentionally capped at 16 symbols (`__m128i`) for hot parsers
(CSV/TSV/JSON/URL). A user-provided trim set can be arbitrarily long, so
this was the wrong tool. A real-world query such as
TRIM(LEADING 'SRID=4326;POINT (' FROM col)
(17 bytes) worked in 25.2 but started failing in 26.4.
Fix: for the custom-characters case, use a 256-entry byte membership
table instead of `SearchSymbols`. It supports a set of any length, looks
up each byte in O(1), and is built once per block. The default
whitespace path keeps its compile-time SIMD search, and the shared
`SearchSymbols` infrastructure is untouched.
Caused by: ClickHouse#93543
`trimLeft`, `trimRight`, `trimBoth` (and aliases `ltrim`, `rtrim`,
`trim`) rejected a custom trim character set longer than 16 bytes with:
Code: 131. DB::Exception: Function trimLeft supports at most 16 trim
characters, but 17 were provided. (TOO_LARGE_STRING_SIZE)
The second argument was fed into `SearchSymbols`, a SIMD search primitive
that is intentionally capped at 16 symbols (`__m128i`) for hot parsers
(CSV/TSV/JSON/URL). A user-provided trim set can be arbitrarily long, so
this was the wrong tool. A real-world query such as
TRIM(LEADING 'SRID=4326;POINT (' FROM col)
(17 bytes) worked in 25.2 but started failing in 26.4.
Fix: for the custom-characters case, use a 256-entry byte membership
table instead of `SearchSymbols`. It supports a set of any length, looks
up each byte in O(1), and is built once per block. The default
whitespace path keeps its compile-time SIMD search, and the shared
`SearchSymbols` infrastructure is untouched.
Caused by: #93543
`04051_functions_various_bugs` and `03784_functions_various_bugs` (both added by #93543) asserted that `trimRight` with a trim character set longer than 16 bytes throws `TOO_LARGE_STRING_SIZE`. That limit is removed, so the queries now succeed; convert them to positive assertions and update the references.
`trimLeft`, `trimRight`, `trimBoth` (and aliases `ltrim`, `rtrim`,
`trim`) rejected a custom trim character set longer than 16 bytes with:
Code: 131. DB::Exception: Function trimLeft supports at most 16 trim
characters, but 17 were provided. (TOO_LARGE_STRING_SIZE)
The second argument was fed into `SearchSymbols`, a SIMD search primitive
that is intentionally capped at 16 symbols (`__m128i`) for hot parsers
(CSV/TSV/JSON/URL). A user-provided trim set can be arbitrarily long, so
this was the wrong tool. A real-world query such as
TRIM(LEADING 'SRID=4326;POINT (' FROM col)
(17 bytes) worked in 25.2 but started failing in 26.4.
Fix: for the custom-characters case, use a 256-entry byte membership
table instead of `SearchSymbols`. It supports a set of any length, looks
up each byte in O(1), and is built once per block. The default
whitespace path keeps its compile-time SIMD search, and the shared
`SearchSymbols` infrastructure is untouched.
Caused by: #93543
`04051_functions_various_bugs` and `03784_functions_various_bugs` (both added by #93543) asserted that `trimRight` with a trim character set longer than 16 bytes throws `TOO_LARGE_STRING_SIZE`. That limit is removed, so the queries now succeed; convert them to positive assertions and update the references.
Changelog category (leave one):
Changelog entry:
Implement a stress test for functions, checking the soundness of their various properties.
A test that runs random SQL functions on random arguments and checks many things like:
Currently many of these checks fail on many functions for many different reasons. I'm working on triaging suppressing these errors before the test can run in CI.
Here are some classes of problems found:
getReturnTypeImpl) to the execution stage (executeImpl). This is super inconvenient to do, so someIFunctions havemutablefields for that (e.g. Clean up thread safety in FunctionConvert #90644 ), which may break things in subtle ways if the sameIFunctionOverloadResolverinstance (which is just anIFunctionpointer on the inside) is used to create multipleIExecutableFunctioninstances (which are also just anIFunctionpointer on the inside, the exact same one, shared). MaybeIFunctionshould have a virtualclone()method, andFunctionToOverloadResolverAdaptor::buildshould use it, so that eachIFunctioninstance gets only onegetReturnTypeImplcall for only one overload, andgetReturnTypeImplcan be non-const and just assign fields?intDiv(NULL, 0)shouldn't throw. Every function that's in this situation has a different awkward ad-hoc solution for this, and most of those solutions have some cases where they fail. E.g.select modulo(if(number=0,null,0), CAST(number AS IPv4)) from numbers(2)fails, but succeeds if you run it separately on each row (from numbers(1)andfrom numbers(1, 1)). There should be a better default implementation for nulls; maybeIExecutableFunction::defaultImplementationForNullscould just check if the function is fallible, and always filter input rows in that case?ColumnNullableis allowed to have non-default values in the nested column in NULL rows. Some functions output such columns, some other functions break on such inputs.select -1::Int32 as x, 2::Int32 as y, x%y, materialize(x)%y,select '' as x, 0::Enum8('a' = 0) as y, x < y, materialize(x) < y.Version info
26.4.1.8026.3.11.13,26.2.19.17,26.1.13.2,25.8.24.9