englefly opened a new pull request, #69857:
URL: https://github.com/apache/doris/pull/69857
### What problem does this PR solve?
Issue Number: None
Related PR: #69784 #69787
Problem Summary:
Constant propagation materializes a constant above the aggregate or the
project which defines a
column. The materialized item is a literal, which is always not-nullable,
while the column it
replaces may be nullable. The item kept the exprId of the column in every
case, so the rewritten
plan could contain two definitions of the same exprId with different
nullability: the not-nullable
literal above, and the nullable column of the subtree below. The plan stays
valid while a node still
separates them, but a later rule may remove that node, and AdjustNullable
then has to widen the
column on the way down; with \`fe_debug\` enabled the check aborts the query
with
\"AdjustNullable convert slot ... from not-nullable to nullable\", e.g. for
the two queries reported
in the issue.
The fix keeps the exprId only when the materialized constant does not change
the nullability of the
column, or when the child does not produce the column any more (then the
project item is the only
definition of the exprId). When the child still produces the column and the
constant has another
nullability, the constant gets a fresh exprId and the references above are
refreshed, so one exprId
keeps one definition.
Keeping the identity of the columns whose nullability does not change is
what the materialized view
matching relies on. Two companion changes keep the mv rewrite working when a
constant is renamed:
accept constant query outputs when matching a view, and align the outputs of
the view plan with the
final origin plan before it is copied into the memo.
### Release note
None
### Check List (For Author)
- Test: Manual test / Regression test
- Manual: the two reported queries are planned with \`fe_debug\`
enabled; without the fix both
abort with \"AdjustNullable convert slot ... from not-nullable to
nullable\", with the fix both
produce a plan
- Regression: the mv suites agg_optimize_when_uniform,
aggregate_with_roll_up,
aggregate_without_roll_up, pre_write_strategy on branch-4.2
- Behavior changed: No
- Does this need documentation: No
--
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]