Skip to content

[MAJOR] Equivalence System Overhaul #16217

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

Merged
merged 197 commits into from
Jun 7, 2025

Conversation

ozankabak
Copy link
Contributor

@ozankabak ozankabak commented May 30, 2025

Which issue does this PR close?

Rationale for this change

DF's theoretical approach to representing orderings, equivalences and constants is sound, but it suffers from many implementation problems that lead to various issues. Some of these issues include:

  • High-complexity planning times for queries involving UNION and ORDER BY clauses (see the referred issue).
  • A continuous stream of subtle bugs that arise from the fact that our objects allow multiple representations of the same underlying state (e.g. a non-existing ordering is sometimes represented by a None value for a type Option<LexOrdering>, and sometimes with a Some value with the payload being "empty").
  • The inability to relay ordering preference information to optimizer rules such as EnforceSorting, which results in missed optimization opportunities. For example, a windowing operator prefers its input to be sorted w.r.t. both PARTITION BY and ORDER BY keys, but if the former is not available, it is still preferable to have just the latter instead of a fully unsorted input.

What changes are included in this PR?

  • The equivalence system is rewritten to solve the computational complexity problem. The new system avoids handling constants separately from other equivalences and treats them on an equal footing within the same mechanism, avoiding unnecessary work during ordering_satisfy checks. Also, the new system caches normalization results for equivalent orderings, which was one of the major sources of excessive computational complexity during sort enforcement.
  • The LexOrdering and LexRequirement objects do not allow degenerate orderings anymore, whenever you see this object, you can be sure there will be some ordering. Possible absence of an ordering will henceforth be properly represented by an Option<LexOrdering>.
  • The OrderingRequirements object is introduced to capture ordering preferences of operators.

Are these changes tested?

Yes.

Are there any user-facing changes?

Yes -- this is a major API change and will break old code. We spent months looking for ways to (1) break this PR down into smaller ones, (2) yet lump all API changes in one PR -- but couldn't find an effective way to do this.

Therefore, I invite all contributors who are also downstream stakeholders to help by participating in a "pre-scream" test. Please test and report how this PR breaks your code, so we can collectively prepare an upgrade guide for the community at large.

Tips and Tricks for Reviewing

The "meat" of the code is in the following files:

  • datafusion/physical-expr-common/src/sort_expr.rs: Definition of OrderingRequirements, changes to LexOrdering and friends.
  • datafusion/physical-plan/src/execution_plan.rs: API change to required_input_ordering.
  • datafusion/physical-expr/src/equivalence: Re-implementation of the equivalence system.
  • datafusion/functions-aggregate/src: Effects of the above on aggregate function implementations.

The rest of the changes are "mandatory" propagative effects of fixing a fundamental low-level mechanism in a large codebase, and mostly trivial.

@alamb, @andygrove, @berkaysynnada -- feel free to tag others.

mertak-synnada added 30 commits February 12, 2025 15:22
remove usage of prefer_existing_sort
as default set requirements Hard
set soft on AggregateExec and BoundedWindowExec since they have InputOrderMode functionalities
remove prefer_existing_sort based test cases
# Conflicts:
#	datafusion/core/src/datasource/listing/table.rs
#	datafusion/physical-optimizer/src/enforce_sorting/mod.rs
# Conflicts:
#	datafusion-examples/examples/custom_file_format.rs
#	datafusion/core/src/datasource/file_format/csv.rs
#	datafusion/core/src/datasource/file_format/json.rs
#	datafusion/core/src/datasource/file_format/mod.rs
#	datafusion/core/src/datasource/file_format/parquet.rs
#	datafusion/core/tests/physical_optimizer/enforce_distribution.rs
#	datafusion/core/tests/physical_optimizer/test_utils.rs
#	datafusion/physical-optimizer/src/enforce_sorting/sort_pushdown.rs
return alternative on BoundedWindowAggExec
# Conflicts:
#	datafusion/catalog/src/stream.rs
#	datafusion/core/tests/physical_optimizer/enforce_distribution.rs
#	datafusion/physical-plan/src/joins/sort_merge_join.rs
#	datafusion/physical-plan/src/joins/symmetric_hash_join.rs
add requirements compatible test cases
@alamb
Copy link
Contributor

alamb commented Jun 2, 2025

