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 451e2991515 [Opt](performance) Optimize timeround with minute / second (#25073) 451e2991515 is described below commit 451e29915155ba6465576ae36ae68869217402a0 Author: Mryange <59914473+mrya...@users.noreply.github.com> AuthorDate: Sun Oct 8 23:14:23 2023 +0800 [Opt](performance) Optimize timeround with minute / second (#25073) --- .../vec/functions/function_datetime_floor_ceil.cpp | 49 ++++++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/be/src/vec/functions/function_datetime_floor_ceil.cpp b/be/src/vec/functions/function_datetime_floor_ceil.cpp index 6ef3bfce5c0..6cdfd01083d 100644 --- a/be/src/vec/functions/function_datetime_floor_ceil.cpp +++ b/be/src/vec/functions/function_datetime_floor_ceil.cpp @@ -524,13 +524,21 @@ template <typename Impl, typename DateValueType> struct TimeRoundOpt { constexpr static bool can_use_optimize(int period) { if constexpr (!std::is_same_v<DateValueType, VecDateTimeValue> && Impl::Type == FLOOR) { - if constexpr (Impl::Unit == YEAR || Impl::Unit == MONTH || Impl::Unit == DAY || - Impl::Unit == MINUTE || Impl::Unit == SECOND) { + if constexpr (Impl::Unit == YEAR || Impl::Unit == DAY) { return period == 1; } + if constexpr (Impl::Unit == MONTH) { + return period <= 11 && 12 % period == 0; + } if constexpr (Impl::Unit == HOUR) { return period <= 23 && 24 % period == 0; } + if constexpr (Impl::Unit == MINUTE) { + return period <= 59 && 60 % period == 0; + } + if constexpr (Impl::Unit == SECOND) { + return period <= 59 && 60 % period == 0; + } } return false; } @@ -541,9 +549,21 @@ struct TimeRoundOpt { } else { static constexpr uint64_t MASK_HOUR_FLOOR = 0b1111111111111111111111111111111100000000000000000000000000000000; - + static constexpr uint64_t MASK_MINUTE_FLOOR = + 0b1111111111111111111111111111111111111100000000000000000000000000; + static constexpr uint64_t MASK_SECOND_FLOOR = + 0b1111111111111111111111111111111111111111111100000000000000000000; // Optimize the performance of the datetimev2 type on the floor operation. - // Now supports unit hour + // Now supports unit month hour minute seconde + if constexpr (Impl::Unit == MONTH && !std::is_same_v<DateValueType, VecDateTimeValue>) { + int month = ts2.month() - 1; + int new_month = month / period * period; + if (new_month >= 12) { + new_month = new_month % 12; + } + ts1.set_time(ts2.year(), ts2.month(), 1, 0, 0, 0); + ts1.template set_time_unit<TimeUnit::MONTH>(new_month + 1); + } if constexpr (Impl::Unit == HOUR && !std::is_same_v<DateValueType, VecDateTimeValue>) { int hour = ts2.hour(); int new_hour = hour / period * period; @@ -553,6 +573,26 @@ struct TimeRoundOpt { ts1.set_int_val(ts2.to_date_int_val() & MASK_HOUR_FLOOR); ts1.template set_time_unit<TimeUnit::HOUR>(new_hour); } + if constexpr (Impl::Unit == MINUTE && + !std::is_same_v<DateValueType, VecDateTimeValue>) { + int minute = ts2.minute(); + int new_minute = minute / period * period; + if (new_minute >= 60) { + new_minute = new_minute % 60; + } + ts1.set_int_val(ts2.to_date_int_val() & MASK_MINUTE_FLOOR); + ts1.template set_time_unit<TimeUnit::MINUTE>(new_minute); + } + if constexpr (Impl::Unit == SECOND && + !std::is_same_v<DateValueType, VecDateTimeValue>) { + int second = ts2.second(); + int new_second = second / period * period; + if (new_second >= 60) { + new_second = new_second % 60; + } + ts1.set_int_val(ts2.to_date_int_val() & MASK_SECOND_FLOOR); + ts1.template set_time_unit<TimeUnit::SECOND>(new_second); + } } } @@ -567,6 +607,7 @@ struct TimeRoundOpt { ts1.set_time(ts2.year(), ts2.month(), ts2.day(), 0, 0, 0); } + // only DateTimeV2ValueType type have hour minute second if constexpr (std::is_same_v<DateValueType, DateV2Value<DateTimeV2ValueType>>) { static constexpr uint64_t MASK_HOUR_FLOOR = 0b1111111111111111111111111111111100000000000000000000000000000000; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org