[fix](aggregate) Normalize projected count slots before null safety checks - #67732
Open
morrySnow wants to merge 1 commit into
Open
[fix](aggregate) Normalize projected count slots before null safety checks#67732morrySnow wants to merge 1 commit into
morrySnow wants to merge 1 commit into
Conversation
The count-on-index implementation rule checked filter safety using the aggregate's projected slot IDs. A filter below the project uses source slot IDs, so an IS NULL predicate on a counted alias could be missed. Resolve aggregate arguments through the project before applying the existing predicate checks. This keeps the checks and filters in the same slot-ID domain and prevents an unsafe storage-layer count pushdown. Issue Number: None Tests: - PhysicalStorageLayerAggregateTest - sandbox SQL reproduction with nullable indexed data and a subquery alias
morrySnow
requested review from
924060929,
englefly and
starocean999
as code owners
September 9, 2026 10:05
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
TPC-H: Total hot run time: 16935 ms |
Contributor
TPC-DS: Total hot run time: 82745 ms |
Contributor
ClickBench: Total hot run time: 14.84 s |
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.
Problem
Counting a projected alias over a nullable indexed column can return an incorrect non-zero result when the filter retains only null rows. Mixing the alias count with
COUNT(*)or another count exposes the problem:For two matching null rows, the correct result is
(0, 2), but the storage-layer index-count path can return(2, 2).Root cause
The FE implementation rule validates
IS NULLand OR predicates before pushing count aggregation to the storage layer. In the Project variant, this validation used the aggregate-side alias slot, while the filter below the Project refers to the source slot. Their expression IDs differ, so the null-safety guard did not recognize that the filter andCOUNTreferenced the same nullable value.The rule normalized the aggregate argument to the source slot only later, after the safety decision had already been made.
Reproduction
Before this change, both queries return
(2, 2)and the plan containspushAggOp=COUNT_ON_INDEX. Both queries should return(0, 2).Fix
Normalize aggregate arguments through the Project before collecting the slots used by the predicate safety checks. The count slots and filter slots are now compared in the same source expression-ID domain. If
IS NULLtargets a counted source slot, the FE rejects the index-count pushdown and preserves the column's null values.This change is limited to the FE planner.
Tests
COUNT(projected_alias) + COUNT(*)above anIS NULLfilter, verifying that the count-on-index implementation rule is rejected.PhysicalStorageLayerAggregateTest: 7 tests passed.(0, 2), and the scan plan reportspushAggOp=NONE.