🤖: Benchmark completed

Details

group                                         main                                   required-input-ordering
-----                                         ----                                   -----------------------
logical_aggregate_with_join                   1.01    736.0±4.72µs        ? ?/sec    1.00    730.8±3.47µs        ? ?/sec
logical_select_all_from_1000                  1.01    125.3±0.28ms        ? ?/sec    1.00    124.5±0.75ms        ? ?/sec
logical_select_one_from_700                   1.00    410.9±1.54µs        ? ?/sec    1.00    412.0±1.37µs        ? ?/sec
logical_trivial_join_high_numbered_columns    1.00    377.2±1.11µs        ? ?/sec    1.00    377.5±2.10µs        ? ?/sec
logical_trivial_join_low_numbered_columns     1.00    362.6±1.18µs        ? ?/sec    1.00    363.5±2.03µs        ? ?/sec
physical_intersection                         1.00    842.7±6.01µs        ? ?/sec    1.02   863.4±10.79µs        ? ?/sec
physical_join_consider_sort                   1.00   1356.9±5.64µs        ? ?/sec    1.03   1395.7±5.69µs        ? ?/sec
physical_join_distinct                        1.01    353.9±3.21µs        ? ?/sec    1.00    351.4±1.13µs        ? ?/sec
physical_many_self_joins                      1.00     10.1±0.02ms        ? ?/sec    1.00     10.1±0.04ms        ? ?/sec
physical_plan_clickbench_all                  1.00    146.6±1.33ms        ? ?/sec    1.01    148.4±1.44ms        ? ?/sec
physical_plan_clickbench_q1                   1.00  1705.1±20.55µs        ? ?/sec    1.01  1725.0±15.43µs        ? ?/sec
physical_plan_clickbench_q10                  1.00      2.5±0.03ms        ? ?/sec    1.02      2.5±0.04ms        ? ?/sec
physical_plan_clickbench_q11                  1.00      2.6±0.02ms        ? ?/sec    1.02      2.6±0.04ms        ? ?/sec
physical_plan_clickbench_q12                  1.00      2.7±0.04ms        ? ?/sec    1.03      2.8±0.02ms        ? ?/sec
physical_plan_clickbench_q13                  1.00      2.4±0.02ms        ? ?/sec    1.02      2.4±0.02ms        ? ?/sec
physical_plan_clickbench_q14                  1.00      2.6±0.02ms        ? ?/sec    1.03      2.6±0.03ms        ? ?/sec
physical_plan_clickbench_q15                  1.00      2.5±0.03ms        ? ?/sec    1.04      2.6±0.02ms        ? ?/sec
physical_plan_clickbench_q16                  1.00      2.3±0.03ms        ? ?/sec    1.05      2.4±0.04ms        ? ?/sec
physical_plan_clickbench_q17                  1.00      2.4±0.04ms        ? ?/sec    1.05      2.6±0.04ms        ? ?/sec
physical_plan_clickbench_q18                  1.00  1977.1±11.26µs        ? ?/sec    1.02      2.0±0.03ms        ? ?/sec
physical_plan_clickbench_q19                  1.00      2.9±0.01ms        ? ?/sec    1.05      3.0±0.02ms        ? ?/sec
physical_plan_clickbench_q2                   1.00  1957.0±25.76µs        ? ?/sec    1.02  1994.0±18.70µs        ? ?/sec
physical_plan_clickbench_q20                  1.00  1674.5±15.67µs        ? ?/sec    1.01  1683.8±25.23µs        ? ?/sec
physical_plan_clickbench_q21                  1.00  1993.9±24.54µs        ? ?/sec    1.00  1999.9±19.07µs        ? ?/sec
physical_plan_clickbench_q22                  1.00      2.6±0.03ms        ? ?/sec    1.02      2.7±0.01ms        ? ?/sec
physical_plan_clickbench_q23                  1.00      3.0±0.02ms        ? ?/sec    1.02      3.0±0.03ms        ? ?/sec
physical_plan_clickbench_q24                  1.00      4.7±0.03ms        ? ?/sec    1.02      4.7±0.04ms        ? ?/sec
physical_plan_clickbench_q25                  1.00      2.0±0.03ms        ? ?/sec    1.03      2.1±0.03ms        ? ?/sec
physical_plan_clickbench_q26                  1.00  1834.0±27.02µs        ? ?/sec    1.03  1887.5±26.64µs        ? ?/sec
physical_plan_clickbench_q27                  1.00      2.1±0.03ms        ? ?/sec    1.02      2.1±0.03ms        ? ?/sec
physical_plan_clickbench_q28                  1.00      2.9±0.03ms        ? ?/sec    1.01      3.0±0.03ms        ? ?/sec
physical_plan_clickbench_q29                  1.00      3.6±0.03ms        ? ?/sec    1.02      3.7±0.04ms        ? ?/sec
physical_plan_clickbench_q3                   1.00  1929.8±19.37µs        ? ?/sec    1.04      2.0±0.02ms        ? ?/sec
physical_plan_clickbench_q30                  1.09     15.1±0.15ms        ? ?/sec    1.00     13.9±0.13ms        ? ?/sec
physical_plan_clickbench_q31                  1.00      2.9±0.02ms        ? ?/sec    1.03      3.0±0.03ms        ? ?/sec
physical_plan_clickbench_q32                  1.00      2.9±0.02ms        ? ?/sec    1.02      3.0±0.02ms        ? ?/sec
physical_plan_clickbench_q33                  1.00      2.5±0.03ms        ? ?/sec    1.01      2.5±0.01ms        ? ?/sec
physical_plan_clickbench_q34                  1.00      2.1±0.02ms        ? ?/sec    1.03      2.2±0.02ms        ? ?/sec
physical_plan_clickbench_q35                  1.00      2.2±0.03ms        ? ?/sec    1.02      2.3±0.03ms        ? ?/sec
physical_plan_clickbench_q36                  1.00      3.0±0.03ms        ? ?/sec    1.02      3.1±0.03ms        ? ?/sec
physical_plan_clickbench_q37                  1.00      3.1±0.04ms        ? ?/sec    1.01      3.1±0.03ms        ? ?/sec
physical_plan_clickbench_q38                  1.00      3.1±0.03ms        ? ?/sec    1.02      3.1±0.03ms        ? ?/sec
physical_plan_clickbench_q39                  1.00      2.8±0.03ms        ? ?/sec    1.01      2.9±0.04ms        ? ?/sec
physical_plan_clickbench_q4                   1.00  1668.3±14.38µs        ? ?/sec    1.03  1714.2±24.87µs        ? ?/sec
physical_plan_clickbench_q40                  1.00      3.5±0.03ms        ? ?/sec    1.02      3.5±0.03ms        ? ?/sec
physical_plan_clickbench_q41                  1.00      3.0±0.02ms        ? ?/sec    1.02      3.1±0.03ms        ? ?/sec
physical_plan_clickbench_q42                  1.00      3.0±0.04ms        ? ?/sec    1.00      3.0±0.04ms        ? ?/sec
physical_plan_clickbench_q43                  1.00      3.1±0.04ms        ? ?/sec    1.07      3.3±0.11ms        ? ?/sec
physical_plan_clickbench_q44                  1.00  1830.7±25.31µs        ? ?/sec    1.00  1835.2±18.71µs        ? ?/sec
physical_plan_clickbench_q45                  1.00  1844.6±20.01µs        ? ?/sec    1.00  1844.1±30.61µs        ? ?/sec
physical_plan_clickbench_q46                  1.00      2.3±0.03ms        ? ?/sec    1.01      2.3±0.02ms        ? ?/sec
physical_plan_clickbench_q47                  1.00      2.9±0.03ms        ? ?/sec    1.01      2.9±0.03ms        ? ?/sec
physical_plan_clickbench_q48                  1.00      3.5±0.04ms        ? ?/sec    1.01      3.5±0.05ms        ? ?/sec
physical_plan_clickbench_q49                  1.03      3.9±0.04ms        ? ?/sec    1.00      3.8±0.03ms        ? ?/sec
physical_plan_clickbench_q5                   1.00  1882.5±26.37µs        ? ?/sec    1.02  1929.0±23.74µs        ? ?/sec
physical_plan_clickbench_q50                  1.00      3.5±0.02ms        ? ?/sec    1.00      3.6±0.02ms        ? ?/sec
physical_plan_clickbench_q51                  1.00      2.4±0.02ms        ? ?/sec    1.01      2.4±0.01ms        ? ?/sec
physical_plan_clickbench_q52                  1.00      3.2±0.03ms        ? ?/sec    1.02      3.3±0.02ms        ? ?/sec
physical_plan_clickbench_q6                   1.00  1865.0±14.75µs        ? ?/sec    1.03  1926.6±35.69µs        ? ?/sec
physical_plan_clickbench_q7                   1.00  1714.9±17.28µs        ? ?/sec    1.02  1747.1±25.25µs        ? ?/sec
physical_plan_clickbench_q8                   1.00      2.4±0.02ms        ? ?/sec    1.04      2.5±0.02ms        ? ?/sec
physical_plan_clickbench_q9                   1.00      2.3±0.03ms        ? ?/sec    1.02      2.4±0.03ms        ? ?/sec
physical_plan_tpcds_all                       1.00   1090.9±3.37ms        ? ?/sec    1.04   1129.2±7.87ms        ? ?/sec
physical_plan_tpch_all                        1.00     65.2±0.92ms        ? ?/sec    1.04     67.6±0.82ms        ? ?/sec
physical_plan_tpch_q1                         1.00      2.2±0.02ms        ? ?/sec    1.04      2.3±0.01ms        ? ?/sec
physical_plan_tpch_q10                        1.00      3.3±0.02ms        ? ?/sec    1.05      3.5±0.01ms        ? ?/sec
physical_plan_tpch_q11                        1.00      3.5±0.01ms        ? ?/sec    1.05      3.6±0.02ms        ? ?/sec
physical_plan_tpch_q12                        1.00   1962.6±9.99µs        ? ?/sec    1.04      2.0±0.02ms        ? ?/sec
physical_plan_tpch_q13                        1.00   1497.3±6.27µs        ? ?/sec    1.06  1579.9±25.05µs        ? ?/sec
physical_plan_tpch_q14                        1.00      2.0±0.01ms        ? ?/sec    1.05      2.1±0.02ms        ? ?/sec
physical_plan_tpch_q16                        1.00      2.6±0.01ms        ? ?/sec    1.05      2.7±0.02ms        ? ?/sec
physical_plan_tpch_q17                        1.00      2.6±0.01ms        ? ?/sec    1.02      2.6±0.01ms        ? ?/sec
physical_plan_tpch_q18                        1.00      2.8±0.01ms        ? ?/sec    1.05      2.9±0.03ms        ? ?/sec
physical_plan_tpch_q19                        1.00      4.0±0.03ms        ? ?/sec    1.01      4.0±0.03ms        ? ?/sec
physical_plan_tpch_q2                         1.00      5.7±0.03ms        ? ?/sec    1.04      5.9±0.01ms        ? ?/sec
physical_plan_tpch_q20                        1.00      3.3±0.04ms        ? ?/sec    1.03      3.4±0.01ms        ? ?/sec
physical_plan_tpch_q21                        1.00      4.4±0.03ms        ? ?/sec    1.03      4.5±0.06ms        ? ?/sec
physical_plan_tpch_q22                        1.00      3.0±0.03ms        ? ?/sec    1.03      3.1±0.03ms        ? ?/sec
physical_plan_tpch_q3                         1.00      2.3±0.01ms        ? ?/sec    1.05      2.4±0.03ms        ? ?/sec
physical_plan_tpch_q4                         1.00   1662.8±8.32µs        ? ?/sec    1.04  1729.9±12.29µs        ? ?/sec
physical_plan_tpch_q5                         1.00      3.2±0.01ms        ? ?/sec    1.04      3.4±0.03ms        ? ?/sec
physical_plan_tpch_q6                         1.00    944.0±7.01µs        ? ?/sec    1.02    964.7±6.33µs        ? ?/sec
physical_plan_tpch_q7                         1.00      4.4±0.02ms        ? ?/sec    1.05      4.6±0.03ms        ? ?/sec
physical_plan_tpch_q8                         1.00      5.3±0.05ms        ? ?/sec    1.03      5.5±0.02ms        ? ?/sec
physical_plan_tpch_q9                         1.00      4.2±0.01ms        ? ?/sec    1.05      4.4±0.03ms        ? ?/sec
physical_select_aggregates_from_200           1.19     26.1±0.07ms        ? ?/sec    1.00     21.9±0.08ms        ? ?/sec
physical_select_all_from_1000                 1.01    139.7±0.27ms        ? ?/sec    1.00    138.6±0.23ms        ? ?/sec
physical_select_one_from_700                  1.00   1038.2±5.50µs        ? ?/sec    1.01   1045.3±5.50µs        ? ?/sec
physical_sorted_union_orderby                 1.37     64.2±1.20ms        ? ?/sec    1.00     47.0±0.34ms        ? ?/sec
physical_theta_join_consider_sort             1.00   1736.6±7.42µs        ? ?/sec    1.01   1762.2±8.80µs        ? ?/sec
physical_unnest_to_join                       1.00  1329.5±14.09µs        ? ?/sec    1.01   1337.2±5.08µs        ? ?/sec
with_param_values_many_columns                1.01    166.3±1.24µs        ? ?/sec    1.00    164.2±0.89µs        ? ?/sec

@alamb
Copy link
Contributor

alamb commented Jun 3, 2025

🤖 ./gh_compare_branch_bench.sh Benchmark Script Running

I think the planning slowdown is real and reproducible.

I did some profiling and it seems it should be fairly easy to fix (we could do it in a follow on even) by optimizing the projection removal code:

Screenshot 2025-06-03 at 7 03 07 AM Screenshot 2025-06-03 at 7 04 35 AM

@ozankabak
Copy link
Contributor Author

Thanks for all the reviews. I will address them today 🚀

With the computational complexity issue removed, I agree that we can progressively reduce the "constant factor" in running time over a few future PRs. To give reviewers some context: Complexity issue is solved by computing normalizations only once (when equivalences are modified) and handling constants on an equal footing with other equivalences. This makes ordering checks fast, but some parts of the current codebase probably make modifications eagerly, which is the likely source of the small slowdown @alamb is seeing. I expect refactoring those parts of the code a little bit will mitigate this.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is good to merge as is -- thank you again for all the work

I think the code is much clearer and faster (and will be easier to work with going forward).

I also verified that the reproducer on #13748

If we are not able to resolve the planning time regression before merge, I think we should file a follow on ticket and I can help try and resolve it prior to the 49.0.0 release

Finally, here is a proposed small improvement I ran across while reviewing this PR

Performance Results

on main ( at 900279c)

Running with 10 columns...completed in 31.865667ms
Running with 20 columns...completed in 50.299667ms
Running with 30 columns...completed in 121.58075ms
Running with 40 columns...completed in 253.701875ms
Running with 50 columns...completed in 489.564584ms
Running with 60 columns...completed in 768.394167ms
Running with 70 columns...completed in 1.291121416s
Running with 80 columns...completed in 1.876029208s
Running with 90 columns...completed in 2.652548541s
Running with 100 columns...completed in 3.843196875s

on this branch 🚀

Running with 10 columns...completed in 23.371333ms
Running with 20 columns...completed in 35.933167ms
Running with 30 columns...completed in 74.359083ms
Running with 40 columns...completed in 125.760666ms
Running with 50 columns...completed in 198.790375ms
Running with 60 columns...completed in 285.836584ms
Running with 70 columns...completed in 408.980167ms
Running with 80 columns...completed in 557.148791ms
Running with 90 columns...completed in 710.347208ms
Running with 100 columns...completed in 880.061541ms

Minor: remove an unecessary clone in common_sort_prefix_length
Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments after (roughly) reviewing followed after @alamb's call on dev. 🙂
It is roughly because the size of the changes. A 7000+ lines PR is too hard to review very in details.

