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 optimization: join prunning and "uniqeness" #4487

Open
aljazerzen opened this issue May 20, 2024 · 3 comments
Open

Query optimization: join prunning and "uniqeness" #4487

aljazerzen opened this issue May 20, 2024 · 3 comments
Labels
compiler language-design Changes to PRQL-the-language

Comments

@aljazerzen
Copy link
Member

Under certain conditions, join transforms could be removed from the query without changing its result. This would have significantly improve query performance.

Example:

from e = employees
join side:left addresses (e.id == that.employee_id)
select {e.name}

... could be simplified into:

from e = employees
select {e.name}

Conditions:

  1. when there is a join of left relation with right relation,
  2. and it is a left join (so no left rows are dropped),
  3. and right relation is unique on the join condition (so no left rows are duplicated),
  4. and none of the columns from the right relation are used in the output.

At the moment, PRQL does contain knowledge to detect the conditions 1.-3., but not 4., so this is not possible to implement.

It would be possible to have this "uniqueness" information either:

  • declared at relation definition site (in SQL terms, this would be a UNIQUE constraint / PRIMARY KEY),
  • inferred from the query (if there is a group x (take 1), we can infer uniqueness on x).
    Then, it would be possible to detect condition 4.
@aljazerzen aljazerzen added language-design Changes to PRQL-the-language compiler labels May 20, 2024
@aljazerzen
Copy link
Member Author

PostgreSQL does do this already

@aljazerzen
Copy link
Member Author

Ok, cool, so this is even less of a priority for PRQL, if downstream databases generally support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler language-design Changes to PRQL-the-language
Projects
None yet
Development

No branches or pull requests

2 participants