Skip to content

[CALCITE-7587] RelDecorrelator fails on correlated scalar subquery with ROW_NUMBER window function due to RexOver nullability mismatch#4998

Merged
iwanttobepowerful merged 1 commit into
apache:mainfrom
iwanttobepowerful:CALCITE-7587
Jun 13, 2026
Merged

Conversation

@iwanttobepowerful

Copy link
Copy Markdown
Contributor

# Correlated scalar sub-query in the SELECT list that contains a window function.
# Decorrelation must add the correlation key to the window partition and preserve nullability
# of the OVER expression after pulling it above the left correlate.
SELECT e.ename,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mihaibudiu

Copy link
Copy Markdown
Contributor

This looks fine, but I my knowledge of the decorrelation algorithms is rather superficial, so if @suibianwanwank can weigh in we can be more confident.

Comment thread core/src/test/resources/sql/sub-query.iq Outdated
@Override public RexNode visitOver(RexOver over) {
// Collect correlation fields that are referenced directly by the window
// expression. They need to be added to the window partition keys so that
// decorrelation does not widen the window computation scope.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you show here a plan fragment before and after the rewrite?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great

@iwanttobepowerful iwanttobepowerful force-pushed the CALCITE-7587 branch 2 times, most recently from 0f597e5 to 6c35e62 Compare June 12, 2026 06:16
…th ROW_NUMBER window function due to RexOver nullability mismatch
@sonarqubecloud

Copy link
Copy Markdown

@mihaibudiu mihaibudiu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to merge it

@iwanttobepowerful iwanttobepowerful merged commit c91b6f4 into apache:main Jun 13, 2026
19 checks passed
Sign up for free to 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