eldenmoon commented on PR #65561:
URL: https://github.com/apache/doris/pull/65561#issuecomment-5032371662

   再梳理了一遍 `cast/variant_v2`,整体判断是:**批量分组(`ScalarGroups`)、不同 decimal scale 
分组、ARRAY 递归 plan 这些有正确性和向量化性能价值,建议保留;当前主要的过度设计是为了复用接口引入了多次中间列、全量复制和重复编码。** 
建议按下面优先级精简:
   
   1. **P0:encoded Variant -> scalar 存在每行一次 `DataType` 堆分配。**  
      `cast_variant_to_scalar.cpp` 的 
`append_bool/int/float/double/decimal/date/timestamp/string` 都以 
`initialize_group(..., std::make_shared<DataType...>())` 调用。函数参数会先求值,所以 group 
已初始化后仍会每行执行 `make_shared`。应改成 lazy factory,只在 group 第一次创建时构造 type。
   
   2. **P0:scalar -> Variant 不必要地深拷贝源列。**  
      `cast_scalar_to_variant()` 中的 `IColumn::mutate(source)` 在 Block 仍持有 
source 时会触发 COW clone,抵消 typed Variant 本应提供的低成本包装。建议 typed state 共享原 nested 
column,真正发生写操作时再 detach;现有 `EXPECT_NE(..., source_identity)` 只是实现细节,不应作为契约。
   
   3. **P0:ARRAY -> Variant 存在“先编码、再解析、再编码”。**  
      scalar/typed leaf 当前经过 `cast_scalar_to_variant -> clone_as_encoded -> 
get_value_ref -> Row::add_value`。而 `Row::add_value` 会递归校验、导入并重新编码,不是简单 
memcpy。建议 typed dispatch 后直接把 `VariantScalarEncodingPlan` 写入 builder。已经是 
encoded Variant 的 leaf 也不应 clone,只读引用即可。
   
   4. **P0:Variant -> ARRAY<String/JSONB> 有无意义的中间 `ColumnVariantV2`。**  
      当前是 `VariantRef -> encoded_refs() -> 新 ColumnVariantV2 -> 再 cast 
String/JSONB`。这两个目标都可以直接消费 `span<VariantRef>`,建议删除该中间编码。
   
   5. **P1:top-level encoded Variant -> scalar 先构造整列 
`DorisVector<VariantRef>`,随后又逐行分类。**  
      可以直接遍历 source 写入 `ScalarGroups`,去掉 O(rows) 临时数组。分组本身保留,同时增加单 group 
且顺序未变化时直接返回的 fast path,避免 concatenate + full permutation。
   
   6. **P1:typed Variant -> String/JSONB 目前先 `clone_as_encoded()` 整列物化。**  
      SerDe 已有 typed row visitor + scalar scratch 的实现,建议抽成公共内部 visitor 复用,避免完整 
encoded column。String 路径还可以针对 all-concrete / all-fallback 直接返回,避免再次拼接和 permute。
   
   7. **P2:ARRAY 每一层都会复制 effective null map。**  
      只有 local nulls 或 inherited nulls 时可直接保存 span;仅在两者需要合并且确实存在 null 时分配 owned 
buffer。隐藏在 null array 下的非法值屏蔽逻辑仍需保留,这是正确性要求。
   
   另外,cast wrapper 顶层的 `catch (const Exception&)` 与 Column 中只做回滚的 `catch (...)` 
不同:这里负责把异常转换为 `Status`,建议保留。
   
   当前 cast UT 主要覆盖正确性,没有 RELEASE benchmark 或 allocation 
约束。上述复杂结构如果以性能为理由保留,建议至少补 homogeneous scalar、mixed scalar、typed -> 
String/JSONB、nested ARRAY round-trip 四组 benchmark。


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