Repository navigation
Evaluate randomHadamardTransform once for a constant vector - #112921
Conversation
`randomHadamardTransform` did not use the default implementation for
constant arguments, so it called `convertToFullColumnIfConst` on its
first argument and ran the transform for every row of the block even
when the vector was a constant. It also returned a plain `ColumnArray`
rather than a `ColumnConst`, which prevented the analyzer from folding
the call to a literal.
This matters for the intended vector search usage, where the query
vector has to be rotated the same way as the stored vectors:
WITH randomHadamardTransform([...]) AS target
SELECT id FROM t
ORDER BY cosineDistanceTransposedQuantized(vec_quantized, target, 2, 384)
LIMIT 100
On 2 million 768-dimensional vectors this query took 2.744 s, while the
same query with the transform hidden in a scalar subquery (so that it is
computed once) took 0.148 s.
Set `useDefaultImplementationForConstants` and declare `seed` and
`output_dims` in `getArgumentsThatAreAlwaysConstant`, so that an
all-constant call is executed on a single row and wrapped in a
`ColumnConst`. The constant check for `seed` and `output_dims` now comes
from the base class; its error code is still `ILLEGAL_COLUMN`.
Related: #103466
|
Workflow [PR], commit [ae40953] Summary: ✅
AI ReviewSummaryThis PR switches Final Verdict✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/20 (90.00%) · Uncovered code |
|
📊 Cloud Performance Report ✅ AI verdict: This PR only modifies the randomHadamardTransform function used in vector search (constant-folding a fully-constant call). No ClickBench query exercises that path, so the flagged -11.6% improvement on Q17 (GROUP BY UserID/SearchPhrase) cannot plausibly be attributed to this change and is downgraded to not_sure as measurement variance. Both the private and public diffs are identical and touch only this one function plus its test and docs, so no per-query performance effect is expected. clickbenchFlagged queries (1 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 9/11 (81.82%) · Uncovered code |
|
🕵 Merged The two CI reds — The Related: #112940 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
|
🕵 Merged The only CI red on the previous run — |
…ransform Address review: `output_dims` is documented to never exceed the transform length, but the `k > working_dim` check lives inside the `length != 0` branch, so a positive `output_dims` on an empty vector silently returned `[]` instead of throwing. Throw `ARGUMENT_OUT_OF_BOUND` for that case and cover both the constant and the per-row paths in the test. Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 Addressed the AI review finding: an explicit The only CI red on the previous run — |
The previous commit made an explicit `output_dims` on an empty vector throw `ARGUMENT_OUT_OF_BOUND`. That behavior change broke the existing `04408_random_hadamard_transform`, which pins the released behavior: an empty input array yields an empty array and `output_dims` does not apply to it. Rejecting it would also turn a column that merely contains some empty arrays into a query-wide error, so restore the original semantics and assert them in the new test instead. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 The only CI red on Reverted that behavior change in Verified locally with a |
|
🕵 Merged
|
|
🕵 The only CI red on Otherwise the PR is ready: AI review verdict is "✅ Approve" and there are no unresolved review threads. |
…viewIfPermitted
The parser accepts only a function call after ELSE in `viewIfPermitted`
(the argument is a table function such as `null('structure')`), but the
formatter used the generic expression path for it, so a function that is
normally written as an operator (e.g. `not`) was formatted as `ELSE NOT x`,
which cannot be parsed back. Found by AST fuzzer: the query
`... viewIfPermitted(SELECT ... ELSE not(...)) ...` failed the AST
formatting consistency check with a logical error.
Format the ELSE argument with `allow_operators = false` so it keeps the
function-call form.
Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112921&sha=22a3a1e446758ffbb12704d86470c4c27a4e73a2&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%29
Found in: ClickHouse#112921
Co-Authored-By: Claude Fable 5 <[email protected]>
|
🕵 CI on @groeneai, please investigate this flake: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112921&sha=ba9c3d4cc9183c01f61bc5383eabc5f5d42adc22&name_0=PR&name_1=Stateless%20tests%20(amd_debug,%20sequential) and provide a fix in a separate PR (open a tracking issue too, since the previous ones are closed). If a fix is already in progress, link it here. Merged |
|
No fix in progress: no open PR touches this test, and the three earlier issues are closed. I opened #114213 to track it, and I am working on the fix. Root cause from the failing run: the cache was already full of non-releasable segments when the test warmed up, so nothing could be evicted for its own data.
The test's In that same job, of the 8 runs of the measured query only the failing one logged any cache-pressure lines (18 of them); all 7 reruns logged zero. That is what makes it look random. The test already has The assertion is on an absolute byte counter that requires a fully warm cache, which the test cannot guarantee on a shared cache. I will fix it by giving the test its own cache disk, or by verifying the warm-up instead of assuming it, and will link the PR on #114213 and here. |
|
Fix: #114245, tracked by The table is The PR gives the table its own inline cache disk and leaves the assertion, the reference file and the |
|
🕵 The three
@groeneai, the fixes are already in progress (linked above) — once they land on |
Backport #112921 to 26.7: Evaluate randomHadamardTransform once for a constant vector
|
@alexey-milovidov are there performance tests for randomHadamardTransform? |
randomHadamardTransformdid not use the default implementation for constant arguments, so it calledconvertToFullColumnIfConston its first argument and ran the transform for every row of the block even when the vector was a constant. It also returned a plainColumnArrayrather than aColumnConst, so the analyzer could not fold the call to a literal either (resolveFunction.cpponly folds when the executed column is aColumnConst).This matters for the intended vector search usage, where the query vector has to be rotated the same way as the stored vectors:
On 2 million 768-dimensional vectors (
QBit(Int8, 768, 128), 2 bits and 384 dimensions, 64-core machine, warm cache):The whole difference was the transform of the constant query vector being repeated for every row; after the change the inline form costs the same as the hand-rolled workaround.
The fix sets
useDefaultImplementationForConstantsand declaresseedandoutput_dimsingetArgumentsThatAreAlwaysConstant, so an all-constant call is executed on a single row and wrapped in aColumnConst. The constant check forseedandoutput_dimsnow comes from the base class, with the sameILLEGAL_COLUMNerror code as before.Related: #103466
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
randomHadamardTransformof a constant vector is now evaluated once instead of once per row. This speeds up vector search queries that rotate the query vector withrandomHadamardTransformbefore comparing it against aQBitcolumn.Version info
26.7.4.41