Skip to content

branch-4.1: [Opt](func) Improve AggFunc Percentile performance (#62520) - #65677

Merged
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-62520-branch-4.1
Jul 16, 2026
Merged

branch-4.1: [Opt](func) Improve AggFunc Percentile performance (#62520)#65677
yiguolei merged 1 commit into
apache:branch-4.1from
linrrzqqq:pick-62520-branch-4.1

Conversation

@linrrzqqq

Copy link
Copy Markdown
Collaborator

pick: #62520

- Reworked exact percentile state into a simpler `values +
PercentileLevels + inited_flag` layout.
- Removed the old Counts-based exact percentile path and replaced it
with a lightweight `PercentileLevels` metadata structure.
- Reduced add-path overhead by directly appending values into a
contiguous buffer and initializing `percentile levels` only once.
- Optimized multi-quantile finalize(`percentile_array`) by sorting
quantiles through permutation once, then reusing incremental
`nth_element` selection.

before:
```text
Doris> select percentile(FUniqID, 0.91) from hits_100m;
+---------------------------+
| percentile(FUniqID, 0.91) |
+---------------------------+
|     8.749975206154981e+18 |
+---------------------------+
1 row in set (6.149 sec)

Doris> select percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56]) from hits_100m;
+------------------------------------------------------------------------------------------------+
| percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56])                                      |
+------------------------------------------------------------------------------------------------+
| [0, 5.097819197233503e+18, 5.68906185719365e+18, 6.281280528073601e+18, 6.869583632113269e+18] |
+------------------------------------------------------------------------------------------------+
1 row in set (28.984 sec)

Doris> select percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56, 0.67, 0.78, 0.89, 0.91]) from hits_100m;
ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[E-3113]string column length is too large: total_length=7200000149, element_number=0, rows=0
```

now
```text
Doris> select percentile(FUniqID, 0.91) from hits_100m;
+---------------------------+
| percentile(FUniqID, 0.91) |
+---------------------------+
|     8.749975206154981e+18 |
+---------------------------+
1 row in set (2.107 sec)

Doris> select percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56]) from hits_100m;
+------------------------------------------------------------------------------------------------+
| percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56])                                      |
+------------------------------------------------------------------------------------------------+
| [0, 5.097819197233503e+18, 5.68906185719365e+18, 6.281280528073601e+18, 6.869583632113269e+18] |
+------------------------------------------------------------------------------------------------+
1 row in set (5.903 sec)

Doris> select percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56, 0.67, 0.78, 0.89, 0.91]) from hits_100m;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| percentile_array(FUniqID, [0.12, 0.23, 0.34, 0.45, 0.56, 0.67, 0.78, 0.89, 0.91])                                                                                                          |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| [0, 5.097819197233503e+18, 5.68906185719365e+18, 6.281280528073601e+18, 6.869583632113269e+18, 7.459044216605808e+18, 8.044902013692362e+18, 8.640523572825436e+18, 8.749975206154981e+18] |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (8.866 sec)
```
@linrrzqqq
linrrzqqq requested a review from yiguolei as a code owner July 15, 2026 16:09
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@linrrzqqq

Copy link
Copy Markdown
Collaborator Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 6.29% (19/302) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 54.94% (21098/38401)
Line Coverage 38.41% (202010/525949)
Region Coverage 34.79% (158573/455736)
Branch Coverage 35.81% (69301/193542)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 86.09% (260/302) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.09% (27806/37529)
Line Coverage 57.77% (302406/523488)
Region Coverage 55.30% (253771/458916)
Branch Coverage 56.70% (109901/193840)

@hello-stephen

Copy link
Copy Markdown
Contributor

FE Regression Coverage Report

Increment line coverage 100.00% (5/5) 🎉
Increment coverage report
Complete coverage report

@yiguolei
yiguolei merged commit eac094a into apache:branch-4.1 Jul 16, 2026
30 of 33 checks passed
@linrrzqqq
linrrzqqq deleted the pick-62520-branch-4.1 branch July 16, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants