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

Simplify some collection queries #1

Open
8 of 15 tasks
ranma42 opened this issue Sep 19, 2024 · 0 comments
Open
8 of 15 tasks

Simplify some collection queries #1

ranma42 opened this issue Sep 19, 2024 · 0 comments

Comments

@ranma42
Copy link
Owner

ranma42 commented Sep 19, 2024

The following expressions are equivalent (the arrow describes the preferred direction):

No-op:

  • source.Skip(0) -> source
  • source.Where(true) -> source

Absorb:

  • source.Take(0).* -> source.Take(0)
  • source.Take(0) -> whatever.Take(0)
  • source.Where(false) <-> source.Take(0)

Commutativity:

  • source.OrderBy(x).Where(y) <-> source.Where(y).OrderBy(x)
  • source.Where(x).Distinct() <-> source.Distinct().Where(x)

Simplifications:

  • source.Where(x).Where(y) -> source.Where(x && y)
  • source.OrderBy(x).OrderBy(y) -> source.OrderBy(y)
  • source.Take(x).Take(y) -> source.Take(Min(x, y)) Optimize multiple consecutive LIMITs dotnet/efcore#35384
  • source.Skip(x).Skip(y) -> source.Skip(Max(x, 0) + Max(y, 0))
  • source.Take(x).Skip(y) -> source.Skip(y).Take(Max(x, 0) - Max(y, 0))

Operations on singletons:

@ranma42 ranma42 changed the title WIP simplify collections Simplify some collection queries Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant