-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-6942] Support decorrelated for sub-queries with LIMIT 1 and OFFSET #4633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
3cf367f to
a463a62
Compare
46e621a to
ce662e7
Compare
ce662e7 to
2fca43a
Compare
|
|
||
| !ok | ||
|
|
||
| select * from emp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5159fd0 to
5ec06f2
Compare
| Frame aggFrame = decorrelateSortAsAggregate(sort, frame); | ||
| if (aggFrame != null) { | ||
| return aggFrame; | ||
| if (sort.offset == null |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
core/src/main/java/org/apache/calcite/sql2rel/RelDecorrelator.java
Outdated
Show resolved
Hide resolved
3ea095e to
c314d24
Compare
mihaibudiu
left a comment
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 ..."
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks
bfde556
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
bfde556 to
b7dcb67
Compare
|
Can I squash these commits to facilitate merging? |
mihaibudiu
left a comment
There was a problem hiding this 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.
b7dcb67 to
8168d98
Compare
|
Sorry, but the branch has developed a conflict, please fix and rebase so we can merge |
8168d98 to
28068af
Compare
|
Done |



CALCITE-6942