Skip to content
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

[release/6.0] Query: Match correct predicate structure to convert apply to join #27292

Merged
merged 1 commit into from
Feb 3, 2022

Conversation

smitpatel
Copy link
Member

@smitpatel smitpatel commented Jan 26, 2022

Resolves #26756

For property access on optional dependents sharing column with principal, we generate CaseExpression. In order to match them during join key search, we updated our recursive function to match shape of the test in CaseExpression which incorrectly matched similar structure outside of case block causing somewhat wrong join key to be extracted. While join key in itself could work, when generating partitions out of it due to paging operation, it gives incorrect results.

The fix is to match the special structure of CaseExpression. Test separately. Also made the key comparison match more robust by only allowing column or case block to appear in condition. Other structures don't represent part of join key in a comparison.
Null checks for join keys are handled separately so that we only remove null checks which are indeed used in comparison with other columns in other operations.

Description

When a correlated subquery which has paging applied to it is converted to join, we detect incorrect join predicate causing wrong partitions to be created for row number operation which gives wrong result.

Customer impact

Customers running query with affected scenarios can receive incorrect results.

How found

Customer reported on 6.0

Regression

Yes. From 5.0. We fixed bug in 6.0 to generate a complex expression for optional dependent. To match this new structure we updated join predicate detection code which inadvertently matched wrong thing.

Testing

Added test for user reported scenario. Some existing tests which had wrong SQL also got updated. The tests for original fix in 6.0 are also passing.

Risk

Low risk. We are matching what is exactly required now. Also added quirk to revert to previous behavior.

@smitpatel smitpatel requested a review from a team January 26, 2022 23:17
@smitpatel smitpatel added this to the 6.0.x milestone Jan 26, 2022
@smitpatel smitpatel changed the title Query: Match correct predicate structure to convert apply to join [release/6.0] Query: Match correct predicate structure to convert apply to join Jan 26, 2022
@leecow leecow modified the milestones: 6.0.x, 6.0.3 Jan 27, 2022
Base automatically changed from smit/6.0/issue26744_take2 to release/6.0 February 2, 2022 17:37
@wtgodbe
Copy link
Member

wtgodbe commented Feb 2, 2022

@smitpatel could you resolve the conflicts here?

Resolves #26756

For property access on optional dependents sharing column with principal, we generate CaseExpression. In order to match them during join key search, we updated our recursive function to match shape of the test in CaseExpression which incorrectly matched similar structure outside of case block causing somewhat wrong join key to be extracted. While join key in itself could work, when generating partitions out of it due to paging operation, it gives incorrect results.
The fix is to match the special structure of CaseExpression.Test separately. Also made the key comparison match more robust by only allowing column or case block to appear in condition. Other structures don't represent part of join key in a comparison.
Null checks for join keys are handled separately so that we only remove null checks which are indeed used in comparison with other columns in other operations.
@smitpatel smitpatel merged commit 4b0f830 into release/6.0 Feb 3, 2022
@smitpatel smitpatel deleted the smit/6.0/issue26756 branch February 3, 2022 00:28
@ajcvickers ajcvickers removed this from the 6.0.3 milestone Feb 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants