Mryange opened a new pull request, #71340:
URL: https://github.com/apache/doris/pull/71340

   ### Background
   
   Doris uses column hashes for condition cache literal digests and for array 
keys in `multi_distinct_count`. These hashes must retain the structure of the 
value, including NULL positions and the boundaries of nested containers.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #71143 (scalar NULL digest handling)
   PR Type: Bugfix
   
   Problem Summary:
   
   `[7, NULL]`, `[NULL, 7]`, and `[0, 7]` can produce the same hash. Different 
nested Array or Map boundaries can also produce identical hash inputs. These 
collisions can cause condition cache entries to be reused for a different 
predicate or array values to be counted as one. Encode the NULL positions and 
container sizes in the existing column hash methods.
   
   ### Details
   
   - **Frequency:** The hash collisions are deterministic for the reproduced 
inputs. An incorrect condition cache result also requires a hit on an earlier 
predicate's entry.
   - **Root cause:** Nullable range hashing folds NULL values into the seed 
before non-NULL values without recording their positions. Non-empty Arrays and 
Maps omit their element or pair counts from the hash.
   - **Why existing tests missed it:** The previous digest tests covered scalar 
NULL and simple containers. The condition cache regression coverage did not 
compare predicates that differ only in nested NULL positions or container 
boundaries. The new column and expression unit tests target these cases.
   - **Fix:** Include each NULL's one-based position within its range and the 
size of each Array and Map. The nested columns are still hashed in batches.
   - **Other paths and branches:** Ordinary `COUNT(DISTINCT array_col)` is 
rejected during analysis. The window form can be rewritten to 
`multi_distinct_count`, but each window partition is computed by one BE from 
input rows, without merging partial hash sets across BEs. An explicit 
distributed `multi_distinct_count(ARRAY)` or a merge of persisted aggregate 
states can combine keys generated by different versions and overcount. This PR 
changes the column hash directly and does not translate existing aggregate 
keys. Affected release branches have not been established.
   
   - **Behavior change:** Condition cache literals and array distinct counts 
use the corrected column hashes. Previously stored array distinct keys keep 
their original values.
   
   ### Testing
   
   The focused ASAN BEUT run on commit `064601d89fe` passed all 13 tests across 
four suites, including the three new direct column tests and all 
`VLiteralDigestTest` cases. Baseline SQL and EXPLAIN confirmed the grouped and 
window behavior above. The mixed-version key mismatch was verified by source 
review and independent XXH3 calculation. A mixed-version cluster was not run. 
Formatting, diff, and build hygiene checks passed. The supplementary full-file 
clang-tidy run was not completed.
   
   ### Release note
   
   Fix deterministic hash collisions caused by NULL positions and nested Array 
or Map boundaries.
   
   ### Check List (For Author)
   
   - Behavior changed: Yes (see Details).
   - Does this need documentation: No.
   - Pre-submission status: Partially verified: mixed-version execution was not 
tested and full-file clang-tidy was not completed.
   
   ### AI Disclosure
   
   - Tool: Codex and Astra.
   - Generated: Implementation, tests, PR draft, and independent source review.
   - Human review: The author reviewed the column hashing changes before the 
additional unit tests were added.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to