Skip to content

Ordering satisfy consider ordering equivalence of different lengths - #6330

Merged
mustafasrepo merged 7 commits into
apache:mainfrom
synnada-ai:feature/ordering-satisfy
May 12, 2023
Merged

mustafasrepo merged 7 commits into
apache:mainfrom
synnada-ai:feature/ordering-satisfy

Conversation

@berkaysynnada

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #6280.

Rationale for this change

ordering_satisfy_concrete() function first checks whether the required PhysicalSortExpr's length is greater than provided PhysicalSortExpr's length. If so, it directly returns false. However, there may be cases such as:

Provided: (a)
Required: (a,b) ,but a and b are in an equivalent class.

In that case, an unnecessary sort is added. We can remove it by changing the implementation of ordering_satisfy_concrete().

What changes are included in this PR?

Required PhysicalSortExpr's are normalized, and simplified to have unique elements. Provided PhysicalSortExpr's are also normalized before the comparison of expressions. The length check is moved to the final, after the normalization and compression steps.

Additionally, there have been a few cleanups and silent bug fixes related to ordering equivalences.

Are these changes tested?

Yes, both in utils.rs and window.slt.

Are there any user-facing changes?

@github-actions github-actions Bot added core Core DataFusion crate physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels May 11, 2023
@ozankabak

Copy link
Copy Markdown
Contributor

This PR also includes some drive-by cleanups in the adjacent code in utils.rs to get rid of some unnecessary clones etc.

@mustafasrepo mustafasrepo 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.

I have reviewed this PR (in our internal review process). It is LGTM!. We welcome community feedback, I will leave it open a little while. In case community has feedback

@alamb alamb 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.

Thank you @berkaysynnada and @mustafasrepo -- I skimmed the code and reviewed the test changes. 👍

statement error DataFusion error: Error during planning: Invalid window frame: frame offsets must be non negative integers
select row_number() over (rows between current row and -1 following) from (select 1 a) x

# This test shows that ordering satisfy considers ordering equivalences,

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.

👍 for the explanation

@mustafasrepo
mustafasrepo merged commit 4b21b61 into apache:main May 12, 2023
@berkaysynnada
berkaysynnada deleted the feature/ordering-satisfy branch May 15, 2023 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ordering satisfy consider ordering equivalence of different lengths

4 participants