HappenLee commented on code in PR #69296:
URL: https://github.com/apache/doris/pull/69296#discussion_r4348675533


##########
be/src/exprs/vcase_expr.cpp:
##########
@@ -39,17 +43,100 @@ class RuntimeState;
 
 namespace doris {
 
+namespace {
+
+template <PrimitiveType PType>
+constexpr bool supports_simple_case = is_number(PType) || PType == TYPE_STRING;
+
+template <PrimitiveType PType>
+constexpr size_t simple_case_lookup_threshold() {
+    static_assert(supports_simple_case<PType>);
+    if constexpr (sizeof(typename ColumnElementView<PType>::ElementType) <= 
sizeof(uint32_t)) {
+        return 64;
+    } else if constexpr (sizeof(typename 
ColumnElementView<PType>::ElementType) <=
+                         sizeof(uint64_t)) {
+        return 32;
+    } else {
+        return 8;
+    }
+}
+
+template <PrimitiveType PType>
+struct SimpleCaseLookupState {
+    using Key = typename ColumnElementView<PType>::ElementType;
+    using Hash = std::conditional_t<PType == TYPE_STRING, StringRefHash, 
phmap::Hash<Key>>;

Review Comment:
   [P2] Use a mixed whole-value hash for wide decimal keys
   
   This numeric hash alias selects `phmap::Hash<Key>`, which reaches 
`std::hash<Decimal128V3>`. The existing specialization in `core/types.h` XORs 
the hashes of the upper and lower 64-bit halves. Distinct, valid 
`DECIMAL(38,0)` keys `x_i = i * (2^64 + 1)` therefore all hash to zero: both 
halves equal `i`, so `hash(i) ^ hash(i) == 0`. For example, the first keys are 
`18446744073709551617`, `36893488147419103234` and `55340232221128654851`. The 
first 1024 keys fit comfortably in the type. The Decimal256 four-limb XOR 
admits the same pattern.
   
   A table-slot input of `DECIMAL(38,0)` and WHEN literals explicitly cast to 
that type satisfy the FE eligibility checks; eight or more branches select this 
new lookup path. These are distinct keys, so they cannot be eliminated as 
duplicate WHENs. All-colliding keys make table initialization quadratic in 
branch count and missed probes linear in branch count, undermining the intended 
matching speedup and adding expensive fragment-open work.
   
   Using the exact hasher formula and the repository's phmap container in an 
independent probe, 256 keys produced 65,536 equality calls during construction 
and 256 for one miss; 1024 keys produced 1,048,576 during construction and 1024 
for one miss. This probe counted operations; it did not run Doris SQL or 
measure end-to-end query latency.
   
   Please reuse a mixed whole-value decimal hash, such as the existing 
`HashCRC32<Decimal128V3>` / `HashCRC32<Decimal256>` implementations in 
`exec/common/hash_table/hash.h`, and include repeated-limb wide-decimal keys in 
collision/performance validation. This affects performance; the hash table 
still returns correct results.
   



-- 
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