Repository navigation
Fix DEFAULT recomputation for QBit subcolumns in transposed distance functions (Sonnet) - #110638
alexey-milovidov wants to merge 2 commits into
Conversation
…nsposed) `cosineDistanceTransposed` and `cosineDistanceTransposedQuantized` rewrite their `QBit` argument into a read of the individual bit-plane subcolumns (e.g. `qb.1`, `qb.2`, ...) via `DistanceTransposedPartialReadsPass`. When the `QBit` column is not yet physically materialized in a part (its value comes from a `DEFAULT` expression, e.g. right after `ADD COLUMN ... DEFAULT ...` or mid-`MATERIALIZE COLUMN` mutation), `injectRequiredColumnsRecursively` looked up the `DEFAULT` using the raw, possibly-subcolumn name (`qb.1`) instead of resolving it to the top-level storage column name (`qb`) first. `ColumnsDescription::getDefault` only indexes top-level column names, so the lookup silently failed for subcolumn requests, and the `DEFAULT`'s real dependency columns (e.g. `v` in `qb DEFAULT CAST(v, 'Array(BFloat16)')`) were never injected for physical reading. `IMergeTreeReader::evaluateMissingDefaults` then fell back to a zero-length placeholder for the missing dependency, which fails `QBit`'s strict per-vector size check with `Code: 190. SIZES_OF_ARRAYS_DONT_MATCH`. A plain (non-transposed) read of the same column was unaffected, since it requests the top-level column name directly. Closes: #110634
|
Workflow [PR], commit [daea90a] Summary: ❌
AI ReviewSummaryThis PR fixes the missing- Findings
Final Verdict |
…-default-mutation
|
Merged in the latest
@groeneai, could you take a look at the |
| WITH (SELECT CAST(qb, 'Array(Float32)') FROM t_qbit_default_transposed WHERE id = 0) AS r | ||
| SELECT id, round(cosineDistanceTransposed(qb, r, 16, 4), 4) FROM t_qbit_default_transposed ORDER BY id; | ||
|
|
||
| SELECT 'cosineDistanceTransposedQuantized must recompute the DEFAULT too, instead of reading an empty source column'; | ||
| WITH (SELECT CAST(qi, 'Array(Float32)') FROM t_qbit_default_transposed WHERE id = 0) AS r | ||
| SELECT id, round(cosineDistanceTransposedQuantized(qi, r, 8, 4), 4) FROM t_qbit_default_transposed ORDER BY id; |
There was a problem hiding this comment.
This regression only checks the final result, but the failure being fixed only happens after DistanceTransposedPartialReadsPass rewrites qb / qi into subcolumn reads. A plain full-column read already recomputes the DEFAULT correctly (the block above proves that), so this stays green if a later change disables the rewrite for unmaterialized QBit columns, or if the query runs under an old-analyzer profile. Please force the analyzer/optimized path here and assert that the plan actually reads qb.N / qi.N (similar to 03375, 04489, 04491), otherwise the test does not prove the broken path is fixed.
|
On the Summary: it recurs on I could not build a deterministic local reproducer (it needs the exact granule-boundary tie under stress data/scheduling), so per the no-speculative-change policy I am not opening a fix PR. The fix belongs in the virtual-row optimization: truncate the remembered/checked boundary to the sort-column prefix the virtual row actually populates from the index. |
|
The |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
cosineDistanceTransposedandcosineDistanceTransposedQuantizedrewrite theirQBitargument into a read of individual bit-plane subcolumns (qb.1,qb.2, ...) viaDistanceTransposedPartialReadsPass, instead of reading the wholeQBitcolumn. When theQBitcolumn is not yet physically materialized in a part — e.g. right afterALTER TABLE ... ADD COLUMN qb QBit(...) DEFAULT ..., or while aMATERIALIZE COLUMNmutation for it is still running — a plain read of the column correctly recomputes theDEFAULTon the fly, but the subcolumn-rewritten transposed read did not, and instead fed an empty array into the implicitQBitcast:The root cause is in
injectRequiredColumnsRecursively(src/Storages/MergeTree/MergeTreeBlockReadUtils.cpp): when a requested column is missing from the part, it looks up the column'sDEFAULTexpression to determine which real columns must be read to recompute it. For a subcolumn request such asqb.1, it looked up theDEFAULTusing that raw subcolumn name — butColumnsDescription::getDefaultonly indexes top-level column names, so the lookup silently failed, and theDEFAULT's actual dependency (vinqb DEFAULT CAST(v, 'Array(BFloat16)')) was never injected into the set of physically-read columns.IMergeTreeReader::evaluateMissingDefaultsthen had no data forvand fell back to the type's placeholder default (an empty array), which failsQBit's strict per-vector size check.The fix resolves the column to its top-level storage name before the
DEFAULTlookup, matching what the plain (non-subcolumn) read path already does. A regression test reproduces the bug deterministically by stopping merges on a table right afterADD COLUMN qb QBit(...) DEFAULT ..., so the column stays permanently un-materialized in the existing part.Closes: #110634
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
cosineDistanceTransposedandcosineDistanceTransposedQuantizedthrowingCode: 190. SIZES_OF_ARRAYS_DONT_MATCH(Array arguments must have size N for QBit conversion, got 0) when theirQBitcolumn argument has aDEFAULTexpression and is not yet physically materialized in a part, e.g. right afterADD COLUMN ... DEFAULT ...or while aMATERIALIZE COLUMNmutation for it is still in progress.