opt: transfer constraints on join equality columns #39054
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
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 downx=1
can make things more efficient (and may trigger other optimizations).The rough idea from some discussions:
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
The text was updated successfully, but these errors were encountered: