yujun777 opened a new pull request, #71440: URL: https://github.com/apache/doris/pull/71440
### Background During incremental refresh of an aggregate IVM materialized view, `IvmAggDeltaHandler` computes signed per-group deltas and merges them into the MV's current state via a `RIGHT OUTER JOIN` (`mv_scan RIGHT OUTER JOIN delta`). When `ivm_use_full_keys` is disabled, the join previously matched only on `__DORIS_IVM_ROW_ID_COL__`. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Performance Problem Summary: When an aggregate IVM materialized view explicitly specifies `KEY`, `PARTITION BY`, or `DISTRIBUTED BY HASH` on business columns without enabling `ivm_use_full_keys`, those visible columns form the physical key prefix ahead of `__DORIS_IVM_ROW_ID_COL__`. Joining only on `__DORIS_IVM_ROW_ID_COL__` blocks Bucket Shuffle Join, dynamic partition pruning, and prefix/ZoneMap pruning on the MV scan. This PR adds redundant null-safe equality conjuncts for visible MV key, partition, and distribution columns that directly pass through a group key slot. ### Details - **Why it was slow:** For aggregate MVs partitioned or hash-distributed by business group keys, a `RIGHT OUTER JOIN` keyed solely on `__DORIS_IVM_ROW_ID_COL__` cannot align with the MV's bucket distribution (forcing a full shuffle of the MV), cannot push runtime filters onto the partition column, and lands runtime filters on the trailing hash column instead of the leading prefix keys. - **Optimization:** Record the normalized query root in `IvmDeltaRewriteState` and trace visible MV key/partition/distribution columns downward through projects above `LogicalAggregate` by `ExprId`. For every visible key column that is a direct passthrough or plain rename of a group key slot (with matching type and no expression/cast transformation), emit a redundant `NullSafeEqual` conjunct in `IvmAggDeltaHandler.buildApplyJoinConjuncts`, deduplicating against any `identityKeys` already added by `ivm_use_full_keys`. - **Results:** Plan-level optimization verified via FE unit tests; enables Bucket Shuffle Join, dynamic partition pruning, and prefix-key runtime filter pushdown on custom-keyed/partitioned/bucketed aggregate MVs without changing MV storage layout or default `row_id`-bucketed MVs. - **Applicability and cost:** Applies only to grouped aggregate IVM MVs whose visible key/partition/distribution columns directly pass through group keys. Columns produced by expressions/casts above the aggregate or with ambiguous names are safely skipped, leaving `__DORIS_IVM_ROW_ID_COL__` to guard correctness. Planning overhead is a single linear walk over projects above the aggregate. ### Testing - Ran FE unit tests: `IvmAggDeltaHandlerTest` (38 tests passed, including 4 new tests covering visible MV keys without `ivm_use_full_keys`, deduplication with `ivm_use_full_keys`, aliased same-named join group keys mapped by `ExprId`, and transformed group key expressions skipped safely). - Ran FE Checkstyle (`checkstyle:check` on `fe-core`): passed. - Full regression suite will run in CI. ### Release note Incremental refresh for aggregate IVM materialized views with explicit key, partition, or hash-distribution columns now includes those direct group-key columns in the apply join predicates, enabling Bucket Shuffle Join, dynamic partition pruning, and prefix-index pruning. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Ready -- 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]
