Skip to content

branch-4.0:[fix](mtmv) Avoid invalid slot cast in MV null-reject compensation (#66613) - #67255

Open
seawinde wants to merge 1 commit into
apache:branch-4.0from
seawinde:pr_66613_to_branch-4.0
Open

branch-4.0:[fix](mtmv) Avoid invalid slot cast in MV null-reject compensation (#66613)#67255
seawinde wants to merge 1 commit into
apache:branch-4.0from
seawinde:pr_66613_to_branch-4.0

Conversation

@seawinde

Copy link
Copy Markdown
Member

pr: #66613
commitId: 7128b3e

…pache#66613)
Related PR: apache#43539, apache#62492, apache#63268
Problem Summary:
When an INNER JOIN query is matched against a LEFT OUTER JOIN
materialized
view, the rewrite must prove that the nullable side is null-rejected.
The MV
rule shuttles the nullable-side output Slots through the view plan
lineage to
normalize Project and Alias outputs before selecting an `IS NOT NULL`
compensation Slot.
**Root cause:**
`AbstractMaterializedViewRule.getShuttledRequireNoNullableViewSlots()`
assumed that `ExpressionUtils.shuttleExpressionWithLineage()` always returns
`Slot` values and unconditionally used `Slot.class::cast`. The API returns
general `Expression` values. Expression JOIN keys such as CAST equality can
introduce helper projections whose lineage expands to `Cast`, causing a
`ClassCastException` during MV rewrite. The unsafe assumption was introduced
by apache#43539. PR apache#62492 added INNER JoinEdge null-reject inference, and apache#63268
materialized that evidence as compensation, making this path more readily reachable.
**Current limitation:** This is a conservative crash fix, not transparent
rewrite support for CAST or arbitrary derived expressions. If no usable Slot
remains after lineage expansion, the existing proof checks return invalid and
the MV rewrite safely falls back to base tables. The CAST JOIN case covered by
the test therefore still does not use the MV. Using an expression's input Slots
as compensation evidence is not generally sound because functions and casts
can change nullability semantics; supporting such expressions requires an
explicit nullability-preserving proof.
Fixed an internal `ClassCastException` during materialized view rewrite for
expression-based join keys. Unsupported derived-expression lineage now falls
back safely.
@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?

@seawinde

Copy link
Copy Markdown
MemberAuthor

run buildall

Sign up for freeto 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.

2 participants

@seawinde@hello-stephen