Overall the change looks good and it solves the complexity issue reported. 👍

Although the PR claims that it couldn't find an effective way to split it to smaller ones. I'm not very sure but I can see there are changes that are good to have but maybe not so urgent in just one shot, e.g., a lot of code refactors seems not core change, code comment rephrasing, API change that seems can be in separate works.

For such big overhaul, I still prefer and suggest we can it in incremental approach. It will help reviewing a lot.

@ozankabak
Copy link
Contributor Author

Thanks for all the reviews. I went through each and sent a commit that addresses all the suggestions, I also tried to answer any questions I saw.

I will later resolve the conflicts and get this ready to go. I see that we are close to getting ready for the 48 release too, so it seems like we are making a good effort to align them in the way we want.

Thanks all 🚀

@ozankabak
Copy link
Contributor Author

ozankabak commented Jun 4, 2025

I removed the conflicts, this is in a good state now. Did we get to the 48 cut-off point yet?

@Omega359
Copy link
Contributor

Omega359 commented Jun 5, 2025

I plan on running my test suite against this side branch hopefully tomorrow or early next week to verify it.

@alamb
Copy link
Contributor

alamb commented Jun 6, 2025

I removed the conflicts, this is in a good state now. Did we get to the 48 cut-off point yet?

We are close I think

Update yes I think main is open for new features and we can merge this one (though maybe it would be a good idea for @Omega359 to test before we do so)

@ozankabak
Copy link
Contributor Author

I think there are some incoming big PRs, so I'd like to go ahead with this and help with fixing any issues @Omega359 finds after merge. In addition to the time cost of going through merges, I am fearful of accidentally introducing bugs every time I merge.

@ozankabak
Copy link
Contributor Author

OK, I resolved the conflicts and all seems OK. Should we go ahead after CI passes?

@Omega359
Copy link
Contributor

Omega359 commented Jun 6, 2025

I'll be able to do my tests Sat afternoon or Sun morning. I'm good with doing that against either main or the branch.

@ozankabak
Copy link
Contributor Author

Thanks @Omega359. Given that we didn't hear any concerns yesterday, I will go ahead and merge this.

Thanks everyone for all the reviews!

@ozankabak ozankabak merged commit 1daa5ed into apache:main Jun 7, 2025
28 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 7, 2025

🚀 woohoo!

@Omega359
Copy link
Contributor

Omega359 commented Jun 8, 2025

fyi I did run this through my test suite and it seemed to work correctly :)

kosiew pushed a commit to kosiew/datafusion that referenced this pull request Jun 9, 2025
* introduce Soft & Hard RequiredInputOrderings
remove usage of prefer_existing_sort
as default set requirements Hard
set soft on AggregateExec and BoundedWindowExec since they have InputOrderMode functionalities

* add documentation to replace_with_partial_sort
simplify indentation

* add documentation to analyze_immediate_sort_removal
simplify indentation

* remove prefer_existing_sort effects
remove prefer_existing_sort based test cases

* remove prefer_existing_sort configuration

* remove prefer_existing_sort configuration

* add documentation

* add documentation

* add documentation

* fix imports and test cases

* fix imports and test cases

* implement RequiredInputOrdering as vectors

* implement RequiredInputOrdering as vectors
return alternative on BoundedWindowAggExec

* fix test cases

* change doc

* revert prefer_existing_sort flag

* fix changes

* fix test case

* make LexRequirement private

* ensure RequiredInputOrdering inner requirement can not be empty
simplify sort_pushdown.rs

* add default test cases
add requirements compatible test cases

* doc fixes

* fix clippy and docs

* format code

* format code

* doc fix

* add TODO test cases with test_soft_hard_requirements prefix

* Review Part 1

* Review Part 2

* Review Part 3

* Review Part 4

* Review Part 5

* Review Part 6

* Enforce non-degeneracy for LexRequirement

* Enforce non-degeneracy for LexOrdering (Part 1)

* Enforce non-degeneracy for LexOrdering (Part 2)

* fix first phase of merge conflicts and other bugs

* Fix sqllogictests except the schema mismatch

* Cleanup Part 1

* Cleanup Part 2

* Cleanup Part 3

* do not initialize Trivial accumulators if ordering is set

* initialize TrivialFirstPrimitiveGroupsAccumulator struct and return

* fix clippy

* fix merge conflicts

* fix typos
remove TrivialFirstPrimitiveGroupsAccumulator
make groups accumulator available only when order requirement is set

* format code

* Add requirement_satisfied back in

* Replace AsRef with ordinary & for LexOrdering

* Further cleanup

* add OutputRequirementExec fetches to sort adding

* Simplify remove_redundant_entries

* Work with iterators in ordering_satisfy_requirement

* Fix doctests

* Cleanup LexOrdering APIs

* Cleanup LexOrdering APIs 2

* Add reverse_each to LexOrdering

* Use LexOrdering instead of Arc<[PhysicalSortExpr]>

* Use PhysicalSortExpr slices in contexts where we simply list sort expressions

