Baymine opened a new pull request, #66644:
URL: https://github.com/apache/doris/pull/66644
…egate
### What problem does this PR solve?
Issue Number: close #<TBD>
Problem Summary: The Nullable wrapper for window/analytic aggregate
functions called ColumnNullable::has_null() over the ENTIRE buffered column on
every row in AggregateFunctionNullUnaryInline::add_range_single_place and
::execute_function_with_incremental. For an analytic sliding window this makes
the per-row null check O(n) and the whole scan O(n * buffer), even when nulls
are sparse or absent. This narrows the scan to only the frame range that is
actually touched: [current_frame_start, current_frame_end) for
add_range_single_place, and [frame_start-1, current_frame_end) for the
incremental path (covering the outgoing frame_start-1 and incoming frame_end-1
boundary positions). Result is correct and unchanged; the per-row check drops
from O(n) to O(frame).
### Release note
None
### Check List (For Author)
- Test: Unit Test (be/test/exprs/aggregate/agg_function_null_window_test.cpp)
- Behavior changed: No
- Does this need documentation: No
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [x] Unit Test
- [x] Manual test (add detailed scripts or steps below)
```bash
# Step 1 — build no-null tables of increasing size (nullable type, all
values non-null)
for N in 2000000 4000000 8000000; do
mysql -h127.0.0.1 -P9030 -uroot -e "
DROP TABLE IF EXISTS d4_repro.nn_$N;
CREATE TABLE d4_repro.nn_$N (
vender_id INT, monitor_day INT, roll_diff_amount DOUBLE NULL
) DUPLICATE KEY(vender_id)
DISTRIBUTED BY HASH(vender_id) BUCKETS 8
PROPERTIES('replication_num'='1');
INSERT INTO d4_repro.nn_$N
SELECT cast(number % 400000 AS int), -- ~400k partitions (small
partitions, matches prod)
cast(number % 30 AS int),
cast(number % 100000 AS double) -- NEVER null
FROM numbers('number'='$N');"
done
# Step 2 — time the window query single-threaded; per-row = wall / N
for N in 2000000 4000000 8000000; do
Q="SELECT count(a+s) FROM (
SELECT vender_id,
avg(roll_diff_amount) OVER (PARTITION BY vender_id ORDER BY
monitor_day
ROWS BETWEEN 7 PRECEDING AND 1
PRECEDING) a,
stddev(roll_diff_amount) OVER (PARTITION BY vender_id ORDER BY
monitor_day
ROWS BETWEEN 7 PRECEDING AND 1
PRECEDING) s
FROM d4_repro.nn_$N) t"
start=$(date +%s.%N)
mysql -h127.0.0.1 -P9030 -uroot -e "set parallel_pipeline_task_num=1;
${Q}" >/dev/null 2>&1
end=$(date +%s.%N)
el=$(echo "$end - $start" | bc)
perrow=$(echo "scale=3; $el * 1000000 / $N" | bc)
echo "N=$N wall=${el}s per-row=${perrow}us"
done
```
Evaluation Results(single-thread, no NULLs)
| N | before fix | after fix | speedup |
|---|---|---|---|
| 2,000,000 | 16.05 µs/row (32.1 s) | 0.39 µs/row (0.78 s) | ~41x |
| 4,000,000 | 17.51 µs/row (70.0 s) | 0.35 µs/row (1.40 s) | ~50x |
| 8,000,000 | **>120 s (timeout)** | 0.32 µs/row (2.56 s) | ~50x+ |
- [ ] 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:
https://github.com/apache/doris-website/pull/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 -->
### APPENDIX
flame graph in our prod env:
<img width="1915" height="906" alt="image"
src="https://github.com/user-attachments/assets/4bf2096c-e483-4e6a-ad90-9050faa064b3"
/>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]