branch-4.0: [Opt](function) opt of certain time field functions used in conjunction with FROM_UNIXTIME.#60843
Merged
yiguolei merged 2 commits intoapache:branch-4.0from Feb 26, 2026
Conversation
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
…on with FROM_UNIXTIME. (apache#57941) opt of certain time field functions(`HOUR`, `MINUTE`, `SECOND`, `MICROSECOND`) used in conjunction with `FROM_UNIXTIME` Take `HOUR(FROM_UNIXTIME(ts))` as an example: The `hour(from_unixtime(xxx))` function is slow because `from_unixtime`needs to extract the full yyyy-MM-dd HH:mm:ss format from the timestamp, which is not necessary. By calculating only the required fields directly from the timestamp, the process can be significantly faster. Add a function `hour_from_unixtime(ts)` to extract the hour from a unix timestamp, which is timezone aware. Implementation: 1. Lookup the timezone offset with cctz library 2. Calculate the hour from local unixtime ```cpp int64_t local_unixtime = unixtime + timezone.lookup_offset(unixtime); int hour = (local_unixtime % (24 * 3600)) / 3600 ``` Performance: Before VS After: ```text -- HOUR Doris> SELECT COUNT(HOUR(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +--------------------------------+ | COUNT(HOUR(FROM_UNIXTIME(ts))) | +--------------------------------+ | 100000000 | +--------------------------------+ 1 row in set (9.51 sec) Doris> SELECT COUNT(HOUR(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +--------------------------------+ | COUNT(HOUR(FROM_UNIXTIME(ts))) | +--------------------------------+ | 100000000 | +--------------------------------+ 1 row in set (0.96 sec) -- MINUTE Doris> SELECT COUNT(MINUTE(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +----------------------------------+ | COUNT(MINUTE(FROM_UNIXTIME(ts))) | +----------------------------------+ | 100000000 | +----------------------------------+ 1 row in set (10.98 sec) Doris> SELECT COUNT(MINUTE(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +----------------------------------+ | COUNT(MINUTE(FROM_UNIXTIME(ts))) | +----------------------------------+ | 100000000 | +----------------------------------+ 1 row in set (1.00 sec) -- SECOND Doris> SELECT COUNT(SECOND(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +----------------------------------+ | COUNT(SECOND(FROM_UNIXTIME(ts))) | +----------------------------------+ | 100000000 | +----------------------------------+ 1 row in set (10.01 sec) Doris> SELECT COUNT(SECOND(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +----------------------------------+ | COUNT(SECOND(FROM_UNIXTIME(ts))) | +----------------------------------+ | 100000000 | +----------------------------------+ 1 row in set (0.90 sec) -- MICROSECOND Doris> SELECT COUNT(MICROSECOND(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +---------------------------------------+ | COUNT(MICROSECOND(FROM_UNIXTIME(ts))) | +---------------------------------------+ | 100000000 | +---------------------------------------+ 1 row in set (9.75 sec) Doris> SELECT COUNT(MICROSECOND(FROM_UNIXTIME(ts))) FROM test_hour_from_unixtime; +---------------------------------------+ | COUNT(MICROSECOND(FROM_UNIXTIME(ts))) | +---------------------------------------+ | 100000000 | +---------------------------------------+ 1 row in set (1.24 sec) ```
…MAL(18, 6) (apache#60829) ### What problem does this PR solve? Issue Number: close #xxx Related PR: #xxx Problem Summary: ```sql mysql> SELECT MICROSECOND_FROM_UNIXTIME(1145.14); +------------------------------------+ | MICROSECOND_FROM_UNIXTIME(1145.14) | +------------------------------------+ | 140000 | +------------------------------------+ 1 row in set (0.02 sec) mysql> select @@debug_skip_fold_constant; +----------------------------+ | @@debug_skip_fold_constant | +----------------------------+ | 0 | +----------------------------+ 1 row in set (0.01 sec) mysql> set debug_skip_fold_constant=true; Query OK, 0 rows affected (0.02 sec) mysql> SELECT MICROSECOND_FROM_UNIXTIME(1145.14); ERROR 1105 (HY000): RpcException, msg: send fragments failed. io.grpc.StatusRuntimeException: UNAVAILABLE: Keepalive failed. The connection is likely gone, host: 10.16.10.3 ``` ```text F20260225 00:04:40.698660 618581 status.h:467] Bad cast from type:doris::vectorized::ColumnDecimal<(doris::PrimitiveType)28>* to doris::vectorized::ColumnDecimal<(doris::PrimitiveType)29> const* *** Check failure stack trace: *** @ 0x55dbc5c4dc4f google::LogMessage::SendToLog() @ 0x55dbc5c44260 google::LogMessage::Flush() @ 0x55dbc5c47959 google::LogMessageFatal::~LogMessageFatal() @ 0x55db8f09709b doris::Status::FatalError<>() @ 0x55dbb7936b66 _ZZ11assert_castIPKN5doris10vectorized13ColumnDecimalILNS0_13PrimitiveTypeE29EEEL18TypeCheckOnRelease1EPKNS1_7IColumnEET_OT1_ENKUlOSB_E_clISA_EES6_SE_ @ 0x55dbb7935f74 assert_cast<>() @ 0x55dbbcbf2f1f doris::vectorized::FunctionTimeFieldFromUnixtime<>::execute_impl() @ 0x55dbbcbf3762 doris::vectorized::FunctionTimeFieldFromUnixtime<>::execute_impl() @ 0x55dbba5ca2d8 doris::vectorized::PreparedFunctionImpl::_execute_skipped_constant_deal() @ 0x55dbba5ad094 doris::vectorized::PreparedFunctionImpl::default_implementation_for_constant_arguments() @ 0x55dbba5af1fd doris::vectorized::PreparedFunctionImpl::default_execute() @ 0x55dbba5af624 doris::vectorized::PreparedFunctionImpl::execute() ``` ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
9cb475b to
f482b62
Compare
Contributor
Author
|
run buildall |
Contributor
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
yiguolei
approved these changes
Feb 26, 2026
ybtsdst
pushed a commit
to ybtsdst/doris
that referenced
this pull request
Feb 27, 2026
…in conjunction with FROM_UNIXTIME. (apache#60843) pick: apache#57941 and apache#60829
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pick: #57941 and #60829