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

opt: transfer constraints on join equality columns #39054

Open
RaduBerinde opened this issue Jul 23, 2019 · 3 comments
Open

opt: transfer constraints on join equality columns #39054

RaduBerinde opened this issue Jul 23, 2019 · 3 comments
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team

Comments

@RaduBerinde
Copy link
Member

RaduBerinde commented Jul 23, 2019

We saw a user case that was roughly of the form:
SELECT .. FROM (SELECT * FROM t WHERE x=1) AS t1 JOIN t2 ON t1.x=t2.x

Here it would be ideal to push down the x=1 constraint on the right-hand side, in the hope that there is an index there that can help. Without pushing the constraint, we would get a lookup join on that index which is not too bad, but pushing down x=1 can make things more efficient (and may trigger other optimizations).

The rough idea from some discussions:

  • use rule props to bubble up constraints on relevant columns
  • a normalization rule for join checks both sides for constraints on equality columns, if they are not the same, it pushes down additional filters as needed (by wrapping the input in a Select).

There is a difficulty here: if we create a Select and the filter gets pushed down by other rules, it must be guaranteed that the constraint would reflect the filter (in other words, the constraint propagation can't be "best effort"). If this is not the case, we would enter an infinite loop where we keep adding the filter.

Jira issue: CRDB-5595

@RaduBerinde RaduBerinde added this to Triage in BACKLOG, NO NEW ISSUES: SQL Optimizer via automation Jul 23, 2019
@RaduBerinde
Copy link
Member Author

#20100 is somewhat related.

@awoods187 awoods187 added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-optimizer SQL logical planning and optimizations. labels Jul 23, 2019
@RaduBerinde RaduBerinde moved this from Triage to Plan enhancements (lower priority) in BACKLOG, NO NEW ISSUES: SQL Optimizer Apr 18, 2020
@github-actions
Copy link

github-actions bot commented Jun 4, 2021

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
5 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@github-actions
Copy link

We have marked this issue as stale because it has been inactive for
18 months. If this issue is still relevant, removing the stale label
or adding a comment will keep it active. Otherwise, we'll close it in
10 days to keep the issue queue tidy. Thank you for your contribution
to CockroachDB!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2023
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Plan enhancements (lower priority) to Done Oct 3, 2023
@RaduBerinde RaduBerinde reopened this Oct 3, 2023
BACKLOG, NO NEW ISSUES: SQL Optimizer automation moved this from Done to Triage Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

3 participants