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

lihaopeng 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 9e7e33cb05d [opt](vec) opt the date/datetime is invalid func 
performance (#41986)
9e7e33cb05d is described below

commit 9e7e33cb05dacff08e78754988203e7a8bc19815
Author: HappenLee <happen...@selectdb.com>
AuthorDate: Tue Jan 7 10:46:41 2025 +0800

    [opt](vec) opt the date/datetime is invalid func performance (#41986)
    
    ## Proposed changes
    
    before : cost 40s
    ```
    select count(month(d1)) from tb1;
    ```
    
    
    after : cost 28s
    ```
    select count(month(d1)) from tb1;
    ```
---
 be/src/util/time_lut.cpp                    |  4 ----
 be/src/util/time_lut.h                      |  4 +++-
 be/src/vec/functions/date_time_transforms.h |  3 +++
 be/src/vec/runtime/vdatetime_value.cpp      | 22 ----------------------
 be/src/vec/runtime/vdatetime_value.h        | 14 +++++++++++++-
 5 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/be/src/util/time_lut.cpp b/be/src/util/time_lut.cpp
index 616541d411f..cb2aecb7289 100644
--- a/be/src/util/time_lut.cpp
+++ b/be/src/util/time_lut.cpp
@@ -87,10 +87,6 @@ uint32_t calc_days_in_year(uint32_t year) {
     return is_leap(year) ? 366 : 365;
 }
 
-bool is_leap(uint32_t year) {
-    return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 && 
year));
-}
-
 uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day) {
     return (day_nr + 5L + (is_sunday_first_day ? 1L : 0L)) % 7;
 }
diff --git a/be/src/util/time_lut.h b/be/src/util/time_lut.h
index 3955d8c8ed7..f98560c45e1 100644
--- a/be/src/util/time_lut.h
+++ b/be/src/util/time_lut.h
@@ -36,7 +36,9 @@ uint32_t calc_daynr(uint16_t year, uint8_t month, uint8_t 
day);
 
 uint8_t calc_weekday(uint64_t day_nr, bool is_sunday_first_day);
 
-bool is_leap(uint32_t year);
+inline bool is_leap(uint32_t year) {
+    return ((year % 4) == 0) && ((year % 100 != 0) || ((year % 400) == 0 && 
year));
+}
 
 uint32_t calc_days_in_year(uint32_t year);
 
diff --git a/be/src/vec/functions/date_time_transforms.h 
b/be/src/vec/functions/date_time_transforms.h
index b65840445ca..301effe80e0 100644
--- a/be/src/vec/functions/date_time_transforms.h
+++ b/be/src/vec/functions/date_time_transforms.h
@@ -353,6 +353,9 @@ struct Transformer {
             auto res = Transform::execute(vec_from[i]);
             using RESULT_TYPE = std::decay_t<decltype(res)>;
             vec_to[i] = cast_set<ToType, RESULT_TYPE, false>(res);
+        }
+
+        for (size_t i = 0; i < size; ++i) {
             null_map[i] = !((typename DateTraits<typename 
Transform::OpArgType>::T&)(vec_from[i]))
                                    .is_valid_date();
         }
diff --git a/be/src/vec/runtime/vdatetime_value.cpp 
b/be/src/vec/runtime/vdatetime_value.cpp
index 026648319d4..8e053c93447 100644
--- a/be/src/vec/runtime/vdatetime_value.cpp
+++ b/be/src/vec/runtime/vdatetime_value.cpp
@@ -1936,28 +1936,6 @@ std::size_t hash_value(VecDateTimeValue const& value) {
     return HashUtil::hash(&value, sizeof(VecDateTimeValue), 0);
 }
 
-template <typename T>
-bool DateV2Value<T>::is_invalid(uint32_t year, uint32_t month, uint32_t day, 
uint8_t hour,
-                                uint8_t minute, uint8_t second, uint32_t 
microsecond,
-                                bool only_time_part) {
-    if (hour >= 24 || minute >= 60 || second >= 60 || microsecond > 999999) {
-        return true;
-    }
-    if (only_time_part) {
-        return false;
-    }
-    if (year > MAX_YEAR) {
-        return true;
-    }
-    if (month == 2 && day == 29 && doris::is_leap(year)) {
-        return false;
-    }
-    if (month == 0 || month > 12 || day > S_DAYS_IN_MONTH[month] || day == 0) {
-        return true;
-    }
-    return false;
-}
-
 template <typename T>
 void DateV2Value<T>::format_datetime(uint32_t* date_val, bool* carry_bits) 
const {
     // ms
diff --git a/be/src/vec/runtime/vdatetime_value.h 
b/be/src/vec/runtime/vdatetime_value.h
index cfe9a368e83..f724f918828 100644
--- a/be/src/vec/runtime/vdatetime_value.h
+++ b/be/src/vec/runtime/vdatetime_value.h
@@ -872,7 +872,19 @@ public:
     // Return true if range or date is invalid
     static bool is_invalid(uint32_t year, uint32_t month, uint32_t day, 
uint8_t hour,
                            uint8_t minute, uint8_t second, uint32_t 
microsecond,
-                           bool only_time_part = false);
+                           bool only_time_part = false) {
+        if constexpr (is_datetime) {
+            if (hour >= 24 || minute >= 60 || second >= 60 || microsecond > 
999999) {
+                return true;
+            }
+            if (only_time_part) {
+                return false;
+            }
+        }
+        return year > MAX_YEAR || !day || !month || month > 12 ||
+               (day > 28 && ((month != 2 && day > S_DAYS_IN_MONTH[month]) ||
+                             (month == 2 && day > 28 + doris::is_leap(year))));
+    }
 
     [[nodiscard]] bool check_range_and_set_time(uint16_t year, uint8_t month, 
uint8_t day,
                                                 uint8_t hour, uint8_t minute, 
uint8_t second,


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

Reply via email to