Skip to content

Conversation

@iwanttobepowerful
Copy link
Contributor

@iwanttobepowerful iwanttobepowerful commented Nov 14, 2025

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 90 days if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 15, 2025
@iwanttobepowerful iwanttobepowerful marked this pull request as ready for review December 16, 2025 05:13
@iwanttobepowerful iwanttobepowerful force-pushed the zwhtest branch 6 times, most recently from 46e621a to ce662e7 Compare December 16, 2025 09:07
@iwanttobepowerful iwanttobepowerful changed the title draft fix [CALCITE-6942] Support decorrelated for sub-queries with LIMIT 1 and OFFSET Dec 16, 2025

!ok

select * from emp
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@iwanttobepowerful iwanttobepowerful force-pushed the zwhtest branch 2 times, most recently from 5159fd0 to 5ec06f2 Compare December 16, 2025 11:15
Frame aggFrame = decorrelateSortAsAggregate(sort, frame);
if (aggFrame != null) {
return aggFrame;
if (sort.offset == null
Copy link
Contributor

Choose a reason for hiding this comment

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

the name of this function is no longer appropriate, but it is protected, so I am not sure you can change it.
you may need to create a new one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe need change to a better name

return aggFrame;
if (sort.offset == null
&& sort.fetch != null
&& RexLiteral.intValue(sort.fetch) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is 0 even allowed?
Also, intValue seems unsafe; there have been some bug fixes about this in the past.
BigInt is probably safest.

Copy link
Contributor Author

@iwanttobepowerful iwanttobepowerful Dec 17, 2025

Choose a reason for hiding this comment

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

The purpose of this if check is to skip the subsequent optimization process for limit 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BigInt is probably safest.

ok

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

I have approved, but I still have a couple of comments.

return null;
if (rel.offset == null
&& rel.fetch != null
&& RexLiteral.longValue(rel.fetch) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

long is probably safe -- I don't expect more than 2^64 elements in a collection very soon
bigInt would have been safest. See https://issues.apache.org/jira/browse/CALCITE-7181 and the associated PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I will submit the modifications later. Thank you for your review.
At that time, I referred to

&& RexLiteral.longValue(sort.fetch) == 0;

@mihaibudiu @xiedeyantu

Copy link
Member

Choose a reason for hiding this comment

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

I don‘t think it's ok, please refer to https://issues.apache.org/jira/browse/CALCITE-7181. @julianhyde provided a very clear explanation.

Copy link
Contributor

Choose a reason for hiding this comment

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

It won't be much harder to use BigInteger here, so why not build the perfect solution?

// - group by corVar1, covVar2, field1, field2
// - any_value(fields1), any_value(fields2) group by corVar1, covVar2
// Here we use the first.
protected @Nullable Frame decorrelateSortWithRowNumber(Sort sort, final Frame frame) {
Copy link
Contributor

Choose a reason for hiding this comment

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

My comment was that protected functions are part of the public API, so they cannot be modified (unless you change the major version). Perhaps the function should have been private?

I think it's safer to leave the function unchanged and add a new function.

Does the function have no other callers except this one? In that case you may need to add a description of a breaking change to the release notes: "Function RelDecorrelator.decorrelateFetchOneSort is no longer called by the decorrelator; instead consider using ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function should have been designed as private in the first place. It only has one caller.
@mihaibudiu @suibianwanwank

Copy link
Contributor

Choose a reason for hiding this comment

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

You can bite the bullet and change the function as private, and add this in the list of breaking changes in _docs/history.md. It has to be part of the same commit. The way I see this, it will be a breaking change if you preserve the original function and if you don't, so why not make it private now?

Copy link
Contributor Author

@iwanttobepowerful iwanttobepowerful Dec 18, 2025

Choose a reason for hiding this comment

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

OK, thanks
bfde556

Copy link
Contributor

Choose a reason for hiding this comment

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

Making this protected makes it easier for users to turn off the rewrite when they don’t want the plan to be transformed into row_number or min/max. That said, this might be over-engineering, and I’m fine either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is a legit reason to keep it protected, let's do it.
Then renaming it is still a breaking change, so let's document that.

@iwanttobepowerful iwanttobepowerful force-pushed the zwhtest branch 3 times, most recently from bfde556 to b7dcb67 Compare December 19, 2025 08:04
@iwanttobepowerful
Copy link
Contributor Author

Can I squash these commits to facilitate merging?
@mihaibudiu @suibianwanwank

Copy link
Contributor

@mihaibudiu mihaibudiu left a comment

Choose a reason for hiding this comment

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

If the other reviewers have no comments I propose to merge this.

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Dec 22, 2025
@mihaibudiu
Copy link
Contributor

Sorry, but the branch has developed a conflict, please fix and rebase so we can merge

@sonarqubecloud
Copy link

@iwanttobepowerful
Copy link
Contributor Author

Sorry, but the branch has developed a conflict, please fix and rebase so we can merge

Done

@mihaibudiu mihaibudiu merged commit 1e92bbe into apache:main Dec 24, 2025
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LGTM-will-merge-soon Overall PR looks OK. Only minor things left.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants