Mryange opened a new pull request, #62047:
URL: https://github.com/apache/doris/pull/62047

   ### What problem does this PR solve?
   
   `aggregate_function_reader_replace.cpp` took **86.91s** to compile because 
it included `aggregate_function_reader_first_last.h`, which pulled in heavy 
template machinery: a 28-case column-type switch × 4 bool combinations × 4 
factory functions = ~448 `make_shared<ReaderFunctionData<...>>` instantiations 
in a single TU.
   
   ### How is it solved?
   
   1. **Decouple from `aggregate_function_reader_first_last.h`**: The 
reader/load path now has a self-contained, lightweight implementation directly 
in the `.cpp` file. The shared header is no longer included.
   
   2. **Introduce `PointerStore<ArgIsNullable>` / `CopyStore<ArgIsNullable>`**: 
Two small storage classes with a uniform interface (`is_null`, 
`set_value<SkipNull>`, `insert_into`, `reset`). Reader path uses zero-copy 
`PointerStore`; load path uses `CopyStore` with `Field` deep-copy.
   
   3. **Use 3 bool template params `<IsFirst, SkipNull, ArgIsNullable>`**: 
`IsCopy` is derived as `!IsFirst`. `ArgIsNullable` is resolved at registration 
time (nullable vs non-nullable factory map), eliminating runtime branches. 
`result_is_nullable` stays as a runtime bool (called once per group).
   
   4. **All column operations use `IColumn` virtual dispatch**: No 
column-type-specific template instantiations. Performance impact is negligible 
— `Field` operations and the `add()` virtual call itself dominate.
   
   5. **Clean up `aggregate_function_reader_first_last.h`**: Removed 
`ReaderFunctionFirstData`, `ReaderFunctionLastData`, 
`ReaderFunctionFirstNonNullData`, `ReaderFunctionLastNonNullData`, 
`ReaderFunctionData`, `create_function_single_value`, the 28-case switch, and 
the `CREATE_READER_FUNCTION_WITH_NAME_AND_DATA` macro — all now unused. Also 
removed unnecessary includes (`column_array.h`, `column_map.h`, etc.).
   
   ### Compile time
   
   | Stage | Time |
   |-------|------|
   | Before | 86.91s |
   | After | **17.0s (↓80%)** |
   
   ### 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: 
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 -->
   
   


-- 
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]

Reply via email to