This is an automated email from the ASF dual-hosted git repository.

panxiaolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 516d27bf6bf [Improvement](function) optimize case_when<then_null> 
branch (#51132)
516d27bf6bf is described below

commit 516d27bf6bfcfa890a9846505132b3faef2ba82a
Author: Pxl <x...@selectdb.com>
AuthorDate: Fri May 23 13:53:44 2025 +0800

    [Improvement](function) optimize case_when<then_null> branch (#51132)
    
    
    optimize case_when<then_null> branch
    
    ```sql
    select    count(isnull(x))    from    (select    case    i1    when    -128 
   then    -128    when    -127    then    -127    when    -126    then    -126 
   when    -125    then    -125    when    -124    then    -124    when    -123 
   then    -123    when    -122    then    -122    when    -121    then    -121 
   when    -120    then    -120    when    -119    then    -119    when    -118 
   then    -118    when    -117    then    -117    when    -116    then    -116 
   when    -1 [...]
    before:1sec788ms
    after:648ms
    ```
---
 be/src/vec/functions/function_case.h | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/be/src/vec/functions/function_case.h 
b/be/src/vec/functions/function_case.h
index d7521552d0b..c1a18c83414 100644
--- a/be/src/vec/functions/function_case.h
+++ b/be/src/vec/functions/function_case.h
@@ -217,11 +217,24 @@ public:
                 }
             } else {
                 if constexpr (when_null) {
-                    // TODO: need simd
+                    const auto* column_nullable_ptr =
+                            assert_cast<const 
ColumnNullable*>(when_column_ptr.get());
+                    const auto* __restrict cond_raw_data =
+                            assert_cast<const ColumnUInt8*>(
+                                    
column_nullable_ptr->get_nested_column_ptr().get())
+                                    ->get_data()
+                                    .data();
+                    const auto* __restrict cond_raw_nullmap =
+                            assert_cast<const ColumnUInt8*>(
+                                    
column_nullable_ptr->get_null_map_column_ptr().get())
+                                    ->get_data()
+                                    .data();
+
+                    // simd automatically
                     for (int row_idx = 0; row_idx < rows_count; row_idx++) {
-                        if (!then_idx_ptr[row_idx] && 
when_column_ptr->get_bool(row_idx)) {
-                            then_idx_ptr[row_idx] = i;
-                        }
+                        then_idx_ptr[row_idx] |= (!then_idx_ptr[row_idx] * 
cond_raw_data[row_idx] *
+                                                  !cond_raw_nullmap[row_idx]) *
+                                                 i;
                     }
                 } else {
                     const auto* __restrict cond_raw_data =


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to