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

Query: take indexes into account in optimizations #34159

Open
ranma42 opened this issue Jul 4, 2024 · 5 comments
Open

Query: take indexes into account in optimizations #34159

ranma42 opened this issue Jul 4, 2024 · 5 comments

Comments

@ranma42
Copy link
Contributor

ranma42 commented Jul 4, 2024

Most query optimizations do not take into account whether a column (or expression) is indexed.
In most cases, the optimization can make reasonable choices by simply taking into account the type of the expressions (example: constant vs parameter vs column, ...).
In some cases (especially in the case of symmetries) information coming from the model could help choose the most appropriate expression.

It is not clear how often this is relevant; most cases seem to be handled appropriately by the simpler (type-driven) heuristics.
Real-world use cases would be especially interesting to understand the tradeoff.

@ranma42
Copy link
Contributor Author

ranma42 commented Jul 4, 2024

An example (from #34048 (comment)) is:

  • NOT(x == y)
  • x != y
  • x == NOT(y)
  • NOT(x) == y

are all equivalent assuming both x and y are boolean, but they are treated very differently by (at least) the Sqlite planner.

@ranma42
Copy link
Contributor Author

ranma42 commented Jul 4, 2024

In addition to simple columns, it might make sense to take into account expressions, especially in relationship to

@roji
Copy link
Member

roji commented Jul 8, 2024

Noting that knowing model information isn't trivial - ColumnExpression doesn't reference the IProperty it represents, and reverse-engineering that isn't trivial. At some point we may want to consider enriching our SQL tree model with more information, e.g. adding an option Property to ColumnExpression.

@roji roji added this to the Backlog milestone Jul 8, 2024
@ranma42
Copy link
Contributor Author

ranma42 commented Jul 8, 2024

@roji enriching the expression tree with additional metadata would also enable hints on other optimization opportunities, for example:

  • join order
  • parameter processing (specialize to simplify expressions vs share complex expressions for all cases)

@roji
Copy link
Member

roji commented Jul 8, 2024

Yep. Noting also that for NativeAOT, we currently have trouble generating code representation for our SQL tree, since it references "detached" type mappings, and we can't easily recreate those type mappings in generated code. If we had IProperty instead, we could generate code that looks up those properties in the model. Although fully replacing type mappings by IProperty is a pretty drastic change that needs to be considered more carefully.

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

No branches or pull requests

5 participants