Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
When a join key determines other columns, DataFusion still plans as if it doesn't. After
items JOIN sales ON s_item = i_id, wherei_idis the primary key ofitems, everys_itemhas exactly onei_name. But withsalessorted by[s_item, s_day], the planner still:SortExecforORDER BY s_item, i_name, s_day,SortExecforsum(..) OVER (PARTITION BY s_item, i_name ORDER BY s_day),GROUP BY s_item, i_nameasPartial([0])instead of using the input's clustering ons_item.All three are redundant work on already-ordered or already-clustered input.
What changes are included in this PR?
This is a first slice of #27599, not the full design:
EquivalencePropertiesstores functional dependencies between columns (determinant -> dependents), in a new private moduleproperties/functional_dependency.rs.UNIQUEconstraint on non-nullable columns, counts as "key determines the other columns of that side". The key is no longer unique after the join, but it still determines its own side's columns. Outer joins drop them, since NULL padding breaks the reasoning.i_id -> i_namebecomess_item -> i_nameafters_item = i_id.SortKeyWalkpins the columns that already-pinned columns determine.ordering_satisfy,grouping_satisfyandfind_longest_permutationall use it, which covers the three cases above.Not included: aggregates as a source of dependencies, outer-join propagation, and planning-time benchmarks. Dependencies are dropped wherever they can't be shown to hold (unions, grouping sets).
What is the testing strategy for this PR?
functional_dependency.rs: dependencies through an inner join and offsetting of the right side, ordering and grouping satisfaction, outer-join negative case, nullableUNIQUEnot treated as a key, and projection (including the equal-column replacement and the case where nothing survives). The ordering and grouping tests fail without theSortKeyWalkchange.sqllogictest/test_files/equivalence_properties.sltwith the issue'sitems/salesexample:EXPLAINplans for theORDER BY,GROUP BYand window queries, result rows to check correctness, and a control table without a primary key that still sorts.datafusion-physical-expranddatafusion-physical-planlib tests pass.Are there any user-facing changes?
No public API changes: all new items are private. Some query plans can change: a
SortExecmay be dropped, or aGROUP BYmay be planned withgroup_clustering_mode=Full, when an inner join's key determines the other columns. Query results are unchanged.