* Generalize add_new_ordering APIs

* Simplifications

* More cleanups

* API Simplifications

* Improve comments

* Use vector in Expr structs

* Fix doctests

* Simplify sort

* Simplify the get_finer_aggregate_exprs_requirement function

* Avoid hidden clones

* bugfix

* Simplify the get_finer_aggregate_exprs_requirement function

* Simplify the function with_reorder

* Fix with_reorder bug

* Simplify the function with_reorder (Part 2)

* Simplify

* DRY

* Simplifications

* Improve add_equal_condition

* Improve docs

* Simplifications

* Simplifications

* RequiredInputOrdering -> OrderingAlternatives

* Simplify new_with_orderings

* Transition to fallible LexOrdering constructor

* Transition to fallible LexOrdering constructor - 2

* Transition to fallible LexOrdering constructor - 3

* Transition to fallible LexOrdering constructor - 4

* Transition to fallible LexOrdering constructor - 5

* Transition to fallible LexOrdering constructor - 6

* Transition to fallible LexOrdering constructor - 7

* Transition to fallible LexOrdering constructor - 8

* Transition to fallible LexOrdering constructor - 9

* Transition to fallible LexOrdering constructor - 10

* Transition to fallible LexOrdering constructor - 11

* Simplify constant expressions

* Simplify constant expressions - 2

* Simplify constant expressions - 3

* Simplify constant expressions - 4

* Simplify constant expressions - 5

* Simplify constant expressions - 6

* Simplify constant expressions - 7

* Simplify constant expressions - 8

* Simplify constant expressions - 9

* Fix imports

* Remove explicit constant tracking from equivalences

* Resolve logical conflict

* Remove the unusual take API, instead use the from trait

* Simplify projection mapping - 1

* Use a map instead of a vector in ProjectionMapping

* Simplify DependencyMap

* Simplify DependencyMap - 2

* Simplify DependencyMap - 3

* Incorporate Jay's suggestions

* Simplifications

* Fix doctest

* Improve docstrings

* Update/cast the constant value accordingly when schema changes

* Improve ProjectionMapping

* Remove DerefMut from ProjectionTargets to preserve non-emptiness

* Docstring

* Optimize project_expr by fetching equivalence classes only once

* Project multiple expressions more efficiently at once

* Project multiple expressions more efficiently at once - 2

* Project multiple expressions more efficiently at once - 3

* Project multiple expressions more efficiently at once - 4

* Move normalization of sort expressions to equivalence group

* Improve comments

* Improve display for EquivalenceProperties

* More idiomatic code

* More succinct code

* Remove extend_orderings from EquivalenceProperties

* Simplify with_reorder

* Store normalized orderings - 1

* Reduce time complexity of normalization w.r.t. number of equivalence classes

* Simplify bridge_classes logic

* Remove TODOs

* Simplify generate_dependency_orderings

* normalized orderings - 2

* normalized orderings - 3

* undo normalized orderings

* Fix logical conflicts

* Fix imports

* Remove noop code

* Move add_offset_to_expr

* Remove mutation from LexOrdering

* Remove unwraps

* Remove unwraps - 2

* Remove unwraps - 3

* Remove unwraps - 4

* Remove collapse from LexOrdering

* Remove unwraps - 5

* Remove unwraps - 6

* Remove unwraps - 7

* Remove unwraps - 8

* Remove unwraps - 9

* Remove unwraps - 10

* Remove collapse from LexRequirement

* Simplify ordering_satisfy

* Enforce uniqueness in LexOrdering

* Fix with_reorder

* Use tee

* Fix reorder api

* Comment grammar

* Remove unwraps

* Cache normalized orderings

* Minor: remove an unecessary clone in common_sort_prefix_length

* Address reviews

---------

Co-authored-by: mertak-synnada <mertak67+synaada@gmail.com>
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Co-authored-by: Berkay Şahin <124376117+berkaysynnada@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api change Changes the API exposed to users of the crate catalog Related to the catalog crate common Related to common crate core Core DataFusion crate datasource Changes to the datasource crate ffi Changes to the ffi crate functions Changes to functions implementation logical-expr Logical plan and expressions optimizer Optimizer rules physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate proto Related to proto crate sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exponential planning time (100s of seconds) with UNION and ORDER BY queries
6 participants