Skip to content

fix: do not prune ORDER BY keys using nullable UNIQUE constraints#23918

Open
buraksenn wants to merge 1 commit into
apache:mainfrom
buraksenn:fix-23818-nullable-unique-order-by
Open

fix: do not prune ORDER BY keys using nullable UNIQUE constraints#23918
buraksenn wants to merge 1 commit into
apache:mainfrom
buraksenn:fix-23818-nullable-unique-order-by

Conversation

@buraksenn

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Please check the issue for details, but the main idea is that a nullable UNIQUE column permits multiple NULL rows, so it does not determine later sort keys across them and they must not be pruned.

What changes are included in this PR?

FunctionalDependencies tracks a NullEquality per dependency. Sort-key pruning now requires the determinant to treat NULLs as equal (GROUP BY key), be non-nullable, or have NOT NULL sources.

Are these changes tested?

Yes, regression tests added in functional_dependencies.slt.

Are there any user-facing changes?

No API changes; incorrect results are fixed.

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FunctionalDependencies {
deps: Vec<FunctionalDependence>,
null_equalities: Vec<NullEquality>,

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.

this can be added in FunctionalDependence but since that is pub as well I did not want to change this. I can add this field into that struct if that makes more sense

@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) common Related to common crate labels Jul 27, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.66%. Comparing base (36c417b) to head (3f37107).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##             main   #23918     +/-   ##
=========================================
  Coverage   80.65%   80.66%             
=========================================
  Files        1092     1095      +3     
  Lines      371140   372344   +1204     
  Branches   371140   372344   +1204     
=========================================
+ Hits       299353   300361   +1008     
- Misses      53933    54063    +130     
- Partials    17854    17920     +66     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to common crate core Core DataFusion crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect results: ORDER BY drops a sort key based on a nullable UNIQUE constraint

2 participants